當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。