Added https methods for superagent's Request

This commit is contained in:
Pap Lőrinc
2017-06-30 14:26:38 +03:00
parent 5d810e4179
commit 49002c7cee
2 changed files with 21 additions and 0 deletions
+4
View File
@@ -98,15 +98,19 @@ declare namespace request {
attach(field: string, file: Blob | Buffer | fs.ReadStream | string, filename?: string): this;
auth(user: string, name: string): this;
buffer(val?: boolean): this;
ca(cert: Buffer): this;
cert(cert: Buffer | string): this;
clearTimeout(): this;
end(callback?: CallbackHandler): this;
field(name: string, val: string): this;
get(field: string): string;
key(cert: Buffer | string): this;
on(name: 'error', handler: (err: any) => void): this;
on(name: 'progress', handler: (event: ProgressEvent) => void): this;
on(name: string, handler: (event: any) => void): this;
parse(fn: (res: Response, callback: (err: Error | null, body: any) => void) => void): this;
part(): this;
pfx(cert: Buffer | string): this;
pipe(stream: NodeJS.WritableStream, options?: object): stream.Writable;
query(val: object | string): this;
redirects(n: number): this;
+17
View File
@@ -345,3 +345,20 @@ request
assert(res.xhr instanceof XMLHttpRequest);
assert(res.xhr.response instanceof Blob);
});
// HTTPS request, from: https://github.com/visionmedia/superagent/commit/6158efbf42cb93d77c1a70887284be783dd7dabe
const ca = fs.readFileSync('ca.cert.pem');
const key = fs.readFileSync('key.pem');
const cert = fs.readFileSync('cert.pem');
request
.post('/secure')
.ca(ca)
.key(key)
.cert(cert)
.end(callback);
const pfx = fs.readFileSync('cert.pfx');
request
.post('/secure')
.pfx(pfx)
.end(callback);