You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
What are you trying to achieve or the steps to reproduce?
Trying to respond with a stream and receive an appropriate content-type header on the client.
Under most circumstances, hapi sends a content-type header automatically based on whatever the return value of my handler is. However, if the handler returns a stream, this doesn't happen.
Here is a reproducible example that shows no content-type header being sent for a simple "Hello, world!" stream. The response headers are logged to the server's console when starting the server and also rendered in the browser if you visit /.
No content-type header is sent in the response when the handler's return value is a simple "Hello, world!" readable stream.
What did you expect?
I expected hapi to set a content-type header whenever possible.
Ideally, I'd like it to be based on the actual contents of the stream, which could be determined by reading the first few bytes to inspect the magic number (also see the file-type module). But even the generic application/octect-stream would be better than nothing.
node version: 8.11.3
hapi version: 17.6.0
os: macOS 10.13.6
The text was updated successfully, but these errors were encountered:
hapi is never going to try and guess the content type by peeking at the first few bytes. You can set your own content type when returning a stream using h.response(stream).type('text/html'). I'll look into setting a default value.