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


TypeScript http.IncomingMessage類代碼示例

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


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

示例1: callback

  }, (response: IncomingMessage) => {
    if (response.statusCode >= 400) {
      callback(new Error("Request error, status " + response.statusCode + ": " + response.statusMessage))
      return
    }

    const redirectUrl = response.headers.location
    if (redirectUrl != null) {
      if (redirectCount < maxRedirects) {
        doDownload(redirectUrl, destination, redirectCount++, callback)
      }
      else {
        callback(new Error("Too many redirects (> " + maxRedirects + ")"))
      }
      return
    }

    const downloadStream = createWriteStream(destination)
    response.pipe(downloadStream)
    downloadStream.on("finish", () => downloadStream.close(callback))

    let ended = false
    response.on("end", () => {
      ended = true
    })

    response.on("close", () => {
      if (!ended) {
        callback(new Error("Request aborted"))
      }
    })
  })
開發者ID:Dreadchild,項目名稱:electron-builder,代碼行數:32,代碼來源:httpRequest.ts

示例2: return

  return (req: IncomingMessage, res: ServerResponse) => {
    // return 404 if path is /bogus-route to pass the test, lambda doesn't have paths
    if (req.url.includes('/bogus-route')) {
      res.statusCode = 404;
      return res.end();
    }

    let body = '';
    req.on('data', chunk => (body += chunk));
    req.on('end', () => {
      const urlObject = url.parse(req.url, true);
      const event = {
        httpMethod: req.method,
        body: body,
        path: req.url,
        queryStringParameters: urlObject.query,
        requestContext: {
          path: urlObject.pathname,
        },
        headers: req.headers,
      };
      const callback = (error, result) => {
        if (error) throw error;
        res.statusCode = result.statusCode;
        for (let key in result.headers) {
          if (result.headers.hasOwnProperty(key)) {
            res.setHeader(key, result.headers[key]);
          }
        }
        res.write(result.body);
        res.end();
      };
      handler(event as any, {} as any, callback);
    });
  };
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:35,代碼來源:lambdaApollo.test.ts

示例3: return

  return (req: IncomingMessage, res: ServerResponse) => {
    // return 404 if path is /bogus-route to pass the test, azure doesn't have paths
    if (req.url.includes('/bogus-route')) {
      res.statusCode = 404;
      return res.end();
    }

    let body = '';
    req.on('data', chunk => (body += chunk));
    req.on('end', () => {
      const urlObject = url.parse(req.url, true);
      const request = {
        method: req.method,
        body: body && JSON.parse(body),
        path: req.url,
        query: urlObject.query,
        headers: req.headers,
      };
      const context = {
        done(error, result) {
          if (error) throw error;
          res.statusCode = result.status;
          for (let key in result.headers) {
            if (result.headers.hasOwnProperty(key)) {
              res.setHeader(key, result.headers[key]);
            }
          }
          res.write(result.body);
          res.end();
        },
      };
      handler(context as any, request as any);
    });
  };
開發者ID:apollostack,項目名稱:apollo-server,代碼行數:34,代碼來源:azureFunctionApollo.test.ts

示例4:

 http.get(url, (response: IncomingMessage) => {
     response.setEncoding("utf8");
     response.on("data", (result: string) => {
         result.split("\n").forEach((char: string) => {
             console.log(char);
         });
     });
 });
開發者ID:kyanro,項目名稱:nodeschool-learnyounode,代碼行數:8,代碼來源:main.ts

示例5: outputIfFinished

 http.get(url, (response: IncomingMessage) => {
     let buf: string = "";
     response.setEncoding("utf8");
     response.on("data", (result: string) => {
         buf += result;
     });
     response.on("end", () => {
         outputIfFinished(buf, index);
     });
 });
開發者ID:kyanro,項目名稱:nodeschool-learnyounode,代碼行數:10,代碼來源:main.ts

示例6: _handler

	private _handler(request: IncomingMessage, response: ServerResponse) {
		if (request.method === 'GET') {
			if (/\.js(?:$|\?)/.test(request.url)) {
				this._handleFile(request, response, this.instrument);
			}
			else {
				this._handleFile(request, response);
			}
		}
		else if (request.method === 'HEAD') {
			this._handleFile(request, response, false, true);
		}
		else if (request.method === 'POST') {
			request.setEncoding('utf8');

			let data = '';
			request.on('data', function (chunk) {
				data += chunk;
			});

			request.on('end', () => {
				try {
					let rawMessages: any = JSON.parse(data);

					if (!Array.isArray(rawMessages)) {
						rawMessages = [rawMessages];
					}

					const messages: Message[] = rawMessages.map(function (messageString: string) {
						return JSON.parse(messageString);
					});

					Promise.all(messages.map(message => this._handleMessage(message))).then(
						() => {
							response.statusCode = 204;
							response.end();
						},
						() => {
							response.statusCode = 500;
							response.end();
						}
					);
				}
				catch (error) {
					response.statusCode = 500;
					response.end();
				}
			});
		}
		else {
			response.statusCode = 501;
			response.end();
		}
	}
開發者ID:bryanforbes,項目名稱:intern,代碼行數:54,代碼來源:Server.ts

示例7:

	}, (res: IncomingMessage) => {

		res.setEncoding("utf8");

		let data = "";
		res.on("data", (chunk: string) => {
			data += chunk;
		}).on("end", () => {
			console.log(data);
		});

	});
開發者ID:Psychopoulet,項目名稱:node-logs,代碼行數:12,代碼來源:compilation.ts

示例8: callback

 (res: IncomingMessage) => {
   const data: Buffer[] = [];
   res.on("data", chunk => data.push(chunk as Buffer));
   res.on("end", () => {
     const result = res as ArangojsResponse;
     result.request = req;
     result.body = Buffer.concat(data);
     if (called) return;
     called = true;
     callback(null, result);
   });
 }
開發者ID:arangodb,項目名稱:arangojs,代碼行數:12,代碼來源:request.node.ts


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