mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-12 13:00:19 +00:00
fix: Enable the use of the parse() method for superagent
This commit is contained in:
@@ -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();
|
||||
|
||||
Vendored
+2
-1
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user