Skip to content

[W-12465439] Missing boundary for multipart content type #32

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

Merged
merged 2 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@api-components/api-request",
"description": "A set of composite components that are used to build an HTTP request editor with the support of the AMF model.",
"version": "0.3.2",
"version": "0.3.3",
"license": "Apache-2.0",
"main": "index.js",
"module": "index.js",
Expand Down
9 changes: 9 additions & 0 deletions src/ApiRequestEditorElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,15 @@ export class ApiRequestEditorElement extends AmfHelperMixin(EventsTargetMixin(Li
});

if (['GET', 'HEAD'].indexOf(result.method) === -1) {
const payload = this._payload
if (payload instanceof FormData) {
const contentType = HeadersParser.contentType(result.headers)
// According to form data documentation: do not explicitly set the Content-Type header on the request. Doing so will prevent
// the browser from being able to set the Content-Type header with the boundary expression it will use to delimit form fields in the request body.
if (contentType && contentType.startsWith('multipart/')) {
result.headers = /** @type string */ (HeadersParser.replace(result.headers, 'content-type', null));
}
}
result.payload = this._payload;
}

Expand Down
12 changes: 10 additions & 2 deletions test/ApiRequestEditorElement.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1054,12 +1054,12 @@ describe('ApiRequestEditorElement', () => {
element.url = 'some-url';
});

it('should not remove multipart content type if form data payload', () => {
it('should remove multipart content type if form data payload', () => {
element._headers = 'content-type: multipart/form-data';
element._payload = new FormData()
const request = element.serializeRequest()

assert.equal(request.headers, 'content-type: multipart/form-data');
assert.equal(request.headers, '');
});

it('should not modify headers if content type not defined and form data payload', () => {
Expand All @@ -1069,6 +1069,14 @@ describe('ApiRequestEditorElement', () => {

assert.equal(request.headers, '');
});

it('should not modify headers if content type not multipart and form data payload', () => {
element._headers = 'content-type: application/x-www-form-urlencoded';
element._payload = new FormData()
const request = element.serializeRequest()

assert.equal(request.headers, 'content-type: application/x-www-form-urlencoded');
});
});

describe('allowHideOptional', () => {
Expand Down