Curling header returns HTTP status 404
th507 opened this issue · comments
demo app:
var app = require('koa')();
var route = require("koa-route");
app.use(route.get("/", function *(next){
this.body = 'Hello World';
}));
app.listen(8080);
When fetching HTTP-header with curl -I
, the server returns
# curl -I http://localhost:8080
HTTP/1.1 404 Not Found
X-Powered-By: koa
Date: Thu, 21 Aug 2014 02:20:00 GMT
Meanwhile, a browser visit or a normal curl yields the sane result
#curl -i --raw http://localhost:8080
HTTP/1.1 200 OK
X-Powered-By: koa
Content-Type: text/plain; charset=utf-8
Content-Length: 11
Date: Thu, 21 Aug 2014 02:57:46 GMT
Connection: keep-alive
Hello World
The 'problem' is that you handle only GET
type of requests using route.get
. The -I
uses HEAD type of request. So if you want to handle this, then use
app.use(router.head('/', function *(){
this.set('X-Response-message', 'Welcome to my HEAD');
this.status = 200;
}));
ah yeah this is usually handled by routers but koajs/route is pretty low level, however since koa core handles HEAD we should probably add HEAD here, definitely a necessity for every server even if it's a little weird since this is no longer 1:1
+1, I encountered the same problem today, critical issue
I created a PR for this #19.
2.3.0