本文整理匯總了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();
});