Skip to content
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

Major refactoring #921

Merged
merged 35 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c29d4d3
init
szmarczak Nov 5, 2019
fcc18f8
Big big changes
szmarczak Nov 6, 2019
b803076
fixes
szmarczak Nov 7, 2019
3ceba12
Merge with master
szmarczak Nov 7, 2019
29fee34
remove unnecessary semicolon
szmarczak Nov 7, 2019
d5a2ff2
enhancements
szmarczak Nov 7, 2019
5236d84
rename stream to isStream
szmarczak Nov 7, 2019
c7dbe1e
throw on legacy url input
szmarczak Nov 7, 2019
f1f203a
enhancements
szmarczak Nov 10, 2019
461e8d9
bug fixes
szmarczak Nov 10, 2019
b044037
fixes
szmarczak Nov 10, 2019
22c36bf
fix option merge
szmarczak Nov 11, 2019
aedac8c
more bug fixes
szmarczak Nov 11, 2019
d7c7d53
fixes
szmarczak Nov 11, 2019
507a3cc
make tests pass
szmarczak Nov 11, 2019
9255df7
remove todo
szmarczak Nov 11, 2019
778cf67
Remove got.create() & update docs
szmarczak Nov 12, 2019
e8ff08b
update docs
szmarczak Nov 12, 2019
0841642
another fix
szmarczak Nov 12, 2019
fe76e8c
nitpick
szmarczak Nov 12, 2019
3def303
types
szmarczak Nov 12, 2019
695ebaf
generic cookiejar object
szmarczak Nov 12, 2019
52496df
make tests pass
szmarczak Nov 12, 2019
c6b22e1
Refactor the got() function, aka: fix bugs
szmarczak Nov 14, 2019
ef32a0e
Throw on null value headers
szmarczak Nov 14, 2019
dde0b76
bug fixes
szmarczak Nov 14, 2019
a0850bd
Improve is usage
szmarczak Nov 14, 2019
0d9baf1
remove useless line
szmarczak Nov 14, 2019
42b2605
comments
szmarczak Nov 14, 2019
3b313a7
call beforeRetry hook when retrying in afterResponse hook
szmarczak Nov 14, 2019
518c00d
nitpicks
szmarczak Nov 15, 2019
7f2f477
nitpicks
szmarczak Nov 15, 2019
5bc7319
nitpicks
szmarczak Nov 15, 2019
3ff5ebb
no unnecessary escape
szmarczak Nov 15, 2019
a7e73f2
Update readme.md
sindresorhus Nov 16, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ Default: `{}`

Request headers.

Existing headers will be overwritten. Headers set to `null` will be omitted.
Existing headers will be overwritten. Headers set to `undefined` will be omitted.

###### isStream

Expand Down Expand Up @@ -1311,7 +1311,7 @@ const got = require('got');

### User Agent

It's a good idea to set the `'user-agent'` header so the provider can more easily see how their resource is used. By default, it's the URL to this repo. You can omit this header by setting it to `undefined` (or `null`).
It's a good idea to set the `'user-agent'` header so the provider can more easily see how their resource is used. By default, it's the URL to this repo. You can omit this header by setting it to `undefined`.

```js
const got = require('got');
Expand Down
7 changes: 6 additions & 1 deletion source/normalize-arguments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,10 @@ export const normalizeArguments = (url: URLOrOptions, options?: Options, default

// Make it possible to remove default headers
for (const [key, value] of Object.entries(options.headers)) {
if (is.nullOrUndefined(value)) {
if (is.undefined(value)) {
delete options.headers[key];
} else if (is.null_(value)) {
throw new TypeError('Use `undefined` instead of `null` to delete HTTP headers');
}
}

Expand Down Expand Up @@ -405,5 +407,8 @@ export const normalizeRequestArguments = async (options: NormalizedOptions): Pro

delete options.timeout;

// `http-cache-semantics` check this
szmarczak marked this conversation as resolved.
Show resolved Hide resolved
delete options.url;

return options as unknown as NormalizedRequestArguments;
};
3 changes: 1 addition & 2 deletions source/request-as-event-emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ export default (options: NormalizedOptions) => {
// `cacheable-request` doesn't support Node 10 API, fallback.
szmarczak marked this conversation as resolved.
Show resolved Hide resolved
httpOptions = {
...httpOptions,
...urlToOptions(options.url),
url: undefined // `http-cache-semantics` check this
...urlToOptions(options.url)
};

const cacheRequest = options.cacheableRequest(httpOptions, handleResponse);
Expand Down
10 changes: 3 additions & 7 deletions test/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,12 @@ test('buffer as `options.body` sets `content-length` header', withServer, async
t.is(Number(headers['content-length']), buffer.length);
});

test('removes null value headers', withServer, async (t, server, got) => {
server.get('/', echoHeaders);

const {body} = await got({
test('throws on null value headers', async t => {
await t.throwsAsync(got({
headers: {
'user-agent': null
}
});
const headers = JSON.parse(body);
t.false(Reflect.has(headers, 'user-agent'));
}), TypeError, 'Use `undefined` instead of `null` to delete HTTP headers');
});

test('removes undefined value headers', withServer, async (t, server, got) => {
Expand Down