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.Dismiss alert
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.
Context
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.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
lockbot
locked as resolved and limited conversation to collaborators
Jan 9, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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/
.Source code
What was the result you received?
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.Context
The text was updated successfully, but these errors were encountered: