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


TypeScript http2.Http2ServerResponse類代碼示例

本文整理匯總了TypeScript中http2.Http2ServerResponse的典型用法代碼示例。如果您正苦於以下問題:TypeScript Http2ServerResponse類的具體用法?TypeScript Http2ServerResponse怎麽用?TypeScript Http2ServerResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Http2ServerResponse類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1:

    const onRequestHandler = (request: Http2ServerRequest, response: Http2ServerResponse) => {
        // Http2ServerRequest

        const readable: Readable = request;
        let incomingHeaders: IncomingHttpHeaders = request.headers;
        incomingHeaders = request.trailers;
        const httpVersion: string = request.httpVersion;
        let method: string = request.method;
        let rawHeaders: string[] = request.rawHeaders;
        rawHeaders = request.rawTrailers;
        let socket: Socket | TLSSocket = request.socket;
        let stream: ServerHttp2Stream = request.stream;
        const url: string = request.url;

        request.setTimeout(0, () => {});
        request.on('aborted', (hadError: boolean, code: number) => {});

        // Http2ServerResponse

        let outgoingHeaders: OutgoingHttpHeaders = {
        };
        response.addTrailers(outgoingHeaders);
        socket = response.connection;
        const finished: boolean = response.finished;
        response.sendDate = true;
        response.statusCode = 200;
        response.statusMessage = '';
        socket = response.socket;
        stream = response.stream;

        method = response.getHeader(':method');
        const headers: string[] = response.getHeaderNames();
        outgoingHeaders = response.getHeaders();
        const hasMethod = response.hasHeader(':method');
        response.removeHeader(':method');
        response.setHeader(':method', 'GET');
        response.setHeader(':status', 200);
        response.setHeader('some-list', ['', '']);
        const headersSent: boolean = response.headersSent;

        response.setTimeout(0, () => {});
        response.createPushResponse(outgoingHeaders, (err: Error | null, res: Http2ServerResponse) => {});

        response.writeContinue();
        response.writeHead(200).end();
        response.writeHead(200, outgoingHeaders);
        response.writeHead(200, 'OK', outgoingHeaders);
        response.writeHead(200, 'OK');
        response.write('');
        response.write('', (err: Error) => {});
        response.write('', 'utf8');
        response.write('', 'utf8', (err: Error) => {});
        response.write(Buffer.from([]));
        response.write(Buffer.from([]), (err: Error) => {});
        response.write(Buffer.from([]), 'utf8');
        response.write(Buffer.from([]), 'utf8', (err: Error) => {});
        response.end();
        response.end(() => {});
        response.end('');
        response.end('', () => {});
        response.end('', 'utf8');
        response.end('', 'utf8', () => {});
        response.end(Buffer.from([]));
        response.end(Buffer.from([]), () => {});

        request.on('aborted', (hadError: boolean, code: number) => {});
        request.on('close', () => {});
        request.on('drain', () => {});
        request.on('error', (error: Error) => {});
        request.on('finish', () => {});
    };
開發者ID:apare,項目名稱:DefinitelyTyped,代碼行數:71,代碼來源:http2.ts

示例2: check

 .catch(() => {
     if (copyRoots.length) {
         check(copyRoots.pop());
     } else {
         res.writeHead(404, { 'Content-Type': 'text/plain' });
         res.end('404 Not Found\n');
     }
 });
開發者ID:wavesplatform,項目名稱:WavesGUI,代碼行數:8,代碼來源:utils.ts

示例3: readFile

 readFile(path).then((file: Buffer) => {
     res.setHeader('Cache-Control', 'public, max-age=31557600');
     res.writeHead(200, { 'Content-Type': contentType });
     res.end(file);
 })
開發者ID:wavesplatform,項目名稱:WavesGUI,代碼行數:5,代碼來源:utils.ts


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