hexojs / hexo-server

Server module for Hexo.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server should check whether header has already been set to prevent overwriting

9662 opened this issue · comments

commented

This line:

res.setHeader('Content-Type', extname ? mime.lookup(extname) : 'application/octet-stream');

interferes with my own middleware, which sets Content-Type for files that are not recognised by mime.lookup, but then the header gets overwritten by the above line.

The router middleware should check if the header has already been set before trying to set its value.

Hey @9662 👋 How did you run into that problem? Can you provide a test case?

commented

I am afraid I no longer recall the circumstances around this issue, but looking at my activity around the reporting date, I think a realistic test case could be as follows:

Have a generator middleware that extracts event-related custom metadata from the front matter and uses it to produce .ics files. Because the generated ICS files would normally be served by hexo serve with an inadequate Content-Type (possibly application/octet-stream or text/plain) they would not trigger the desired browser behaviour while testing locally, therefore you will also be needing a filter middleware to add the correct Content-Type: text/calendar header. This filter middleware would cause the reported error.

In the end I must have implemented this differently so I never followed up.

@9662 Oh if there was a solution maybe you can post it. How do you want to proceed? Should we still look for a solution or close it?

commented

@tcrowe Seems like a had an old pull request dealing with this. Let me check if it's salvageable.

commented

Yup, that's the one. I just rebased and updated.