Skip to content

Commit 5df41d7

Browse files
Merge pull request #580 from cloudinary/feature/extra-headers-support
Feature/extra headers support
2 parents 3ef345c + 4559039 commit 5df41d7

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

lib-es5/uploader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,9 @@ function post(url, post_data, boundary, file, callback, options) {
662662
if (options.x_unique_upload_id != null) {
663663
headers['X-Unique-Upload-Id'] = options.x_unique_upload_id;
664664
}
665+
if (options.extra_headers !== null) {
666+
headers = merge(headers, options.extra_headers);
667+
}
665668
if (oauth_token != null) {
666669
headers.Authorization = `Bearer ${oauth_token}`;
667670
}

lib/uploader.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,9 @@ function post(url, post_data, boundary, file, callback, options) {
560560
if (options.x_unique_upload_id != null) {
561561
headers['X-Unique-Upload-Id'] = options.x_unique_upload_id;
562562
}
563+
if (options.extra_headers !== null) {
564+
headers = merge(headers, options.extra_headers);
565+
}
563566
if (oauth_token != null) {
564567
headers.Authorization = `Bearer ${oauth_token}`;
565568
}

test/integration/api/uploader/uploader_spec.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const helper = require("../../../spechelper");
1212
const describe = require('../../../testUtils/suite');
1313
const cloneDeep = require('lodash/cloneDeep');
1414
const ProxyAgent = require('proxy-agent');
15+
const assert = require('assert');
1516

1617
const IMAGE_FILE = helper.IMAGE_FILE;
1718
const LARGE_RAW_FILE = helper.LARGE_RAW_FILE;
@@ -278,19 +279,16 @@ describe("uploader", function () {
278279
tags: UPLOAD_TAGS
279280
});
280281
});
281-
describe("custom headers", function () {
282-
it("should support custom headers in object format e.g. {Link: \"1\"}", function () {
283-
return cloudinary.v2.uploader.upload(IMAGE_FILE, {
284-
headers: {
285-
Link: "1"
286-
},
287-
tags: UPLOAD_TAGS
288-
});
289-
});
290-
it("should support custom headers as array of strings e.g. [\"Link: 1\"]", function () {
291-
return cloudinary.v2.uploader.upload(IMAGE_FILE, {
292-
headers: ["Link: 1"],
293-
tags: UPLOAD_TAGS
282+
describe("extra headers", function () {
283+
it("should support extra headers in object format e.g. {Link: \"1\"}", function () {
284+
return helper.provideMockObjects(function (mockXHR, writeSpy, requestSpy) {
285+
cloudinary.v2.uploader.upload(IMAGE_FILE, {
286+
extra_headers: {
287+
Link: "1"
288+
}
289+
});
290+
assert.ok(requestSpy.args[0][0].headers.Link);
291+
assert.equal(requestSpy.args[0][0].headers.Link, "1");
294292
});
295293
});
296294
});

0 commit comments

Comments
 (0)