Server should check whether header has already been set to prevent overwriting
9662 opened this issue · comments
This line:
hexo-server/lib/middlewares/route.js
Line 33 in 92338ec
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?
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?
@tcrowe Seems like a had an old pull request dealing with this. Let me check if it's salvageable.
Yup, that's the one. I just rebased and updated.