Skip to content

Commit

Permalink
Update HTTPS config options for superagent (DefinitelyTyped#36627)
Browse files Browse the repository at this point in the history
* add tls configuration types

superagent passes the ca, cert, and key parameters to `tls.createSecureContext`: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options

* add `response` event to superagent types
  • Loading branch information
imhoffd authored and armanio123 committed Jul 8, 2019
1 parent fa70abd commit 60e431d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
9 changes: 5 additions & 4 deletions types/superagent/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,22 @@ declare namespace request {
auth(user: string, pass: string, options?: { type: 'basic' | 'auto' }): this;
auth(token: string, options: { type: 'bearer' }): this;
buffer(val?: boolean): this;
ca(cert: Buffer): this;
cert(cert: Buffer | string): this;
ca(cert: string | string[] | Buffer | Buffer[]): this;
cert(cert: string | string[] | Buffer | Buffer[]): this;
clearTimeout(): this;
end(callback?: CallbackHandler): void;
field(name: string, val: MultipartValue): this;
field(fields: { [fieldName: string]: MultipartValue }): this;
get(field: string): string;
key(cert: Buffer | string): this;
key(cert: string | string[] | Buffer | Buffer[]): this;
ok(callback: (res: Response) => boolean): this;
on(name: 'error', handler: (err: any) => void): this;
on(name: 'progress', handler: (event: ProgressEvent) => void): this;
on(name: 'response', handler: (response: Response) => void): this;
on(name: string, handler: (event: any) => void): this;
parse(parser: Parser): this;
part(): this;
pfx(cert: Buffer | string | { pfx: Buffer, passphrase: string }): this;
pfx(cert: string | string[] | Buffer | Buffer[] | { pfx: string | Buffer, passphrase: string }): this;
pipe(stream: NodeJS.WritableStream, options?: object): stream.Writable;
query(val: object | string): this;
redirects(n: number): this;
Expand Down
47 changes: 47 additions & 0 deletions types/superagent/superagent-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,53 @@ request
})
.end(callback);

// HTTPS request with string, Buffer, and arrays of strings and Buffers, from: https://nodejs.org/api/tls.html#tls_tls_createsecurecontext_options
request
.post('/secure')
.ca('ca')
.key('key')
.cert('cert')
.end(callback);

request
.post('/secure')
.ca(['ca'])
.key(['key'])
.cert(['cert'])
.end(callback);

request
.post('/secure')
.ca([ca])
.key([key])
.cert([cert])
.end(callback);

request
.post('/secure')
.pfx('cert.pfx')
.end(callback);

request
.post('/secure')
.pfx(['cert.pfx'])
.end(callback);

request
.post('/secure')
.pfx([pfx])
.end(callback);

// 'response' event, adapted from: https://visionmedia.github.io/superagent/docs/test.html
request
.get('/user/1')
.on('response', res => {
try {
assert.equal('bar', res.body.foo);
} catch (e) { /* ignore */ }
})
.end();

// ok, from: https://github.com/visionmedia/superagent/commit/34533bbc29833889090847c45a82b0ea81b2f06d
request
.get('/404')
Expand Down

0 comments on commit 60e431d

Please sign in to comment.