Skip to content

Commit

Permalink
feat: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Sep 14, 2023
1 parent 87a0fb1 commit 65843b2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 26 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@
"prettier": "prettier --list-different --write .",
"test": "vitest --coverage"
},
"dependencies": {
"formdata-to-string": "^1.1.0",
"qs": "^6.11.2",
"stringify-object": "^3.3.0"
},
"devDependencies": {
"@readme/eslint-config": "^13.0.1",
"@types/eslint": "^8.44.2",
Expand All @@ -94,10 +99,5 @@
"typescript": "^5.2.2",
"vitest": "^0.34.4"
},
"dependencies": {
"formdata-to-string": "^1.0.1",
"qs": "^6.11.2",
"stringify-object": "^3.3.0"
},
"prettier": "@readme/eslint-config/prettier"
}
18 changes: 1 addition & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,23 +212,7 @@ export class HTTPSnippet {

const boundary = '---011000010111000001101001'; // this is binary for "api"
request.postData.boundary = boundary;
request.postData.text = await formDataToString(form).then(str => {
// `formdata-to-string` creates a boundary that contains `--formdata-undici-<number>`
// but for the purpose of our code snippet we want something a little cleaner.
return str.replace(
/([-]+)formdata-undici-(\d+)/gim,

/**
* The boundary that's in a multipart payload has to have a boundary prefix with two
* extra hyphens. If we don't add this, and just replace the `--formdata-uncici-`
* boundary with our custom boundary then all multipart payloads will end up being
* fully corrutped when a request is made from the client.
*
* @see {@link https://datatracker.ietf.org/doc/html/rfc7578#section-4.1}
*/
`--${boundary}`,
);
});
request.postData.text = await formDataToString(form, { boundary });

// Since headers are case-sensitive we need to see if there's an existing `Content-Type` header that we can override.
const contentTypeHeader = getHeaderName(request.headersObj, 'content-type') || 'content-type';
Expand Down

0 comments on commit 65843b2

Please sign in to comment.