當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript IncomingMessage.resume方法代碼示例

本文整理匯總了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
            })
          }
開發者ID:garethhunt,項目名稱:popsicle,代碼行數:49,代碼來源:index.ts

示例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();
    }
}
開發者ID:herculesinc,項目名稱:nova-server,代碼行數:40,代碼來源:finalhandler.ts

示例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']
開發者ID:SaschaNaz,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:http.ts


注:本文中的http.IncomingMessage.resume方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。