Skip to content

Commit

Permalink
use uppercase HTTP method names (#4612)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Aug 8, 2023
1 parent 59e097f commit fa389f2
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
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 @@ -72,8 +72,8 @@ function validateOptions (options) {
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 @@ class Uploader {
}

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', // TODO: switch to the uppercase 'POST' in the next major
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

0 comments on commit fa389f2

Please sign in to comment.