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

Improve option normalization #1521

Closed
wants to merge 40 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
023263c
Separate options
szmarczak Nov 7, 2020
6731636
those should be private
szmarczak Nov 7, 2020
efdde86
Accept an argument
szmarczak Nov 7, 2020
b416ea1
small fix
szmarczak Nov 7, 2020
9cc6f20
call init hooks
szmarczak Nov 8, 2020
fceb122
falsy -> undefined
szmarczak Nov 8, 2020
81457e7
call decodeURI
szmarczak Nov 8, 2020
191e6c7
validate https options
szmarczak Nov 8, 2020
101c9ac
method to upper case
szmarczak Nov 8, 2020
ec5f72d
lowercase headers
szmarczak Nov 8, 2020
31421b0
throw on passing auth
szmarczak Nov 8, 2020
5064336
fix prefixurl
szmarczak Nov 8, 2020
653d8fa
url must not start with a slash
szmarczak Nov 8, 2020
1291834
fix prefixurl
szmarczak Nov 8, 2020
e95fb13
search parameters fix
szmarczak Nov 8, 2020
e6db203
throw on unsupported protocol
szmarczak Nov 8, 2020
a8f8e22
small fix
szmarczak Nov 8, 2020
8607ce0
follow-up commit
szmarczak Nov 8, 2020
982acf7
follow-up commit
szmarczak Nov 8, 2020
331893b
check agent properties
szmarczak Nov 8, 2020
c73b52d
accept url as an argument
szmarczak Nov 8, 2020
447577a
fixes
szmarczak Nov 8, 2020
114b021
fixes
szmarczak Nov 8, 2020
b440723
fixes
szmarczak Nov 8, 2020
64fbd5f
normalize promise api options
szmarczak Nov 8, 2020
6c0b274
fixes
szmarczak Nov 8, 2020
852a783
fixes
szmarczak Nov 8, 2020
a0d080c
fixes
szmarczak Nov 8, 2020
2db2a2d
fixes
szmarczak Nov 8, 2020
b49db9d
clean up
szmarczak Nov 8, 2020
c361111
typo
szmarczak Nov 8, 2020
44343f0
fixes
szmarczak Nov 8, 2020
d1369d3
small fix
szmarczak Nov 9, 2020
5e50af2
small fix
szmarczak Nov 11, 2020
2aafcb8
OptionsInit type
szmarczak Nov 13, 2020
9ae0351
a lot of fixes
szmarczak Nov 14, 2020
5699487
remove unused import
szmarczak Nov 14, 2020
ca7256e
streams finally can be builded
szmarczak Nov 14, 2020
8798afc
first demo!
szmarczak Nov 14, 2020
fb2bc78
fast fix
szmarczak Nov 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions benchmark/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fetch from 'node-fetch';
import request = require('request');
import got from '../source';
import Request, {kIsNormalizedAlready} from '../source/core';
import {Options} from '../source/core/options';

const {normalizeArguments} = Request;

Expand All @@ -23,7 +24,7 @@ const gotOptions = {
agent: {
https: httpsAgent
},
https: {
httpsOptions: {
rejectUnauthorized: false
},
retry: 0
Expand Down Expand Up @@ -162,7 +163,14 @@ suite.add('got - promise', {
console.log(`Fastest is ${this.filter('fastest').map('name') as string}`);

internalBenchmark();
}).run();
});

try {
new Options(url, gotOptions)
} catch (error) {
console.log(error);
process.exit();
}

const internalBenchmark = (): void => {
console.log();
Expand All @@ -172,13 +180,19 @@ const internalBenchmark = (): void => {
fn: () => {
normalizeArguments(url, gotOptions);
}
}).add('got - new options', {
fn: () => {
new Options(url, gotOptions)
}
}).on('cycle', (event: Benchmark.Event) => {
console.log(String(event.target));
});

internalSuite.run();
};

internalBenchmark();

// Results (i7-7700k, CPU governor: performance):
// got - promise x 3,003 ops/sec ±6.26% (70 runs sampled)
// got - stream x 3,538 ops/sec ±5.86% (67 runs sampled)
Expand Down
8 changes: 8 additions & 0 deletions demo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const Request = require('./dist/index').default;

const stream = new Request('https://httpbin.org/anything');

console.log(JSON.parse(JSON.stringify(stream.options)));

stream.setEncoding('utf8');
stream.on('data', console.log);
2 changes: 1 addition & 1 deletion source/as-promise/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export namespace PromiseOnly {
});
```
*/
afterResponse?: AfterResponseHook[];
afterResponse: AfterResponseHook[];
}

export interface Options extends PaginationOptions<unknown, unknown> {
Expand Down
Loading