本文整理汇总了TypeScript中http.IncomingMessage.resume方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IncomingMessage.resume方法的具体用法?TypeScript IncomingMessage.resume怎么用?TypeScript IncomingMessage.resume使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.IncomingMessage
的用法示例。
在下文中一共展示了IncomingMessage.resume方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: response
// Handle the HTTP response.
function response (res: IncomingMessage) {
const status = res.statusCode
const redirect = REDIRECT_STATUS[status]
// Handle HTTP redirects.
if (followRedirects && redirect != null && res.headers.location) {
const newUrl = urlLib.resolve(url, res.headers.location)
// Ignore the result of the response on redirect.
res.resume()
// Kill the old cookies on redirect.
request.remove('Cookie')
if (redirect === REDIRECT_TYPE.FOLLOW_WITH_GET) {
// Update the "Content-Length" for updated redirection body.
request.set('Content-Length', '0')
return get(newUrl, 'GET')
}
if (redirect === REDIRECT_TYPE.FOLLOW_WITH_CONFIRMATION) {
// Following HTTP spec by automatically redirecting with GET/HEAD.
if (arg.method === 'GET' || arg.method === 'HEAD') {
return get(newUrl, method, body)
}
// Allow the user to confirm redirect according to HTTP spec.
if (confirmRedirect(req, res)) {
return get(newUrl, method, body)
}
}
}
request.downloadLength = num(res.headers['content-length'], 0)
// Track download progress.
res.pipe(responseProxy)
return Promise.resolve({
body: responseProxy,
status: status,
statusText: res.statusMessage,
headers: res.headers,
rawHeaders: res.rawHeaders,
url: url
})
}
示例2: send
// HELPER FUNCTIONS
// =================================================================================================
function send(request: IncomingMessage, response: ServerResponse, status: number, headers: { [index: string]: string; }, body: string) {
function write () {
// response status
response.statusCode = status;
// response.statusMessage = STATUS_CODES[status];
// response headers
if (headers) {
for (let key in headers) {
response.setHeader(key, headers[key]);
}
}
// standard headers
response.setHeader('Content-Type', 'application/json; charset=utf-8')
response.setHeader('Content-Length', Buffer.byteLength(body, 'utf8').toString(10));
if (request.method === 'HEAD') {
response.end();
}
else {
response.end(body, 'utf8');
}
}
if (onFinished.isFinished(request)) {
write();
}
else {
// unpipe everything from the request
request.unpipe();
// flush the request
onFinished(request, write);
request.resume();
}
}
示例3:
const listening: boolean = server.listening;
const keepAliveTimeout: number = server.keepAliveTimeout;
server.setTimeout().setTimeout(1000).setTimeout(() => {}).setTimeout(100, () => {});
}
// http IncomingMessage
// http ServerResponse
{
// incoming
const incoming: http.IncomingMessage = new http.IncomingMessage(new net.Socket());
incoming.setEncoding('utf8');
// stream
incoming.pause();
incoming.resume();
// response
const res: http.ServerResponse = new http.ServerResponse(incoming);
// test headers
res.setHeader('Content-Type', 'text/plain');
const bool: boolean = res.hasHeader('Content-Type');
const headers: string[] = res.getHeaderNames();
// trailers
res.addTrailers([
['x-fOo', 'xOxOxOx'],
['x-foO', 'OxOxOxO'],
['X-fOo', 'xOxOxOx'],
['X-foO', 'OxOxOxO']