From 49002c7cee2c0c9aada4968c8c0219ecf2814b8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pap=20L=C5=91rinc?= Date: Fri, 30 Jun 2017 13:06:26 +0300 Subject: [PATCH] Added https methods for superagent's Request --- types/superagent/index.d.ts | 4 ++++ types/superagent/superagent-tests.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/types/superagent/index.d.ts b/types/superagent/index.d.ts index a386894bfb..aa8d737f60 100644 --- a/types/superagent/index.d.ts +++ b/types/superagent/index.d.ts @@ -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; diff --git a/types/superagent/superagent-tests.ts b/types/superagent/superagent-tests.ts index ea4cbc503e..e6fb27c078 100644 --- a/types/superagent/superagent-tests.ts +++ b/types/superagent/superagent-tests.ts @@ -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);