当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ServerResponse.writeHead方法代码示例

本文整理汇总了TypeScript中http.ServerResponse.writeHead方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerResponse.writeHead方法的具体用法?TypeScript ServerResponse.writeHead怎么用?TypeScript ServerResponse.writeHead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.ServerResponse的用法示例。


在下文中一共展示了ServerResponse.writeHead方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: _send404

	private _send404(response: ServerResponse) {
		response.writeHead(404, {
			'Content-Type': 'text/html;charset=utf-8'
		});
		response.end(`<!DOCTYPE html><title>404 Not Found</title><h1>404 Not Found</h1>` +
			`<!-- ${new Array(512).join('.')} -->`);
	}
开发者ID:bryanforbes,项目名称:intern,代码行数:7,代码来源:Server.ts

示例2: pipeUpdateToSquirrel

function pipeUpdateToSquirrel(
  filePath: string,
  server: Server,
  response: ServerResponse,
  logger: LoggerType,
  reject: (error: Error) => void
) {
  const updateFileSize = getFileSize(filePath);
  const readStream = createReadStream(filePath);

  response.on('error', (error: Error) => {
    logger.error(
      'pipeUpdateToSquirrel: update file download request had an error',
      getPrintableError(error)
    );
    shutdown(server, logger);
    reject(error);
  });

  readStream.on('error', (error: Error) => {
    logger.error(
      'pipeUpdateToSquirrel: read stream error response:',
      getPrintableError(error)
    );
    shutdown(server, logger, response);
    reject(error);
  });

  response.writeHead(200, {
    'Content-Type': 'application/zip',
    'Content-Length': updateFileSize,
  });

  readStream.pipe(response);
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:35,代码来源:macos.ts

示例3: makeSubpath

    form.parse(req, (err, fields:Fields, files:Files)=> {

        if (!files) {
            res.end(JSON.stringify({ok: false, error: "no_file_data"}));
        }

        var file = files["file"];
        var tmpPath = file.path;
        var subDir = makeSubpath(token);
        var newDir = '/thumbs/' + subDir;
        var newPath = newDir + "/" + jpgFile;

        fs.exists(newDir, (exists:boolean)=> {
            if (!exists) {
                // console.log("Folder " + newDir + " not exist");
                mkdirp(newDir, (err)=> {
                    if (err) {
                        res.end(JSON.stringify({ok: false, error: "cant_create_subdir"}));
                        console.error(err);
                    } else {
                        moveFile(tmpPath, newPath);
                    }
                });
            } else {
                moveFile(tmpPath, newPath);
            }
        });

        res.writeHead(200, {'content-type': 'text/plain'});
        res.end(JSON.stringify({ok: true, url: subDir + "/" + jpgFile}));
    });
开发者ID:terbooter,项目名称:LVK-thumbs,代码行数:31,代码来源:app.ts

示例4:

 const end = (output: HandlerOutput<Value>) => {
   res.writeHead(200, { 'Content-Type': 'application/json' });
   const outputString = IS_NOW
     ? JSON.stringify(output)
     : JSON.stringify(output, null, 2);
   res.end(outputString);
 };
开发者ID:este,项目名称:este,代码行数:7,代码来源:createHandler.ts

示例5: send

		function send(contentType: string, data: string) {
			response.writeHead(200, {
				'Content-Type': contentType,
				'Content-Length': Buffer.byteLength(data)
			});
			response.end(data);
		}
开发者ID:bryanforbes,项目名称:intern,代码行数:7,代码来源:Server.ts

示例6: write404

function write404(
  url: string | undefined,
  response: ServerResponse,
  logger: LoggerType
) {
  logger.error(`write404: Squirrel requested unexpected url '${url}'`);
  response.writeHead(404);
  response.end();
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:9,代码来源:macos.ts

示例7:

 server.sendRequest(baseUrl + request.url, pathname[2], (res: Host.Response) => {
   response.writeHead(res.status, server.headers);
   if (res.success) {
     response.write(res.data);
     server.setCache(request.url, res.data);
   } else {
     response.write(res.data + '\n');
   }
   response.end();
 });
开发者ID:gitter-badger,项目名称:LegendBuilder,代码行数:10,代码来源:static-server.ts

示例8: checkForKillCommand

export function checkForKillCommand(req: IncomingMessage, res: ServerResponse, next: NextFunction) {
    if (req.url == "/kill") {
        res.setHeader('Content-Type', 'text/plain');
        res.writeHead(200);
        res.end("Goodbye");
        console.log("Received kill command");
        process.exit();
    }
    else
        next();
};
开发者ID:roberthardy,项目名称:rp,代码行数:11,代码来源:utils.ts

示例9: writeJSONResponse

function writeJSONResponse(url: string, response: ServerResponse) {
  const data = Buffer.from(
    JSON.stringify({
      url,
    })
  );
  response.writeHead(200, {
    'Content-Type': 'application/json',
    'Content-Length': data.byteLength,
  });
  response.end(data);
}
开发者ID:WhisperSystems,项目名称:Signal-Desktop,代码行数:12,代码来源:macos.ts

示例10: finish

    /**
     * finish HTTP request
     * @param status - HTTP status code
     * @param headers - HTTP headers
     * @param entiry - HTTP response entiry data
     */
    private finish(
        status: number,
        headers: OutgoingHttpHeaders,
        entiry?: Object
    ) {
        let res = this.res;

        headers = Object.assign({ 'Content-Type': 'text/html' }, headers);

        res.writeHead(status, headers);
        if (entiry !== undefined) res.write(entiry);

        res.end();
    }
开发者ID:lleobox,项目名称:flask-node,代码行数:20,代码来源:response.ts


注:本文中的http.ServerResponse.writeHead方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。