Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use uppercase HTTP method names #4612

Merged
merged 3 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@uppy/aws-s3-multipart/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,15 @@ class HTTPCommunicationQueue {

async #nonMultipartUpload (file, chunk, signal) {
const {
method = 'post',
method = 'POST',
url,
fields,
headers,
} = await this.#getUploadParameters(this.#getFile(file), { signal }).abortOn(signal)

let body
const data = chunk.getData()
if (method === 'post') {
if (method.toUpperCase() === 'POST') {
const formData = new FormData()
Object.entries(fields).forEach(([key, value]) => formData.set(key, value))
formData.set('file', data)
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/aws-s3/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function validateParameters (file, params) {
const methodIsValid = params.method == null || /^p(u|os)t$/i.test(params.method)

if (!methodIsValid) {
const err = new TypeError(`AwsS3: got incorrect method from 'getUploadParameters()' for file '${file.name}', expected 'put' or 'post' but got '${params.method}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
const err = new TypeError(`AwsS3: got incorrect method from 'getUploadParameters()' for file '${file.name}', expected 'PUT' or 'POST' but got '${params.method}' instead.\nSee https://uppy.io/docs/aws-s3/#getUploadParameters-file for more on the expected format.`)
throw err
}
}
Expand Down Expand Up @@ -209,14 +209,14 @@ export default class AwsS3 extends UploaderPlugin {
validateParameters(file, params)

const {
method = 'post',
method = 'POST',
url,
fields,
headers,
} = params
const xhrOpts = {
method,
formData: method.toLowerCase() === 'post',
formData: method.toUpperCase() === 'POST',
endpoint: url,
allowedMetaFields: fields ? Object.keys(fields) : [],
}
Expand Down
6 changes: 3 additions & 3 deletions packages/@uppy/companion/src/server/Uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
// @ts-ignore - typescript resolves this this to a hoisted version of
// serialize-error that ships with a declaration file, we are using a version
// here that does not have a declaration file
const serializeError = require('serialize-error')

Check warning on line 27 in packages/@uppy/companion/src/server/Uploader.js

View workflow job for this annotation

GitHub Actions / Lint JavaScript/TypeScript

`serialize-error` import should occur before import of `./helpers/utils`
const emitter = require('./emitter')
const { jsonStringify, hasMatch } = require('./helpers/utils')
const logger = require('./logger')
Expand Down Expand Up @@ -72,8 +72,8 @@
throw new ValidationError('unsupported HTTP METHOD specified')
}

const method = options.httpMethod.toLowerCase()
if (method !== 'put' && method !== 'post') {
const method = options.httpMethod.toUpperCase()
if (method !== 'PUT' && method !== 'POST') {
throw new ValidationError('unsupported HTTP METHOD specified')
}
}
Expand Down Expand Up @@ -612,7 +612,7 @@
}

try {
const httpMethod = (this.options.httpMethod || '').toLowerCase() === 'put' ? 'put' : 'post'
const httpMethod = (this.options.httpMethod || '').toUpperCase() === 'PUT' ? 'put' : 'post'
const runRequest = got[httpMethod]

const response = await runRequest(url, reqOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/companion/src/server/controllers/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = function s3 (config) {
Key: key,
}).then(data => {
res.json({
method: 'post',
method: 'POST',
aduh95 marked this conversation as resolved.
Show resolved Hide resolved
url: data.url,
fields: data.fields,
expires: config.expires,
Expand Down
12 changes: 6 additions & 6 deletions packages/@uppy/transloadit/src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default class Client {

const url = new URL(ASSEMBLIES_ENDPOINT, `${this.opts.service}`).href
return this.#fetchJSON(url, {
method: 'post',
method: 'POST',
headers: this.#headers,
body: data,
})
Expand All @@ -105,7 +105,7 @@ export default class Client {
reserveFile (assembly, file) {
const size = encodeURIComponent(file.size)
const url = `${assembly.assembly_ssl_url}/reserve_file?size=${size}`
return this.#fetchJSON(url, { method: 'post', headers: this.#headers })
return this.#fetchJSON(url, { method: 'POST', headers: this.#headers })
.catch((err) => this.#reportError(err, { assembly, file, url, type: 'API_ERROR' }))
}

Expand All @@ -126,7 +126,7 @@ export default class Client {

const qs = `size=${size}&filename=${filename}&fieldname=${fieldname}&s3Url=${uploadUrl}`
const url = `${assembly.assembly_ssl_url}/add_file?${qs}`
return this.#fetchJSON(url, { method: 'post', headers: this.#headers })
return this.#fetchJSON(url, { method: 'POST', headers: this.#headers })
.catch((err) => this.#reportError(err, { assembly, file, url, type: 'API_ERROR' }))
}

Expand All @@ -145,7 +145,7 @@ export default class Client {
num_expected_upload_files,
}],
})
return this.#fetchJSON(url, { method: 'post', headers: this.#headers, body })
return this.#fetchJSON(url, { method: 'POST', headers: this.#headers, body })
.catch((err) => this.#reportError(err, { url, type: 'API_ERROR' }))
}

Expand All @@ -156,7 +156,7 @@ export default class Client {
*/
cancelAssembly (assembly) {
const url = assembly.assembly_ssl_url
return this.#fetchJSON(url, { method: 'delete', headers: this.#headers })
return this.#fetchJSON(url, { method: 'DELETE', headers: this.#headers })
.catch((err) => this.#reportError(err, { url, type: 'API_ERROR' }))
}

Expand All @@ -176,7 +176,7 @@ export default class Client {
: err.message

return this.#fetchJSON('https://transloaditstatus.com/client_error', {
method: 'post',
method: 'POST',
body: JSON.stringify({
endpoint,
instance,
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/xhr-upload/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class XHRUpload extends UploaderPlugin {
const defaultOptions = {
formData: true,
fieldName: opts.bundle ? 'files[]' : 'file',
method: 'post',
method: 'POST',
allowedMetaFields: null,
responseUrlFieldName: 'url',
bundle: false,
Expand Down