Browse Source

use uppercase HTTP method names (#4612)

Antoine du Hamel 1 năm trước cách đây
mục cha
commit
fa389f2409

+ 2 - 2
packages/@uppy/aws-s3-multipart/src/index.js

@@ -243,7 +243,7 @@ class HTTPCommunicationQueue {
 
   async #nonMultipartUpload (file, chunk, signal) {
     const {
-      method = 'post',
+      method = 'POST',
       url,
       fields,
       headers,
@@ -251,7 +251,7 @@ class HTTPCommunicationQueue {
 
     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)

+ 3 - 3
packages/@uppy/aws-s3/src/index.js

@@ -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
   }
 }
@@ -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) : [],
         }

+ 3 - 3
packages/@uppy/companion/src/server/Uploader.js

@@ -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')
     }
   }
@@ -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)

+ 1 - 1
packages/@uppy/companion/src/server/controllers/s3.js

@@ -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,

+ 6 - 6
packages/@uppy/transloadit/src/Client.js

@@ -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,
     })
@@ -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' }))
   }
 
@@ -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' }))
   }
 
@@ -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' }))
   }
 
@@ -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' }))
   }
 
@@ -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,

+ 1 - 1
packages/@uppy/xhr-upload/src/index.js

@@ -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,