-
Notifications
You must be signed in to change notification settings - Fork 241
fix(curl) remove boundary form content-type header #227
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
|
|
||
| const util = require('util') | ||
| const helpers = require('../../helpers/shell') | ||
| const headerHelpers = require('../../helpers/headers') | ||
| const CodeBuilder = require('../../helpers/code-builder') | ||
|
|
||
| module.exports = function (source, options) { | ||
|
|
@@ -39,6 +40,22 @@ module.exports = function (source, options) { | |
| code.push(opts.short ? '-0' : '--http1.0') | ||
| } | ||
|
|
||
| // if multipart form data, we want to remove the boundary | ||
| if (source.postData.mimeType === 'multipart/form-data') { | ||
| const contentTypeHeaderName = headerHelpers.getHeaderName(source.headersObj, 'content-type') | ||
| const contentTypeHeader = source.headersObj[contentTypeHeaderName] | ||
|
|
||
| if (contentTypeHeaderName && contentTypeHeader) { | ||
| // remove the leading semi colon and boundary | ||
| // up to the next semi colon or the end of string | ||
| const noBoundary = contentTypeHeader.replace(/; boundary.+?(?=(;|$))/, '') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // replace the content-type header with no boundary in both headersObj and allHeaders | ||
| source.headersObj[contentTypeHeaderName] = noBoundary | ||
| source.allHeaders[contentTypeHeaderName] = noBoundary | ||
| } | ||
| } | ||
|
|
||
| // construct headers | ||
| Object.keys(source.headersObj).sort().forEach(function (key) { | ||
| const header = util.format('%s: %s', key, source.headersObj[key]) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| curl --request POST \ | ||
| --url http://mockbin.com/har \ | ||
| --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ | ||
| --header 'content-type: multipart/form-data' \ | ||
| --form [email protected] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| curl --request POST \ | ||
| --url http://mockbin.com/har \ | ||
| --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ | ||
| --header 'content-type: multipart/form-data' \ | ||
| --form foo=@test/fixtures/files/hello.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| curl --request POST \ | ||
| --url http://mockbin.com/har \ | ||
| --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \ | ||
| --header 'Content-Type: multipart/form-data' \ | ||
| --form foo=bar |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

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.
Per #226, we discussed just scoping this to fixing cURL due to how cURL handles
--formvs raw data.Did you attempt any kind of audit of other targets to see if they are impacted by similar issues?
Uh oh!
There was an error while loading. Please reload this page.
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.
I have not investigate any other targets yet, this fix only pertains to curl multipart