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

How can I set Content-Type header to the content generated from reply.view? #1760

Closed
midnight-wonderer opened this issue Jul 7, 2014 · 1 comment
Labels
Milestone

Comments

@midnight-wonderer
Copy link
Contributor

@midnight-wonderer midnight-wonderer commented Jul 7, 2014

Hello,
I want to set Content-Type header to the content generated from reply.view.
Here what I tried.

this is my route:

{
    path: "/someawesome.txt",
    method: "GET",
    handler: function(request, reply) {
        reply.view("mytemplate", {title:"mytitle"}
        ).type("text/plain");
    }
}

It reply with text/html as the Content-Type. (not what I expected)
I also tried using header method instead of type method without success.
The MIME type got overrode somewhere else.

What's the proper way to set Content-Type in this situation?
and Why doesn't my method works?

@midnight-wonderer
Copy link
Contributor Author

@midnight-wonderer midnight-wonderer commented Jul 7, 2014

I just debug the hapi server and found out that it got overrode in
https://github.com/spumko/hapi/blob/master/lib/views.js

 self.type(config.contentType);
 self.encoding(config.encoding);

So it look like in order to set the content type I have to set (config) it beforehand (since hapi server being created) by passing it as views.contentType and no mechanism to override.

IMO you guys have weird approach for doing things.
my Content-Type got overrode without my consent (also the solution is to override it to something else) and this approach make me unable to use same file extension for templates file (with same template engine) that have different MIME-Type.

Anyway I'm totally new to hapi. I might be wrong. If someone have something to add please do so. Probably you have proper solution to set Content-Type per request rather than using different file extension on template files.

Loading

@danielb2 danielb2 added the bug label Jul 7, 2014
@danielb2 danielb2 self-assigned this Jul 7, 2014
midnight-wonderer added a commit to midnight-wonderer/hapi that referenced this issue Jul 7, 2014
hueniverse pushed a commit that referenced this issue Jul 14, 2014
fix content-type overriding issue #1760.
@hueniverse hueniverse added this to the 6.1.0 milestone Jul 14, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 12, 2020
@lock lock bot unassigned danielb2 Jan 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants