本文整理汇总了TypeScript中express.Request.pipe方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Request.pipe方法的具体用法?TypeScript Request.pipe怎么用?TypeScript Request.pipe使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类express.Request
的用法示例。
在下文中一共展示了Request.pipe方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: return
return (req: Request, res: Response, next: () => void): any => {
logger.info(`[hosting] Rewriting ${req.url} to ${url} for ${rewriteIdentifier}`);
// Extract the __session cookie from headers to forward it to the
// functions cookie is not a string[].
const cookie = (req.headers.cookie as string) || "";
const sessionCookie = cookie.split(/; ?/).find((c: string) => {
return c.trim().indexOf("__session=") === 0;
});
const proxied = request({
method: req.method,
qs: req.query,
url: url + req.url,
headers: {
"X-Forwarded-Host": req.headers.host,
"X-Original-Url": req.url,
Pragma: "no-cache",
"Cache-Control": "no-cache, no-store",
// forward the parsed __session cookie if any
Cookie: sessionCookie,
},
followRedirect: false,
timeout: 60000,
});
req.pipe(proxied);
// err here is `any` in order to check `.code`
proxied.on("error", (err: any) => {
if (err.code === "ETIMEDOUT" || err.code === "ESOCKETTIMEDOUT") {
res.statusCode = 504;
return res.end("Timed out waiting for function to respond.");
}
res.statusCode = 500;
res.end(`An internal error occurred while proxying for ${rewriteIdentifier}`);
});
proxied.on("response", (response) => {
if (response.statusCode === 404) {
// x-cascade is not a string[].
const cascade = response.headers["x-cascade"] as string;
if (cascade && cascade.toUpperCase() === "PASS") {
return next();
}
}
// default to private cache
if (!response.headers["cache-control"]) {
response.headers["cache-control"] = "private";
}
// don't allow cookies to be set on non-private cached responses
if (response.headers["cache-control"].indexOf("private") < 0) {
delete response.headers["set-cookie"];
}
response.headers.vary = makeVary(response.headers.vary);
proxied.pipe(res);
});
};
示例2:
app.post('/__typewiz_report', (req: Request, res: Response) => {
req.pipe(fs.createWriteStream(outputName));
res.send();
});