head & content-length (wip)
This commit is contained in:
parent
0cd49572a6
commit
4edafbcb7b
|
@ -53,8 +53,8 @@ export default class flummpress {
|
||||||
|
|
||||||
await Promise.all([...this.middleware].map(m => m(req, res)));
|
await Promise.all([...this.middleware].map(m => m(req, res)));
|
||||||
|
|
||||||
const method = req.method.toLowerCase();
|
const method = req.method === 'HEAD' ? 'get' : req.method.toLowerCase();
|
||||||
const route = this.router.getRoute(req.url.pathname, req.method);
|
const route = this.router.getRoute(req.url.pathname, req.method == 'HEAD' ? 'GET' : req.method);
|
||||||
|
|
||||||
if(route) { // 200
|
if(route) { // 200
|
||||||
const cb = route[1][method];
|
const cb = route[1][method];
|
||||||
|
@ -107,7 +107,16 @@ export default class flummpress {
|
||||||
code = 200,
|
code = 200,
|
||||||
type = "text/html",
|
type = "text/html",
|
||||||
body
|
body
|
||||||
}) => res.writeHead(code, { "Content-Type": `${type}; charset=utf-8` }).end(body);
|
}) => {
|
||||||
|
res.writeHead(code, {
|
||||||
|
"content-type": `${type}; charset=UTF-8`,
|
||||||
|
"content-length": body.length
|
||||||
|
});
|
||||||
|
if(res.method === 'HEAD')
|
||||||
|
body = null;
|
||||||
|
res.end(body);
|
||||||
|
return res;
|
||||||
|
};
|
||||||
res.json = (body, code = 200) => {
|
res.json = (body, code = 200) => {
|
||||||
if(typeof body === 'object')
|
if(typeof body === 'object')
|
||||||
body = JSON.stringify(body);
|
body = JSON.stringify(body);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user