Explorar o código

Merge pull request #925 from transloadit/customheaders-uppyserver

feature: add support for custom headers sent to uppy-server
Ifedapo .A. Olarewaju %!s(int64=6) %!d(string=hai) anos
pai
achega
561e290926

+ 1 - 0
packages/@uppy/dropbox/src/index.js

@@ -22,6 +22,7 @@ module.exports = class Dropbox extends Plugin {
     // the provider instance must be equal to this.id.
     // the provider instance must be equal to this.id.
     this[this.id] = new Provider(uppy, {
     this[this.id] = new Provider(uppy, {
       serverUrl: this.opts.serverUrl,
       serverUrl: this.opts.serverUrl,
+      serverHeaders: this.opts.serverHeaders,
       provider: 'dropbox'
       provider: 'dropbox'
     })
     })
 
 

+ 1 - 0
packages/@uppy/google-drive/src/index.js

@@ -16,6 +16,7 @@ module.exports = class GoogleDrive extends Plugin {
 
 
     this[this.id] = new Provider(uppy, {
     this[this.id] = new Provider(uppy, {
       serverUrl: this.opts.serverUrl,
       serverUrl: this.opts.serverUrl,
+      serverHeaders: this.opts.serverHeaders,
       provider: 'drive',
       provider: 'drive',
       authProvider: 'google'
       authProvider: 'google'
     })
     })

+ 1 - 0
packages/@uppy/instagram/src/index.js

@@ -19,6 +19,7 @@ module.exports = class Instagram extends Plugin {
 
 
     this[this.id] = new Provider(uppy, {
     this[this.id] = new Provider(uppy, {
       serverUrl: this.opts.serverUrl,
       serverUrl: this.opts.serverUrl,
+      serverHeaders: this.opts.serverHeaders,
       provider: 'instagram',
       provider: 'instagram',
       authProvider: 'instagram'
       authProvider: 'instagram'
     })
     })

+ 7 - 7
packages/@uppy/server-utils/src/RequestClient.js

@@ -25,6 +25,10 @@ module.exports = class RequestClient {
     }
     }
   }
   }
 
 
+  get headers () {
+    return Object.assign({}, this.defaultHeaders, this.opts.serverHeaders || {})
+  }
+
   onReceiveResponse (response) {
   onReceiveResponse (response) {
     const state = this.uppy.getState()
     const state = this.uppy.getState()
     const uppyServer = state.uppyServer || {}
     const uppyServer = state.uppyServer || {}
@@ -51,7 +55,7 @@ module.exports = class RequestClient {
   get (path) {
   get (path) {
     return fetch(this._getUrl(path), {
     return fetch(this._getUrl(path), {
       method: 'get',
       method: 'get',
-      headers: this.defaultHeaders
+      headers: this.headers
     })
     })
       // @todo validate response status before calling json
       // @todo validate response status before calling json
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)
@@ -64,7 +68,7 @@ module.exports = class RequestClient {
   post (path, data) {
   post (path, data) {
     return fetch(this._getUrl(path), {
     return fetch(this._getUrl(path), {
       method: 'post',
       method: 'post',
-      headers: this.defaultHeaders,
+      headers: this.headers,
       body: JSON.stringify(data)
       body: JSON.stringify(data)
     })
     })
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)
@@ -82,11 +86,7 @@ module.exports = class RequestClient {
   delete (path, data) {
   delete (path, data) {
     return fetch(`${this.hostname}/${path}`, {
     return fetch(`${this.hostname}/${path}`, {
       method: 'delete',
       method: 'delete',
-      credentials: 'include',
-      headers: {
-        'Accept': 'application/json',
-        'Content-Type': 'application/json'
-      },
+      headers: this.headers,
       body: data ? JSON.stringify(data) : null
       body: data ? JSON.stringify(data) : null
     })
     })
       .then(this.onReceiveResponse)
       .then(this.onReceiveResponse)

+ 2 - 2
packages/@uppy/server-utils/types/index.d.ts

@@ -2,6 +2,7 @@ import { Uppy } from '@uppy/core';
 
 
 export interface RequestClientOptions {
 export interface RequestClientOptions {
   serverUrl: string;
   serverUrl: string;
+  serverHeaders?: object;
 }
 }
 
 
 export class RequestClient {
 export class RequestClient {
@@ -11,8 +12,7 @@ export class RequestClient {
   delete (path: string, data: object): Promise<any>;
   delete (path: string, data: object): Promise<any>;
 }
 }
 
 
-export interface ProviderOptions {
-  serverUrl: string;
+export interface ProviderOptions extends RequestClientOptions {
   provider: string;
   provider: string;
   authProvider?: string;
   authProvider?: string;
   name?: string;
   name?: string;

+ 4 - 1
packages/@uppy/url/src/index.js

@@ -60,7 +60,10 @@ module.exports = class Url extends Plugin {
 
 
     this.handlePaste = this.handlePaste.bind(this)
     this.handlePaste = this.handlePaste.bind(this)
 
 
-    this.client = new RequestClient(uppy, { serverUrl: this.opts.serverUrl })
+    this.client = new RequestClient(uppy, {
+      serverUrl: this.opts.serverUrl,
+      serverHeaders: this.opts.serverHeaders
+    })
   }
   }
 
 
   getFileNameFromUrl (url) {
   getFileNameFromUrl (url) {