Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StreamableFile overrides Content-Type header #7586

Closed
dzunftmeister-evorhei opened this issue Jul 16, 2021 · 3 comments
Closed

StreamableFile overrides Content-Type header #7586

dzunftmeister-evorhei opened this issue Jul 16, 2021 · 3 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@dzunftmeister-evorhei
Copy link
Contributor

Feature Request

Is your feature request related to a problem? Please describe.

StreamableFile set a fixed content-type header of application/octet-stream, even if you set an other like response.header('content-type', 'image/svg')

https://github.com/dzunftmeister-evorhei/nest-streamablefile-res-issue
nest run start:dev
http://localhost:3000/fileTestInline

Describe the solution you'd like

there should be a possibility to set the content-type header to get inline view of files working
e.g. new StreamableFile(file, {contentType: 'image/svg'})

Teachability, Documentation, Adoption, Migration Strategy

What is the motivation / use case for changing the behavior?

@dzunftmeister-evorhei dzunftmeister-evorhei added needs triage This issue has not been looked into type: enhancement 🐺 labels Jul 16, 2021
@micalevisk
Copy link
Member

micalevisk commented Jul 16, 2021

This happen due to the following lines

if (body instanceof StreamableFile) {
response.setHeader('Content-Type', 'application/octet-stream');
return body.getStream().pipe(response);
}

And the commit message of b862e9c made by @jmcdo29 states this behavior.

But this behaves differently from fastify, which under the hood sets to application/octet-stream only if there's no content-type (I guess)

if (body instanceof StreamableFile) {
body = body.getStream();
}
return fastifyReply.send(body);
}

@dzunftmeister-evorhei
Copy link
Contributor Author

then we could do something like this for express ...
if (!response.getHeader('Content-Type')) { response.setHeader('Content-Type', 'application/octet-stream'); }

@kamilmysliwiec
Copy link
Member

Lets track this here #7589

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

3 participants