Static html is served as download content
talamaska opened this issue · comments
Hi, I have included today h5bp as middleware in my express app, it's added exactly as in your example, before compress and static content. I think something is wrong with the header. Here is what I get from network tab in Chrome. It's Content-Type:application/octet-stream. Can you please help me with configuration, I'm using this example as testing platform
https://github.com/madhums/nodejs-express-mongoose-demo
Request URL:http://localhost:3000/
Request Method:GET
Status Code:206 Partial Content
Request Headers
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en,bg;q=0.8,en-US;q=0.6
Connection:keep-alive
Host:localhost:3000
If-Range:Sun, 24 Feb 2013 16:42:41 GMT
Range:bytes=3811-3811
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.97 Safari/537.22
Response Headers
Accept-Ranges:bytes
cache-control:public,max-age=2419200,no-transform
connection:keep-alive
Content-Length:1
Content-Range:bytes 3811-3811/6738
Content-Type:application/octet-stream
Date:Sun, 24 Feb 2013 16:58:35 GMT
Last-Modified:Sun, 24 Feb 2013 16:42:41 GMT
Vary:Accept-Encoding
Hi, I can reproduce the bug.
The invalid content-type
is set by h5bp
because the requested file has no extension. When the express
router serves this file, express
does not override the invalid content-type
.
h5bp
should not set the content-type
for routes, or any file without extension. According the the http spec, when unknown, content-type
can be optional:
Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream".
For now, you could apply this very ugly patch to your application to remove the invalid header.
Paste this right after h5bp
middleware:
app.use(function(req, res, next) {
if ('application/octet-stream' == res.get('content-type')) {
res.removeHeader('content-type');
}
next();
});
Well the file that is requested by default before going to the view engine is index.html, this is tested. And that's exactly what i see if i open the file that i have downloaded. So it has extension - *.html. A little detail that I missed giving information for the report, is that I have created an index.html file in the public folder. I noticed described behavior after including h5bp as middleware.
Can you dump here your modifications of nodejs-express-mongoose-demo or fork it so I can test in the exactly same environment as you?
Does the very ugly patch resolve your problem?
it's very ugly patch i don't want to implement it. I might have downloadable content.
Well i have just added html 5 boilerplate from http://www.initializr.com/ into public. that's the only change with which i'm testing currently.
https://github.com/talamaska/nodejs-express-mongodb
here is the repo and config, but i have not included your package. It's just showing that the static content is loaded before the view engine.
Ok I will have a look then.
It should be fixed w/ the repo you gave me.
You can test it by installing the fixed version like this: npm install https://github.com/h5bp/node-server-config/tarball/issue/7
Tell me if the issue is still present.
Thanks.
Nope, the bug is not present. Thanks for looking at it.