From 65843b2d830fcb934256c7d7dc39c3fd0f838125 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Thu, 14 Sep 2023 09:32:46 -0700 Subject: [PATCH] feat: pr feedback --- package-lock.json | 8 ++++---- package.json | 10 +++++----- src/index.ts | 18 +----------------- 3 files changed, 10 insertions(+), 26 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4312ff646..183ec1d46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "7.1.2", "license": "MIT", "dependencies": { - "formdata-to-string": "^1.0.1", + "formdata-to-string": "^1.1.0", "qs": "^6.11.2", "stringify-object": "^3.3.0" }, @@ -5019,9 +5019,9 @@ } }, "node_modules/formdata-to-string": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/formdata-to-string/-/formdata-to-string-1.0.1.tgz", - "integrity": "sha512-j/HbGO5pXSxR0mJwXzUcbX25b8eU7yuxpaMSgLFpo8T2pOmhJUxPiRbe/GySX0VdN8gfQocEMXu4KkcNucPpeg==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/formdata-to-string/-/formdata-to-string-1.1.0.tgz", + "integrity": "sha512-f+jVhrBYfgRsHnOBL+1djGwZ4qOAXiIz/JrV1qHIE1cJ30b6IxKWmNmWybxR7vgXYhBHVHeqcbhtGE5J5OAXxQ==", "dependencies": { "undici": "^5.24.0" }, diff --git a/package.json b/package.json index d5b6e9dd7..13568a19c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } diff --git a/src/index.ts b/src/index.ts index 4649a43fe..12bb0a3a4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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-` - // 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';