本文整理汇总了TypeScript中http.ServerResponse类的典型用法代码示例。如果您正苦于以下问题:TypeScript ServerResponse类的具体用法?TypeScript ServerResponse怎么用?TypeScript ServerResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServerResponse类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createServer
var newServer = createServer((req: any, res: ServerResponse)=>{
if (req.url =='/big.html')
{
}
res.write("hi. its sample");
res.end();
})
示例2: nocache
return function nocache (_req: IncomingMessage, res: ServerResponse, next: () => void) {
res.setHeader('Surrogate-Control', 'no-store');
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, proxy-revalidate');
res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0');
next();
};
示例3: write404
function write404(
url: string | undefined,
response: ServerResponse,
logger: LoggerType
) {
logger.error(`write404: Squirrel requested unexpected url '${url}'`);
response.writeHead(404);
response.end();
}
示例4: _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('.')} -->`
);
}
示例5: function
return function (req: ServerRequest, resp: ServerResponse) {
resp.setHeader('Content-Type', 'application/json')
if (req.method === 'GET') {
bot.validate(req, resp)
} else if (req.method === 'POST') {
bot.parseMessagingEvent(req, resp)
} else {
resp.statusCode = 400
resp.end()
}
}
示例6: 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}));
});
示例7:
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);
};
示例8:
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();
});
示例9:
readstream.on("error", err => {
if ((err.code = "ENOENT")) {
// file not found
res.statusCode = 404;
res.end("Not Found");
} else {
console.error(err);
res.statusCode = 500;
res.end("Unknown Server Error");
}
});
示例10:
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();
};