当前位置: 首页>>代码示例>>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;未经允许,请勿转载。