Merge pull request #26383 from dannycochran/patch-10

plugin function expects SuperAgentRequest
This commit is contained in:
Nathan Shively-Sanders
2018-06-18 15:04:17 -07:00
committed by GitHub
2 changed files with 16 additions and 1 deletions

View File

@@ -150,7 +150,7 @@ declare namespace request {
write(data: string | Buffer, encoding?: string): this;
}
type Plugin = (req: Request) => void;
type Plugin = (req: SuperAgentRequest) => void;
interface ProgressEvent {
direction: 'download' | 'upload';

View File

@@ -390,3 +390,18 @@ request
.then(response => {
// reads 404 page as a successful response
});
// Test that the "Plugin" type from "use" provides a SuperAgentRequest rather than a Request,
// which has additional properties.
const echoPlugin = (request: request.SuperAgentRequest) => {
req.url = '' + req.url;
req.cookies = '' + req.cookies;
if (req.method) {
req.url = '/echo';
}
};
request
.get('/echo')
.use(echoPlugin)
.end();