本文整理汇总了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('.')} -->`);
}
示例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);
}
示例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}));
});
示例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);
};
示例5: send
function send(contentType: string, data: string) {
response.writeHead(200, {
'Content-Type': contentType,
'Content-Length': Buffer.byteLength(data)
});
response.end(data);
}
示例6: write404
function write404(
url: string | undefined,
response: ServerResponse,
logger: LoggerType
) {
logger.error(`write404: Squirrel requested unexpected url '${url}'`);
response.writeHead(404);
response.end();
}
示例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();
});
示例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();
};
示例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);
}
示例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();
}