-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Companion option uploadHeaders
#5981
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
Conversation
COMPANION_UPLOAD_HEADERS
🦋 Changeset detectedLatest commit: 2cd02ac The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Diff output filesdiff --git a/packages/@uppy/companion/lib/server/Uploader.d.ts b/packages/@uppy/companion/lib/server/Uploader.d.ts
index 8c222eb..825d14f 100644
--- a/packages/@uppy/companion/lib/server/Uploader.d.ts
+++ b/packages/@uppy/companion/lib/server/Uploader.d.ts
@@ -52,9 +52,9 @@ declare class Uploader {
* @property {number} [chunkSize]
* @property {string} [providerName]
*
- * @param {UploaderOptions} options
+ * @param {UploaderOptions} optionsIn
*/
- constructor(options: {
+ constructor(optionsIn: {
endpoint: string;
uploadUrl?: string;
protocol: string;
@@ -75,6 +75,7 @@ declare class Uploader {
storage: import("ioredis").Redis;
providerName: string;
options: {
+ headers: any;
endpoint: string;
uploadUrl?: string;
protocol: string;
@@ -85,7 +86,6 @@ declare class Uploader {
metadata: any;
companionOptions: any;
storage?: any;
- headers?: any;
httpMethod?: string;
useFormData?: boolean;
chunkSize?: number;
diff --git a/packages/@uppy/companion/lib/server/Uploader.js b/packages/@uppy/companion/lib/server/Uploader.js
index 310c2ba..966a17c 100644
--- a/packages/@uppy/companion/lib/server/Uploader.js
+++ b/packages/@uppy/companion/lib/server/Uploader.js
@@ -122,10 +122,17 @@ export default class Uploader {
* @property {number} [chunkSize]
* @property {string} [providerName]
*
- * @param {UploaderOptions} options
+ * @param {UploaderOptions} optionsIn
*/
- constructor(options) {
- validateOptions(options);
+ constructor(optionsIn) {
+ validateOptions(optionsIn);
+ const options = {
+ ...optionsIn,
+ headers: {
+ ...optionsIn.headers,
+ ...optionsIn.companionOptions.uploadHeaders,
+ },
+ };
this.providerName = options.providerName;
this.options = options;
this.token = randomUUID();
@@ -547,7 +554,7 @@ export default class Uploader {
}
try {
const httpMethod = (this.options.httpMethod || "").toUpperCase() === "PUT" ? "put" : "post";
- const runRequest = await got[httpMethod];
+ const runRequest = got[httpMethod];
const response = await runRequest(url, reqOptions);
if (this.size != null && bytesUploaded !== this.size) {
const errMsg = `uploaded only ${bytesUploaded} of ${this.size} with status: ${response.statusCode}`;
diff --git a/packages/@uppy/companion/lib/standalone/helper.js b/packages/@uppy/companion/lib/standalone/helper.js
index a5f931f..fbba5f2 100644
--- a/packages/@uppy/companion/lib/standalone/helper.js
+++ b/packages/@uppy/companion/lib/standalone/helper.js
@@ -195,6 +195,9 @@ const getConfigFromEnv = () => {
corsOrigins: getCorsOrigins(),
testDynamicOauthCredentials: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS === "true",
testDynamicOauthCredentialsSecret: process.env.COMPANION_TEST_DYNAMIC_OAUTH_CREDENTIALS_SECRET,
+ uploadHeaders: process.env.COMPANION_UPLOAD_HEADERS
+ ? JSON.parse(process.env.COMPANION_UPLOAD_HEADERS)
+ : undefined,
};
};
/** |
(instead of *after* all tests) this makes tests independent (not depending on mocks from previous tests) this also uncovered bugs in tests which have been fixed remove duplicate (and broken) test 'dropbox' remove workaround for test "upload functions with xhr protocol"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget the changeset, ideally also explaining there what this feature does
New Companion option `uploadHeaders` allows inclusion of static headers for all upload requests.
closes #5921
also improve tests that currently depend on eachother
todo
uploadHeadersuppy.io#394