fix: Enable the use of the parse() method for superagent

This commit is contained in:
Benjamin Pannell
2016-08-02 13:36:59 +02:00
parent 3af0c338b9
commit fe2f0deec1
2 changed files with 20 additions and 1 deletions
+18
View File
@@ -193,6 +193,24 @@ request('/search')
var charset: string = res.charset;
});
// Custom parsers
request
.post('/search')
.parse((res, callback) => {
res.setEncoding("binary");
let data = "";
res.on("data", (chunk: string) => {
data += chunk;
});
res.on("end", () => {
callback(null, new Buffer(data, "base64"));
});
})
.end((res: request.Response) => {
res.body.toString("hex");
});
var req = request.get('/hoge');
// Aborting requests
req.abort();
+2 -1
View File
@@ -50,7 +50,7 @@ declare module "superagent" {
search(url: string, callback?: CallbackHandler): Req;
connect(url: string, callback?: CallbackHandler): Req;
parse(fn: Function): Req;
parse(fn: (res: Response, callback: (err: Error, body: any) => void) => void): this;
saveCookies(res: Response): void;
attachCookies(req: Req): void;
}
@@ -107,6 +107,7 @@ declare module "superagent" {
withCredentials(): this;
write(data: string, encoding?: string): this;
write(data: Buffer, encoding?: string): this;
parse(fn: (res: Response, callback: (err: Error, body: any) => void) => void): this;
}
}