From f99294bff43599bf44af19610cd80ca376c1c023 Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Wed, 13 Sep 2023 23:23:57 -0700 Subject: [PATCH] feat: dropping support for non-native FormData implementations --- .eslintrc | 4 +- .sink.d.ts | 1 - README.md | 41 ++++---- package-lock.json | 95 ++++++++----------- package.json | 5 +- src/fixtures/runCustomFixtures.ts | 10 +- src/helpers/form-data.ts | 76 --------------- src/index.ts | 86 ++++++----------- src/integration.test.ts | 1 + .../c/libcurl/fixtures/multipart-data.c | 2 +- .../c/libcurl/fixtures/multipart-file.c | 2 +- .../c/libcurl/fixtures/multipart-form-data.c | 2 +- .../go/native/fixtures/multipart-data.go | 2 +- .../go/native/fixtures/multipart-file.go | 2 +- .../go/native/fixtures/multipart-form-data.go | 2 +- .../http/http1.1/fixtures/multipart-data | 6 +- .../http/http1.1/fixtures/multipart-file | 6 +- .../http/http1.1/fixtures/multipart-form-data | 4 +- src/targets/index.test.ts | 42 ++++---- .../asynchttp/fixtures/multipart-data.java | 2 +- .../asynchttp/fixtures/multipart-file.java | 2 +- .../fixtures/multipart-form-data.java | 2 +- .../java/nethttp/fixtures/multipart-data.java | 2 +- .../java/nethttp/fixtures/multipart-file.java | 2 +- .../nethttp/fixtures/multipart-form-data.java | 2 +- .../java/okhttp/fixtures/multipart-data.java | 2 +- .../java/okhttp/fixtures/multipart-file.java | 2 +- .../okhttp/fixtures/multipart-form-data.java | 2 +- .../java/unirest/fixtures/multipart-data.java | 2 +- .../java/unirest/fixtures/multipart-file.java | 2 +- .../unirest/fixtures/multipart-form-data.java | 2 +- .../kotlin/okhttp/fixtures/multipart-data.kt | 2 +- .../kotlin/okhttp/fixtures/multipart-file.kt | 2 +- .../okhttp/fixtures/multipart-form-data.kt | 2 +- .../node/axios/fixtures/multipart-data.cjs | 2 +- .../node/axios/fixtures/multipart-file.cjs | 2 +- .../axios/fixtures/multipart-form-data.cjs | 2 +- .../node/native/fixtures/multipart-data.cjs | 2 +- .../node/native/fixtures/multipart-file.cjs | 2 +- .../native/fixtures/multipart-form-data.cjs | 2 +- .../ocaml/cohttp/fixtures/multipart-data.ml | 2 +- .../ocaml/cohttp/fixtures/multipart-file.ml | 2 +- .../cohttp/fixtures/multipart-form-data.ml | 2 +- .../php/curl/fixtures/multipart-data.php | 2 +- .../php/curl/fixtures/multipart-file.php | 2 +- .../php/curl/fixtures/multipart-form-data.php | 2 +- .../php/http1/fixtures/multipart-data.php | 5 +- .../php/http1/fixtures/multipart-file.php | 5 +- .../http1/fixtures/multipart-form-data.php | 3 +- .../restmethod/fixtures/multipart-data.ps1 | 5 +- .../restmethod/fixtures/multipart-file.ps1 | 5 +- .../fixtures/multipart-form-data.ps1 | 3 +- .../webrequest/fixtures/multipart-data.ps1 | 5 +- .../webrequest/fixtures/multipart-file.ps1 | 5 +- .../fixtures/multipart-form-data.ps1 | 3 +- .../requests/fixtures/multipart-form-data.py | 2 +- src/targets/r/httr/fixtures/multipart-data.r | 2 +- src/targets/r/httr/fixtures/multipart-file.r | 2 +- .../r/httr/fixtures/multipart-form-data.r | 2 +- .../ruby/native/fixtures/multipart-data.rb | 2 +- .../ruby/native/fixtures/multipart-file.rb | 2 +- .../native/fixtures/multipart-form-data.rb | 2 +- .../shell/httpie/fixtures/multipart-data.sh | 5 +- .../shell/httpie/fixtures/multipart-file.sh | 5 +- .../httpie/fixtures/multipart-form-data.sh | 3 +- .../shell/wget/fixtures/multipart-data.sh | 2 +- .../shell/wget/fixtures/multipart-file.sh | 2 +- .../wget/fixtures/multipart-form-data.sh | 2 +- tsconfig.json | 3 - 69 files changed, 194 insertions(+), 324 deletions(-) delete mode 100644 .sink.d.ts delete mode 100644 src/helpers/form-data.ts diff --git a/.eslintrc b/.eslintrc index 7daa119de..239f510dd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -20,7 +20,9 @@ "unicorn/prefer-node-protocol": "error", - "vitest/require-hook": "off" + "vitest/require-hook": ["error", { + "allowedFunctionCalls": ["runCustomFixtures"] + }] }, "overrides": [ { diff --git a/.sink.d.ts b/.sink.d.ts deleted file mode 100644 index 019dd72be..000000000 --- a/.sink.d.ts +++ /dev/null @@ -1 +0,0 @@ -declare module 'map-stream'; diff --git a/README.md b/README.md index a047ce968..6c8d19a35 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ Type: `object` Available options: -* `harIsAlreadyEncoded` (`boolean`): In the event of you supplying a `source` HAR that already contains escaped data (query and cookie parameters)strings, this allows you to disable automatic encoding of those parameters to prevent them from being double-escaped. +- `harIsAlreadyEncoded` (`boolean`): In the event of you supplying a `source` HAR that already contains escaped data (query and cookie parameters)strings, this allows you to disable automatic encoding of those parameters to prevent them from being double-escaped. ### convert(target [, options]) @@ -159,32 +159,31 @@ For detailed information on each target, please review the [wiki](https://github There are some major differences between this library and the [httpsnippet](https://github.com/Kong/httpsnippet) upstream: -* Includes a full integration test suite for a handful of clients and targets. -* Does not ship with a CLI component. -* Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid. -* The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs. - * We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data. -* Does not support the `insecureSkipVerify` option on `go:native`, `node:native`, `ruby:native`, and `shell:curl` as we don't want snippets generated for our users to bypass SSL certificate verification. -* Node - * `fetch` - * Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as well. - * `request` - * Does not provide query string parameters in a `params` argument due to complexities with query encoding. -* PHP - * `guzzle` - * Snippets have `require_once('vendor/autoload.php');` prefixed at the top. -* Python - * `python3` - * Does not ship this client due to its incompatibility with being able to support file uploads. - * `requests` - * Does not provide query string parameters in a `params` argument due to complexities with query encoding. +- Includes a full integration test suite for a handful of clients and targets. +- Does not ship with a CLI component. +- Does not do any HAR schema validation. It's just assumed that the HAR you're supplying to the library is already valid. +- The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs. + - We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data. +- Does not support the `insecureSkipVerify` option on `go:native`, `node:native`, `ruby:native`, and `shell:curl` as we don't want snippets generated for our users to bypass SSL certificate verification. +- Node + - `fetch` + - Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as well. + - `request` + - Does not provide query string parameters in a `params` argument due to complexities with query encoding. +- PHP + - `guzzle` + - Snippets have `require_once('vendor/autoload.php');` prefixed at the top. +- Python + - `python3` + - Does not ship this client due to its incompatibility with being able to support file uploads. + - `requests` + - Does not provide query string parameters in a `params` argument due to complexities with query encoding. ## License [MIT](LICENSE) © [Kong](https://konghq.com) [license-url]: https://github.com/Kong/httpsnippet/blob/master/LICENSE - [npm-url]: https://www.npmjs.com/package/@readme/httpsnippet [npm-license]: https://img.shields.io/npm/l/@readme/httpsnippet.svg?style=flat-square [npm-version]: https://img.shields.io/npm/v/@readme/httpsnippet.svg?style=flat-square diff --git a/package-lock.json b/package-lock.json index 9da73606f..4312ff646 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,7 @@ "version": "7.1.2", "license": "MIT", "dependencies": { - "form-data": "^4.0.0", - "map-stream": "^0.0.7", + "formdata-to-string": "^1.0.1", "qs": "^6.11.2", "stringify-object": "^3.3.0" }, @@ -2659,11 +2658,6 @@ "has-symbols": "^1.0.3" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" - }, "node_modules/available-typed-arrays": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz", @@ -2944,6 +2938,17 @@ "esbuild": ">=0.17" } }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/cac": { "version": "6.7.14", "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", @@ -3198,17 +3203,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -3492,14 +3486,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/dequal": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", @@ -5032,17 +5018,15 @@ "is-callable": "^1.1.3" } }, - "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "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==", "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "undici": "^5.24.0" }, "engines": { - "node": ">= 6" + "node": ">=18" } }, "node_modules/fs.realpath": { @@ -7025,11 +7009,6 @@ "tmpl": "1.0.5" } }, - "node_modules/map-stream": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/map-stream/-/map-stream-0.0.7.tgz", - "integrity": "sha512-C0X0KQmGm3N2ftbTGBhSyuydQ+vV1LC3f3zPvT3RXHXNZrvfPZcoXp/N5DOa8vedX/rTMm2CjTtivFg2STJMRQ==" - }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", @@ -7058,25 +7037,6 @@ "node": ">=8.6" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mimic-fn": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", @@ -8343,6 +8303,14 @@ "integrity": "sha512-f9aPhy8fYBuMN+sNfakZV18U39PbalgjXG3lLB9WkaYTxijru61wb57V9wxxNthXM5Sd88ETBWi29qLAsHO52Q==", "dev": true }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/string-length": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/string-length/-/string-length-4.0.2.tgz", @@ -9020,6 +8988,17 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici": { + "version": "5.24.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.24.0.tgz", + "integrity": "sha512-OKlckxBjFl0oXxcj9FU6oB8fDAaiRUq+D8jrFWGmOfI/gIyjk/IeS75LMzgYKUaeHzLUcYvf9bbJGSrUwTfwwQ==", + "dependencies": { + "busboy": "^1.6.0" + }, + "engines": { + "node": ">=14.0" + } + }, "node_modules/untildify": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz", diff --git a/package.json b/package.json index 4c8860891..9e2d1e877 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "prebuild": "npm run clean", "prepack": "npm run build", "pretest": "npm run lint", - "prettier": "prettier --list-different --write \"./**/**.{js,ts}\"", + "prettier": "prettier --list-different --write \"./**/**.{md,cjs,js,ts}\"", "test": "vitest --coverage" }, "devDependencies": { @@ -95,8 +95,7 @@ "vitest": "^0.34.4" }, "dependencies": { - "form-data": "^4.0.0", - "map-stream": "^0.0.7", + "formdata-to-string": "^1.0.1", "qs": "^6.11.2", "stringify-object": "^3.3.0" }, diff --git a/src/fixtures/runCustomFixtures.ts b/src/fixtures/runCustomFixtures.ts index d5cd8f4b4..7f000921a 100644 --- a/src/fixtures/runCustomFixtures.ts +++ b/src/fixtures/runCustomFixtures.ts @@ -24,7 +24,7 @@ export interface CustomFixture { export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture) => { describe(`custom fixtures for ${targetId}:${clientId}`, () => { - tests.forEach(async ({ it: title, expected: fixtureFile, options, input: request }) => { + it.each(tests.map(t => [t.it, t]))('%s', async (_, { expected: fixtureFile, options, input: request }) => { const opts: HTTPSnippetOptions = {}; if (options.harIsAlreadyEncoded) { opts.harIsAlreadyEncoded = options.harIsAlreadyEncoded; @@ -39,12 +39,10 @@ export const runCustomFixtures = ({ targetId, clientId, tests }: CustomFixture) writeFileSync(filePath, String(result)); } - it(title, async () => { - const buffer = await readFile(filePath); - const fixture = String(buffer); + const buffer = await readFile(filePath); + const fixture = String(buffer); - expect(result).toStrictEqual(fixture); - }); + expect(result).toStrictEqual(fixture); }); }); }; diff --git a/src/helpers/form-data.ts b/src/helpers/form-data.ts deleted file mode 100644 index ada2761a5..000000000 --- a/src/helpers/form-data.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @license https://raw.githubusercontent.com/node-fetch/node-fetch/master/LICENSE.md - * - * The MIT License (MIT) - * - * Copyright (c) 2016 - 2020 Node Fetch Team - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - * - * Extracted from https://github.com/node-fetch/node-fetch/blob/64c5c296a0250b852010746c76144cb9e14698d9/src/utils/form-data.js - */ - -import type FormData from 'form-data'; - -const carriage = '\r\n'; -const dashes = '-'.repeat(2); - -const NAME = Symbol.toStringTag; - -export const isBlob = (object: any) => - typeof object === 'object' && - typeof object.arrayBuffer === 'function' && - typeof object.type === 'string' && - typeof object.stream === 'function' && - typeof object.constructor === 'function' && - /^(Blob|File)$/.test(object[NAME]); - -const getFooter = (boundary: string) => `${dashes}${boundary}${dashes}${carriage.repeat(2)}`; - -const getHeader = (boundary: string, name: string, field: { name: string; type: string }) => { - let header = ''; - - header += `${dashes}${boundary}${carriage}`; - header += `Content-Disposition: form-data; name="${name}"`; - - if (isBlob(field)) { - header += `; filename="${field.name}"${carriage}`; - header += `Content-Type: ${field.type || 'application/octet-stream'}`; - } - - return `${header}${carriage.repeat(2)}`; -}; - -export const formDataIterator = function* (form: FormData, boundary: string) { - // @ts-expect-error not sure how this ever worked - // eslint-disable-next-line no-restricted-syntax - for (const [name, value] of form) { - yield getHeader(boundary, name, value); - - if (isBlob(value)) { - yield* value.stream(); - } else { - yield value; - } - - yield carriage; - } - - yield getFooter(boundary); -}; diff --git a/src/index.ts b/src/index.ts index 5300cd5de..84d20e526 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,12 +5,9 @@ import type { UrlWithParsedQuery } from 'node:url'; import { format as urlFormat, parse as urlParse } from 'node:url'; -import FormData from 'form-data'; +import formDataToString from 'formdata-to-string'; import { stringify as queryStringify } from 'qs'; -import mapStream from 'map-stream'; - -import { formDataIterator, isBlob } from './helpers/form-data.js'; import { getHeaderName } from './helpers/headers.js'; import { reducer } from './helpers/reducer.js'; import { targets } from './targets/index.js'; @@ -103,8 +100,11 @@ export class HTTPSnippet { } } - init() { + async init() { this.initCalled = true; + + const promises: Promise[] = []; + this.entries.forEach(({ request }) => { // add optional properties to make validation successful const req = { @@ -125,13 +125,15 @@ export class HTTPSnippet { req.postData.mimeType = 'application/octet-stream'; } - this.requests.push(this.prepare(req as HarRequest, this.options)); + promises.push(this.prepare(req as HarRequest, this.options)); }); + this.requests = await Promise.all(promises); + return this; } - prepare(harRequest: HarRequest, options: HTTPSnippetOptions) { + async prepare(harRequest: HarRequest, options: HTTPSnippetOptions) { const request: Request = { ...harRequest, fullUrl: '', @@ -195,64 +197,38 @@ export class HTTPSnippet { if (request.postData?.params) { const form = new FormData(); - // The `form-data` module returns one of two things: a native FormData object, or its own polyfill - // Since the polyfill does not support the full API of the native FormData object, when this library is running in a browser environment it'll fail on two things: - // - // 1. The API for `form.append()` has three arguments and the third should only be present when the second is a - // Blob or USVString. - // 1. `FormData.pipe()` isn't a function. - // - // Since the native FormData object is iterable, we easily detect what version of `form-data` we're working with here to allow `multipart/form-data` requests to be compiled under both browser and Node environments. - // - // This hack is pretty awful but it's the only way we can use this library in the browser as if we code this against just the native FormData object, we can't polyfill that back into Node because Blob and File objects, which something like `formdata-polyfill` requires, don't exist there. - // @ts-expect-error TODO - const isNativeFormData = typeof form[Symbol.iterator] === 'function'; - - // TODO: THIS ABSOLUTELY MUST BE REMOVED. - // IT BREAKS SOME USE-CASES FOR MULTIPART FORMS THAT DEPEND ON BEING ABLE TO SET THE BOUNDARY. - // easter egg - const boundary = '---011000010111000001101001'; // this is binary for "api". yep. - if (!isNativeFormData) { - // @ts-expect-error THIS IS WRONG. VERY WRONG. - form._boundary = boundary; - } - request.postData?.params.forEach(param => { const name = param.name; const value = param.value || ''; const filename = param.fileName || null; + const contentType = param.contentType || ''; - if (isNativeFormData) { - if (isBlob(value)) { - // @ts-expect-error TODO - form.append(name, value, filename); - } else { - form.append(name, value); - } + if (filename) { + form.append(name, new Blob([value], { type: contentType }), filename); } else { - form.append(name, value, { - // @ts-expect-error TODO - filename, - // @ts-expect-error TODO - contentType: param.contentType || null, - }); + form.append(name, value); } }); - if (isNativeFormData) { - // eslint-disable-next-line no-restricted-syntax - for (const data of formDataIterator(form, boundary)) { - request.postData.text += data; - } - } else { - form.pipe( - mapStream((data: string) => { - request.postData.text += data; - }), - ); - } - + 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}`, + ); + }); // 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'; diff --git a/src/integration.test.ts b/src/integration.test.ts index 4994c8911..97495b794 100644 --- a/src/integration.test.ts +++ b/src/integration.test.ts @@ -131,6 +131,7 @@ function looseJSONParse(obj: any) { return new Function(`"use strict";return ${obj}`)(); } +// eslint-disable-next-line vitest/require-hook availableTargets() .filter(target => target.cli) .filter(testFilter('key', environmentFilter())) diff --git a/src/targets/c/libcurl/fixtures/multipart-data.c b/src/targets/c/libcurl/fixtures/multipart-data.c index cab81e014..3969a1b40 100644 --- a/src/targets/c/libcurl/fixtures/multipart-data.c +++ b/src/targets/c/libcurl/fixtures/multipart-data.c @@ -8,6 +8,6 @@ struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); -curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n"); +curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--"); CURLcode ret = curl_easy_perform(hnd); \ No newline at end of file diff --git a/src/targets/c/libcurl/fixtures/multipart-file.c b/src/targets/c/libcurl/fixtures/multipart-file.c index 75863ae92..4747d1df8 100644 --- a/src/targets/c/libcurl/fixtures/multipart-file.c +++ b/src/targets/c/libcurl/fixtures/multipart-file.c @@ -8,6 +8,6 @@ struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=---011000010111000001101001"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); -curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n"); +curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"); CURLcode ret = curl_easy_perform(hnd); \ No newline at end of file diff --git a/src/targets/c/libcurl/fixtures/multipart-form-data.c b/src/targets/c/libcurl/fixtures/multipart-form-data.c index 59f6d0104..e4cd6b5f6 100644 --- a/src/targets/c/libcurl/fixtures/multipart-form-data.c +++ b/src/targets/c/libcurl/fixtures/multipart-form-data.c @@ -8,6 +8,6 @@ struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: multipart/form-data; boundary=---011000010111000001101001"); curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers); -curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n"); +curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--"); CURLcode ret = curl_easy_perform(hnd); \ No newline at end of file diff --git a/src/targets/go/native/fixtures/multipart-data.go b/src/targets/go/native/fixtures/multipart-data.go index 9b1447fea..07a89749b 100644 --- a/src/targets/go/native/fixtures/multipart-data.go +++ b/src/targets/go/native/fixtures/multipart-data.go @@ -11,7 +11,7 @@ func main() { url := "https://httpbin.org/anything" - payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n") + payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--") req, _ := http.NewRequest("POST", url, payload) diff --git a/src/targets/go/native/fixtures/multipart-file.go b/src/targets/go/native/fixtures/multipart-file.go index 9bbf569dd..651872e0c 100644 --- a/src/targets/go/native/fixtures/multipart-file.go +++ b/src/targets/go/native/fixtures/multipart-file.go @@ -11,7 +11,7 @@ func main() { url := "https://httpbin.org/anything" - payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") + payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") req, _ := http.NewRequest("POST", url, payload) diff --git a/src/targets/go/native/fixtures/multipart-form-data.go b/src/targets/go/native/fixtures/multipart-form-data.go index 78e2779bb..b519753c1 100644 --- a/src/targets/go/native/fixtures/multipart-form-data.go +++ b/src/targets/go/native/fixtures/multipart-form-data.go @@ -11,7 +11,7 @@ func main() { url := "https://httpbin.org/anything" - payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") + payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") req, _ := http.NewRequest("POST", url, payload) diff --git a/src/targets/http/http1.1/fixtures/multipart-data b/src/targets/http/http1.1/fixtures/multipart-data index a7c2b3cfd..b0db0b607 100644 --- a/src/targets/http/http1.1/fixtures/multipart-data +++ b/src/targets/http/http1.1/fixtures/multipart-data @@ -1,10 +1,10 @@ POST /anything HTTP/1.1 Content-Type: multipart/form-data; boundary=---011000010111000001101001 Host: httpbin.org -Content-Length: 266 +Content-Length: 283 -----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain Hello World @@ -12,4 +12,4 @@ Hello World Content-Disposition: form-data; name="bar" Bonjour le monde ------011000010111000001101001-- +-----011000010111000001101001-- \ No newline at end of file diff --git a/src/targets/http/http1.1/fixtures/multipart-file b/src/targets/http/http1.1/fixtures/multipart-file index 791374b6c..13b7f1bd9 100644 --- a/src/targets/http/http1.1/fixtures/multipart-file +++ b/src/targets/http/http1.1/fixtures/multipart-file @@ -1,11 +1,11 @@ POST /anything HTTP/1.1 Content-Type: multipart/form-data; boundary=---011000010111000001101001 Host: httpbin.org -Content-Length: 160 +Content-Length: 177 -----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain ------011000010111000001101001-- +-----011000010111000001101001-- \ No newline at end of file diff --git a/src/targets/http/http1.1/fixtures/multipart-form-data b/src/targets/http/http1.1/fixtures/multipart-form-data index 6f7fafef9..cde9fcc99 100644 --- a/src/targets/http/http1.1/fixtures/multipart-form-data +++ b/src/targets/http/http1.1/fixtures/multipart-form-data @@ -1,10 +1,10 @@ POST /anything HTTP/1.1 Content-Type: multipart/form-data; boundary=---011000010111000001101001 Host: httpbin.org -Content-Length: 115 +Content-Length: 113 -----011000010111000001101001 Content-Disposition: form-data; name="foo" bar ------011000010111000001101001-- +-----011000010111000001101001-- \ No newline at end of file diff --git a/src/targets/index.test.ts b/src/targets/index.test.ts index 6d7e057a5..6245f4914 100644 --- a/src/targets/index.test.ts +++ b/src/targets/index.test.ts @@ -53,13 +53,18 @@ const testFilter = (item: T) => list.length > 0 ? list.includes(item[property]) : true; -availableTargets() - .filter(testFilter('key', targetFilter)) - .forEach(({ key: targetId, title, clients }) => { - describe(`${title} Request Validation`, () => { - clients.filter(testFilter('key', clientFilter)).forEach(({ key: clientId, extname: fixtureExtension }) => { - describe(`${clientId}`, () => { - fixtures.filter(testFilter(0, fixtureFilter)).forEach(async ([fixture, request]) => { +describe('request validation', () => { + describe.each( + availableTargets() + .filter(testFilter('key', targetFilter)) + .map(target => [target.key, target]), + )('%s', (title, { key: targetId, clients }) => { + describe.each(clients.filter(testFilter('key', clientFilter)).map(client => [client.key, client]))( + '%s', + (clientId, { extname: fixtureExtension }) => { + it.each(fixtures.filter(testFilter(0, fixtureFilter)))( + 'request should match fixture for "%s.js"', + async (fixture, request) => { const expectedPath = path.join( 'src', 'targets', @@ -68,6 +73,10 @@ availableTargets() 'fixtures', `${fixture}${extname(targetId, clientId)}`, ); + + let result; + let expected; + try { const options: HTTPSnippetOptions = {}; @@ -76,20 +85,16 @@ availableTargets() options.harIsAlreadyEncoded = true; } - const expected = readFileSync(expectedPath).toString(); + expected = readFileSync(expectedPath).toString(); const snippet = new HTTPSnippet(request, options); await snippet.init(); - const result = snippet.convert(targetId, clientId); + result = snippet.convert(targetId, clientId); if (OVERWRITE_EVERYTHING && result) { writeFileSync(expectedPath, String(result)); return; } - - it(`request should match fixture for "${fixture}.js"`, () => { - expect(result).toStrictEqual(expected); - }); } catch (err) { if (err.constructor.name === 'HARError') { throw err; @@ -101,11 +106,14 @@ availableTargets() }\``, ); } - }); - }); - }); - }); + + expect(result).toStrictEqual(expected); + }, + ); + }, + ); }); +}); describe('isTarget', () => { it("should throw if you don't provide an object", () => { diff --git a/src/targets/java/asynchttp/fixtures/multipart-data.java b/src/targets/java/asynchttp/fixtures/multipart-data.java index eaae94ce0..6e118f6fd 100644 --- a/src/targets/java/asynchttp/fixtures/multipart-data.java +++ b/src/targets/java/asynchttp/fixtures/multipart-data.java @@ -1,7 +1,7 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); client.prepare("POST", "https://httpbin.org/anything") .setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n") + .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/src/targets/java/asynchttp/fixtures/multipart-file.java b/src/targets/java/asynchttp/fixtures/multipart-file.java index 88d7c833f..623982dbe 100644 --- a/src/targets/java/asynchttp/fixtures/multipart-file.java +++ b/src/targets/java/asynchttp/fixtures/multipart-file.java @@ -1,7 +1,7 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); client.prepare("POST", "https://httpbin.org/anything") .setHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") + .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/src/targets/java/asynchttp/fixtures/multipart-form-data.java b/src/targets/java/asynchttp/fixtures/multipart-form-data.java index f557f52aa..731b01113 100644 --- a/src/targets/java/asynchttp/fixtures/multipart-form-data.java +++ b/src/targets/java/asynchttp/fixtures/multipart-form-data.java @@ -1,7 +1,7 @@ AsyncHttpClient client = new DefaultAsyncHttpClient(); client.prepare("POST", "https://httpbin.org/anything") .setHeader("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") - .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") + .setBody("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") .execute() .toCompletableFuture() .thenAccept(System.out::println) diff --git a/src/targets/java/nethttp/fixtures/multipart-data.java b/src/targets/java/nethttp/fixtures/multipart-data.java index 452fc4c40..c77af1c99 100644 --- a/src/targets/java/nethttp/fixtures/multipart-data.java +++ b/src/targets/java/nethttp/fixtures/multipart-data.java @@ -1,7 +1,7 @@ HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://httpbin.org/anything")) .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n")) + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--")) .build(); HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); \ No newline at end of file diff --git a/src/targets/java/nethttp/fixtures/multipart-file.java b/src/targets/java/nethttp/fixtures/multipart-file.java index 9f4e46255..c225700fb 100644 --- a/src/targets/java/nethttp/fixtures/multipart-file.java +++ b/src/targets/java/nethttp/fixtures/multipart-file.java @@ -1,7 +1,7 @@ HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://httpbin.org/anything")) .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n")) + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--")) .build(); HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); \ No newline at end of file diff --git a/src/targets/java/nethttp/fixtures/multipart-form-data.java b/src/targets/java/nethttp/fixtures/multipart-form-data.java index 705025f89..6362ce4e8 100644 --- a/src/targets/java/nethttp/fixtures/multipart-form-data.java +++ b/src/targets/java/nethttp/fixtures/multipart-form-data.java @@ -1,7 +1,7 @@ HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://httpbin.org/anything")) .header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") - .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n")) + .method("POST", HttpRequest.BodyPublishers.ofString("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--")) .build(); HttpResponse response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); \ No newline at end of file diff --git a/src/targets/java/okhttp/fixtures/multipart-data.java b/src/targets/java/okhttp/fixtures/multipart-data.java index dad3de42e..45ee7bb65 100644 --- a/src/targets/java/okhttp/fixtures/multipart-data.java +++ b/src/targets/java/okhttp/fixtures/multipart-data.java @@ -1,7 +1,7 @@ OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); -RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n"); +RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--"); Request request = new Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/java/okhttp/fixtures/multipart-file.java b/src/targets/java/okhttp/fixtures/multipart-file.java index eed10e5dd..713ba109d 100644 --- a/src/targets/java/okhttp/fixtures/multipart-file.java +++ b/src/targets/java/okhttp/fixtures/multipart-file.java @@ -1,7 +1,7 @@ OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); -RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n"); +RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--"); Request request = new Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/java/okhttp/fixtures/multipart-form-data.java b/src/targets/java/okhttp/fixtures/multipart-form-data.java index c516d23a6..cafbe51ef 100644 --- a/src/targets/java/okhttp/fixtures/multipart-form-data.java +++ b/src/targets/java/okhttp/fixtures/multipart-form-data.java @@ -1,7 +1,7 @@ OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); -RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n"); +RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--"); Request request = new Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/java/unirest/fixtures/multipart-data.java b/src/targets/java/unirest/fixtures/multipart-data.java index b6c2fcc38..0d517412e 100644 --- a/src/targets/java/unirest/fixtures/multipart-data.java +++ b/src/targets/java/unirest/fixtures/multipart-data.java @@ -1,4 +1,4 @@ HttpResponse response = Unirest.post("https://httpbin.org/anything") .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n") + .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--") .asString(); \ No newline at end of file diff --git a/src/targets/java/unirest/fixtures/multipart-file.java b/src/targets/java/unirest/fixtures/multipart-file.java index 88007d3a1..285119aff 100644 --- a/src/targets/java/unirest/fixtures/multipart-file.java +++ b/src/targets/java/unirest/fixtures/multipart-file.java @@ -1,4 +1,4 @@ HttpResponse response = Unirest.post("https://httpbin.org/anything") .header("content-type", "multipart/form-data; boundary=---011000010111000001101001") - .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") + .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") .asString(); \ No newline at end of file diff --git a/src/targets/java/unirest/fixtures/multipart-form-data.java b/src/targets/java/unirest/fixtures/multipart-form-data.java index 00a0637f5..8cbc64d8d 100644 --- a/src/targets/java/unirest/fixtures/multipart-form-data.java +++ b/src/targets/java/unirest/fixtures/multipart-form-data.java @@ -1,4 +1,4 @@ HttpResponse response = Unirest.post("https://httpbin.org/anything") .header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001") - .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") + .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") .asString(); \ No newline at end of file diff --git a/src/targets/kotlin/okhttp/fixtures/multipart-data.kt b/src/targets/kotlin/okhttp/fixtures/multipart-data.kt index 0ac868046..adc042888 100644 --- a/src/targets/kotlin/okhttp/fixtures/multipart-data.kt +++ b/src/targets/kotlin/okhttp/fixtures/multipart-data.kt @@ -1,7 +1,7 @@ val client = OkHttpClient() val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001") -val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n") +val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--") val request = Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/kotlin/okhttp/fixtures/multipart-file.kt b/src/targets/kotlin/okhttp/fixtures/multipart-file.kt index bb12a5e92..3f1908c00 100644 --- a/src/targets/kotlin/okhttp/fixtures/multipart-file.kt +++ b/src/targets/kotlin/okhttp/fixtures/multipart-file.kt @@ -1,7 +1,7 @@ val client = OkHttpClient() val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001") -val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n") +val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--") val request = Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/kotlin/okhttp/fixtures/multipart-form-data.kt b/src/targets/kotlin/okhttp/fixtures/multipart-form-data.kt index 18ca7d876..7967ff2c1 100644 --- a/src/targets/kotlin/okhttp/fixtures/multipart-form-data.kt +++ b/src/targets/kotlin/okhttp/fixtures/multipart-form-data.kt @@ -1,7 +1,7 @@ val client = OkHttpClient() val mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001") -val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n") +val body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--") val request = Request.Builder() .url("https://httpbin.org/anything") .post(body) diff --git a/src/targets/node/axios/fixtures/multipart-data.cjs b/src/targets/node/axios/fixtures/multipart-data.cjs index db96005c8..f2268d0e5 100644 --- a/src/targets/node/axios/fixtures/multipart-data.cjs +++ b/src/targets/node/axios/fixtures/multipart-data.cjs @@ -4,7 +4,7 @@ const options = { method: 'POST', url: 'https://httpbin.org/anything', headers: {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'}, - data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n' + data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--' }; axios diff --git a/src/targets/node/axios/fixtures/multipart-file.cjs b/src/targets/node/axios/fixtures/multipart-file.cjs index a221877dd..48e0d0162 100644 --- a/src/targets/node/axios/fixtures/multipart-file.cjs +++ b/src/targets/node/axios/fixtures/multipart-file.cjs @@ -4,7 +4,7 @@ const options = { method: 'POST', url: 'https://httpbin.org/anything', headers: {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'}, - data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n' + data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--' }; axios diff --git a/src/targets/node/axios/fixtures/multipart-form-data.cjs b/src/targets/node/axios/fixtures/multipart-form-data.cjs index b3c1e646a..15a56e506 100644 --- a/src/targets/node/axios/fixtures/multipart-form-data.cjs +++ b/src/targets/node/axios/fixtures/multipart-form-data.cjs @@ -4,7 +4,7 @@ const options = { method: 'POST', url: 'https://httpbin.org/anything', headers: {'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001'}, - data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n' + data: '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--' }; axios diff --git a/src/targets/node/native/fixtures/multipart-data.cjs b/src/targets/node/native/fixtures/multipart-data.cjs index 4ec070a50..9470e8ae1 100644 --- a/src/targets/node/native/fixtures/multipart-data.cjs +++ b/src/targets/node/native/fixtures/multipart-data.cjs @@ -23,5 +23,5 @@ const req = http.request(options, function (res) { }); }); -req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n'); +req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--'); req.end(); \ No newline at end of file diff --git a/src/targets/node/native/fixtures/multipart-file.cjs b/src/targets/node/native/fixtures/multipart-file.cjs index df30687ad..aefa51da4 100644 --- a/src/targets/node/native/fixtures/multipart-file.cjs +++ b/src/targets/node/native/fixtures/multipart-file.cjs @@ -23,5 +23,5 @@ const req = http.request(options, function (res) { }); }); -req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n'); +req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--'); req.end(); \ No newline at end of file diff --git a/src/targets/node/native/fixtures/multipart-form-data.cjs b/src/targets/node/native/fixtures/multipart-form-data.cjs index e226a9f19..e914bad77 100644 --- a/src/targets/node/native/fixtures/multipart-form-data.cjs +++ b/src/targets/node/native/fixtures/multipart-form-data.cjs @@ -23,5 +23,5 @@ const req = http.request(options, function (res) { }); }); -req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n'); +req.write('-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--'); req.end(); \ No newline at end of file diff --git a/src/targets/ocaml/cohttp/fixtures/multipart-data.ml b/src/targets/ocaml/cohttp/fixtures/multipart-data.ml index 1b7a50744..1c7d1cb0d 100644 --- a/src/targets/ocaml/cohttp/fixtures/multipart-data.ml +++ b/src/targets/ocaml/cohttp/fixtures/multipart-data.ml @@ -4,7 +4,7 @@ open Lwt let uri = Uri.of_string "https://httpbin.org/anything" in let headers = Header.add (Header.init ()) "content-type" "multipart/form-data; boundary=---011000010111000001101001" in -let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n" in +let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--" in Client.call ~headers ~body `POST uri >>= fun (res, body_stream) -> diff --git a/src/targets/ocaml/cohttp/fixtures/multipart-file.ml b/src/targets/ocaml/cohttp/fixtures/multipart-file.ml index 9f2c6e8a8..ab98f5170 100644 --- a/src/targets/ocaml/cohttp/fixtures/multipart-file.ml +++ b/src/targets/ocaml/cohttp/fixtures/multipart-file.ml @@ -4,7 +4,7 @@ open Lwt let uri = Uri.of_string "https://httpbin.org/anything" in let headers = Header.add (Header.init ()) "content-type" "multipart/form-data; boundary=---011000010111000001101001" in -let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n" in +let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" in Client.call ~headers ~body `POST uri >>= fun (res, body_stream) -> diff --git a/src/targets/ocaml/cohttp/fixtures/multipart-form-data.ml b/src/targets/ocaml/cohttp/fixtures/multipart-form-data.ml index 55f9decdc..2551bc14e 100644 --- a/src/targets/ocaml/cohttp/fixtures/multipart-form-data.ml +++ b/src/targets/ocaml/cohttp/fixtures/multipart-form-data.ml @@ -4,7 +4,7 @@ open Lwt let uri = Uri.of_string "https://httpbin.org/anything" in let headers = Header.add (Header.init ()) "Content-Type" "multipart/form-data; boundary=---011000010111000001101001" in -let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n" in +let body = Cohttp_lwt_body.of_string "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" in Client.call ~headers ~body `POST uri >>= fun (res, body_stream) -> diff --git a/src/targets/php/curl/fixtures/multipart-data.php b/src/targets/php/curl/fixtures/multipart-data.php index 3cbe0e979..c2130d267 100644 --- a/src/targets/php/curl/fixtures/multipart-data.php +++ b/src/targets/php/curl/fixtures/multipart-data.php @@ -10,7 +10,7 @@ CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n", + CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--", CURLOPT_HTTPHEADER => [ "content-type: multipart/form-data; boundary=---011000010111000001101001" ], diff --git a/src/targets/php/curl/fixtures/multipart-file.php b/src/targets/php/curl/fixtures/multipart-file.php index 148c55c42..c76bd53e2 100644 --- a/src/targets/php/curl/fixtures/multipart-file.php +++ b/src/targets/php/curl/fixtures/multipart-file.php @@ -10,7 +10,7 @@ CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n", + CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--", CURLOPT_HTTPHEADER => [ "content-type: multipart/form-data; boundary=---011000010111000001101001" ], diff --git a/src/targets/php/curl/fixtures/multipart-form-data.php b/src/targets/php/curl/fixtures/multipart-form-data.php index b03eb9262..ff8725e28 100644 --- a/src/targets/php/curl/fixtures/multipart-form-data.php +++ b/src/targets/php/curl/fixtures/multipart-form-data.php @@ -10,7 +10,7 @@ CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", - CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n", + CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--", CURLOPT_HTTPHEADER => [ "Content-Type: multipart/form-data; boundary=---011000010111000001101001" ], diff --git a/src/targets/php/http1/fixtures/multipart-data.php b/src/targets/php/http1/fixtures/multipart-data.php index 104ec2cf4..3636106a7 100644 --- a/src/targets/php/http1/fixtures/multipart-data.php +++ b/src/targets/php/http1/fixtures/multipart-data.php @@ -9,7 +9,7 @@ ]); $request->setBody('-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain Hello World @@ -17,8 +17,7 @@ Content-Disposition: form-data; name="bar" Bonjour le monde ------011000010111000001101001-- -'); +-----011000010111000001101001--'); try { $response = $request->send(); diff --git a/src/targets/php/http1/fixtures/multipart-file.php b/src/targets/php/http1/fixtures/multipart-file.php index a180ee608..c4e5f5f56 100644 --- a/src/targets/php/http1/fixtures/multipart-file.php +++ b/src/targets/php/http1/fixtures/multipart-file.php @@ -9,12 +9,11 @@ ]); $request->setBody('-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain ------011000010111000001101001-- -'); +-----011000010111000001101001--'); try { $response = $request->send(); diff --git a/src/targets/php/http1/fixtures/multipart-form-data.php b/src/targets/php/http1/fixtures/multipart-form-data.php index 38c63768c..7d94018f1 100644 --- a/src/targets/php/http1/fixtures/multipart-form-data.php +++ b/src/targets/php/http1/fixtures/multipart-form-data.php @@ -12,8 +12,7 @@ Content-Disposition: form-data; name="foo" bar ------011000010111000001101001-- -'); +-----011000010111000001101001--'); try { $response = $request->send(); diff --git a/src/targets/powershell/restmethod/fixtures/multipart-data.ps1 b/src/targets/powershell/restmethod/fixtures/multipart-data.ps1 index 5bec31959..4073bd282 100644 --- a/src/targets/powershell/restmethod/fixtures/multipart-data.ps1 +++ b/src/targets/powershell/restmethod/fixtures/multipart-data.ps1 @@ -1,7 +1,7 @@ $headers=@{} $headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") $response = Invoke-RestMethod -Uri 'https://httpbin.org/anything' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain Hello World @@ -9,5 +9,4 @@ Hello World Content-Disposition: form-data; name="bar" Bonjour le monde ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/powershell/restmethod/fixtures/multipart-file.ps1 b/src/targets/powershell/restmethod/fixtures/multipart-file.ps1 index 058a4879f..8fc069e4f 100644 --- a/src/targets/powershell/restmethod/fixtures/multipart-file.ps1 +++ b/src/targets/powershell/restmethod/fixtures/multipart-file.ps1 @@ -1,9 +1,8 @@ $headers=@{} $headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") $response = Invoke-RestMethod -Uri 'https://httpbin.org/anything' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/powershell/restmethod/fixtures/multipart-form-data.ps1 b/src/targets/powershell/restmethod/fixtures/multipart-form-data.ps1 index 5c6fba948..f75249092 100644 --- a/src/targets/powershell/restmethod/fixtures/multipart-form-data.ps1 +++ b/src/targets/powershell/restmethod/fixtures/multipart-form-data.ps1 @@ -4,5 +4,4 @@ $response = Invoke-RestMethod -Uri 'https://httpbin.org/anything' -Method POST - Content-Disposition: form-data; name="foo" bar ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/powershell/webrequest/fixtures/multipart-data.ps1 b/src/targets/powershell/webrequest/fixtures/multipart-data.ps1 index 79fd357b2..29281a0f7 100644 --- a/src/targets/powershell/webrequest/fixtures/multipart-data.ps1 +++ b/src/targets/powershell/webrequest/fixtures/multipart-data.ps1 @@ -1,7 +1,7 @@ $headers=@{} $headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") $response = Invoke-WebRequest -Uri 'https://httpbin.org/anything' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain Hello World @@ -9,5 +9,4 @@ Hello World Content-Disposition: form-data; name="bar" Bonjour le monde ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/powershell/webrequest/fixtures/multipart-file.ps1 b/src/targets/powershell/webrequest/fixtures/multipart-file.ps1 index fc703f7c4..120321a6a 100644 --- a/src/targets/powershell/webrequest/fixtures/multipart-file.ps1 +++ b/src/targets/powershell/webrequest/fixtures/multipart-file.ps1 @@ -1,9 +1,8 @@ $headers=@{} $headers.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") $response = Invoke-WebRequest -Uri 'https://httpbin.org/anything' -Method POST -Headers $headers -ContentType 'multipart/form-data; boundary=---011000010111000001101001' -Body '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/powershell/webrequest/fixtures/multipart-form-data.ps1 b/src/targets/powershell/webrequest/fixtures/multipart-form-data.ps1 index ffd9f721f..8c7f3c140 100644 --- a/src/targets/powershell/webrequest/fixtures/multipart-form-data.ps1 +++ b/src/targets/powershell/webrequest/fixtures/multipart-form-data.ps1 @@ -4,5 +4,4 @@ $response = Invoke-WebRequest -Uri 'https://httpbin.org/anything' -Method POST - Content-Disposition: form-data; name="foo" bar ------011000010111000001101001-- -' \ No newline at end of file +-----011000010111000001101001--' \ No newline at end of file diff --git a/src/targets/python/requests/fixtures/multipart-form-data.py b/src/targets/python/requests/fixtures/multipart-form-data.py index 7230e88db..4adceef96 100644 --- a/src/targets/python/requests/fixtures/multipart-form-data.py +++ b/src/targets/python/requests/fixtures/multipart-form-data.py @@ -2,7 +2,7 @@ url = "https://httpbin.org/anything" -payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n" +payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" headers = {"Content-Type": "multipart/form-data; boundary=---011000010111000001101001"} response = requests.post(url, data=payload, headers=headers) diff --git a/src/targets/r/httr/fixtures/multipart-data.r b/src/targets/r/httr/fixtures/multipart-data.r index c2310c985..bdc35201e 100644 --- a/src/targets/r/httr/fixtures/multipart-data.r +++ b/src/targets/r/httr/fixtures/multipart-data.r @@ -2,7 +2,7 @@ library(httr) url <- "https://httpbin.org/anything" -payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n" +payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--" encode <- "multipart" diff --git a/src/targets/r/httr/fixtures/multipart-file.r b/src/targets/r/httr/fixtures/multipart-file.r index cb08267a0..8c0f62662 100644 --- a/src/targets/r/httr/fixtures/multipart-file.r +++ b/src/targets/r/httr/fixtures/multipart-file.r @@ -2,7 +2,7 @@ library(httr) url <- "https://httpbin.org/anything" -payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n" +payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" encode <- "multipart" diff --git a/src/targets/r/httr/fixtures/multipart-form-data.r b/src/targets/r/httr/fixtures/multipart-form-data.r index c10910273..05f080f20 100644 --- a/src/targets/r/httr/fixtures/multipart-form-data.r +++ b/src/targets/r/httr/fixtures/multipart-form-data.r @@ -2,7 +2,7 @@ library(httr) url <- "https://httpbin.org/anything" -payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n" +payload <- "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" encode <- "multipart" diff --git a/src/targets/ruby/native/fixtures/multipart-data.rb b/src/targets/ruby/native/fixtures/multipart-data.rb index 1768f9cad..1af607d20 100644 --- a/src/targets/ruby/native/fixtures/multipart-data.rb +++ b/src/targets/ruby/native/fixtures/multipart-data.rb @@ -8,7 +8,7 @@ request = Net::HTTP::Post.new(url) request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' -request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n" +request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"bar\"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--" response = http.request(request) puts response.read_body \ No newline at end of file diff --git a/src/targets/ruby/native/fixtures/multipart-file.rb b/src/targets/ruby/native/fixtures/multipart-file.rb index 092a62595..1ba5250a9 100644 --- a/src/targets/ruby/native/fixtures/multipart-file.rb +++ b/src/targets/ruby/native/fixtures/multipart-file.rb @@ -8,7 +8,7 @@ request = Net::HTTP::Post.new(url) request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' -request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n" +request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"; filename=\"src/fixtures/files/hello.txt\"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--" response = http.request(request) puts response.read_body \ No newline at end of file diff --git a/src/targets/ruby/native/fixtures/multipart-form-data.rb b/src/targets/ruby/native/fixtures/multipart-form-data.rb index 34c215dc8..1ce7cd7ce 100644 --- a/src/targets/ruby/native/fixtures/multipart-form-data.rb +++ b/src/targets/ruby/native/fixtures/multipart-form-data.rb @@ -8,7 +8,7 @@ request = Net::HTTP::Post.new(url) request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001' -request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n" +request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"foo\"\r\n\r\nbar\r\n-----011000010111000001101001--" response = http.request(request) puts response.read_body \ No newline at end of file diff --git a/src/targets/shell/httpie/fixtures/multipart-data.sh b/src/targets/shell/httpie/fixtures/multipart-data.sh index 3b30b706f..65e8761bb 100644 --- a/src/targets/shell/httpie/fixtures/multipart-data.sh +++ b/src/targets/shell/httpie/fixtures/multipart-data.sh @@ -1,5 +1,5 @@ echo '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain Hello World @@ -7,7 +7,6 @@ Hello World Content-Disposition: form-data; name="bar" Bonjour le monde ------011000010111000001101001-- -' | \ +-----011000010111000001101001--' | \ http POST https://httpbin.org/anything \ content-type:'multipart/form-data; boundary=---011000010111000001101001' \ No newline at end of file diff --git a/src/targets/shell/httpie/fixtures/multipart-file.sh b/src/targets/shell/httpie/fixtures/multipart-file.sh index 95a532e8e..9d8af4a2b 100644 --- a/src/targets/shell/httpie/fixtures/multipart-file.sh +++ b/src/targets/shell/httpie/fixtures/multipart-file.sh @@ -1,9 +1,8 @@ echo '-----011000010111000001101001 -Content-Disposition: form-data; name="foo"; filename="hello.txt" +Content-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt" Content-Type: text/plain ------011000010111000001101001-- -' | \ +-----011000010111000001101001--' | \ http POST https://httpbin.org/anything \ content-type:'multipart/form-data; boundary=---011000010111000001101001' \ No newline at end of file diff --git a/src/targets/shell/httpie/fixtures/multipart-form-data.sh b/src/targets/shell/httpie/fixtures/multipart-form-data.sh index 4d3f90534..d58677e62 100644 --- a/src/targets/shell/httpie/fixtures/multipart-form-data.sh +++ b/src/targets/shell/httpie/fixtures/multipart-form-data.sh @@ -2,7 +2,6 @@ echo '-----011000010111000001101001 Content-Disposition: form-data; name="foo" bar ------011000010111000001101001-- -' | \ +-----011000010111000001101001--' | \ http POST https://httpbin.org/anything \ Content-Type:'multipart/form-data; boundary=---011000010111000001101001' \ No newline at end of file diff --git a/src/targets/shell/wget/fixtures/multipart-data.sh b/src/targets/shell/wget/fixtures/multipart-data.sh index 5840c954a..a92b72793 100644 --- a/src/targets/shell/wget/fixtures/multipart-data.sh +++ b/src/targets/shell/wget/fixtures/multipart-data.sh @@ -1,6 +1,6 @@ wget --quiet \ --method POST \ --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ - --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--\r\n' \ + --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\nHello World\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name="bar"\r\n\r\nBonjour le monde\r\n-----011000010111000001101001--' \ --output-document \ - https://httpbin.org/anything \ No newline at end of file diff --git a/src/targets/shell/wget/fixtures/multipart-file.sh b/src/targets/shell/wget/fixtures/multipart-file.sh index e172b94ce..dbc0765db 100644 --- a/src/targets/shell/wget/fixtures/multipart-file.sh +++ b/src/targets/shell/wget/fixtures/multipart-file.sh @@ -1,6 +1,6 @@ wget --quiet \ --method POST \ --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ - --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--\r\n' \ + --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"; filename="src/fixtures/files/hello.txt"\r\nContent-Type: text/plain\r\n\r\n\r\n-----011000010111000001101001--' \ --output-document \ - https://httpbin.org/anything \ No newline at end of file diff --git a/src/targets/shell/wget/fixtures/multipart-form-data.sh b/src/targets/shell/wget/fixtures/multipart-form-data.sh index 6859dad17..317e04fde 100644 --- a/src/targets/shell/wget/fixtures/multipart-form-data.sh +++ b/src/targets/shell/wget/fixtures/multipart-form-data.sh @@ -1,6 +1,6 @@ wget --quiet \ --method POST \ --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \ - --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--\r\n' \ + --body-data '-----011000010111000001101001\r\nContent-Disposition: form-data; name="foo"\r\n\r\nbar\r\n-----011000010111000001101001--' \ --output-document \ - https://httpbin.org/anything \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index add5b1c1c..a781fea7c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,9 +8,6 @@ "module": "ESNext", "moduleResolution": "bundler", "outDir": "dist", - "paths": { - "map-stream": ["./.sink.d.ts"], - }, "resolveJsonModule": true, "target": "ES2020",