Skip to content

Commit

Permalink
feat: dropping support for non-native FormData implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
erunion committed Sep 14, 2023
1 parent a080016 commit f99294b
Show file tree
Hide file tree
Showing 69 changed files with 194 additions and 324 deletions.
4 changes: 3 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

"unicorn/prefer-node-protocol": "error",

"vitest/require-hook": "off"
"vitest/require-hook": ["error", {
"allowedFunctionCalls": ["runCustomFixtures"]
}]
},
"overrides": [
{
Expand Down
1 change: 0 additions & 1 deletion .sink.d.ts

This file was deleted.

41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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
95 changes: 37 additions & 58 deletions package-lock.json

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

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
},
Expand Down
10 changes: 4 additions & 6 deletions src/fixtures/runCustomFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
});
};
76 changes: 0 additions & 76 deletions src/helpers/form-data.ts

This file was deleted.

Loading

0 comments on commit f99294b

Please sign in to comment.