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 to define HTTP headers to 'always' be returned? #53

Closed
etnt opened this issue Feb 19, 2011 · 3 comments
Closed

How to define HTTP headers to 'always' be returned? #53

etnt opened this issue Feb 19, 2011 · 3 comments

Comments

@etnt
Copy link
Collaborator

etnt commented Feb 19, 2011

Hi folks, Let's say I want to always return a 'Origin:' header (see: http://www.w3.org/TR/cors/). How can I do that? For an appmod, or yaws-page that is easy, but how about index.html or Javascript files being served? Perhaps a server-config <header>Origin: http://example.com </header> could work?

Cheers, Tobbe

@vinoski
Copy link
Collaborator

vinoski commented Feb 20, 2011

Hey Tobbe, how's it going? I think an appmod registered for "/" that returned

{page, {[{header, {"Origin", "http://example.com"}}], OriginalUrl}}.

can do this. More completely:

out(Arg) ->
    Req = Arg#arg.req,
    {abs_path, Path} = Req#http_request.path,
    {page, {[{header, {"X-Extra-Header", "testing testing"}}], Path}}.

There are drawbacks to this, of course, which is that this code doesn't handle query parameters (though it could), and that the extra header is included in the response even if the result is a 404 or other error.

Still, adding some sort of config option wouldn't be a bad idea. Adding a URI matching capability for this would be handy, something along the lines of "if you see a URI matching this pattern add these headers to the response."

@etnt
Copy link
Collaborator Author

etnt commented Feb 21, 2011

Yes, an appmod for '/' would do it. But I guess it would hijack the whole URI namespace, which wouldn't be acceptable in most cases I suspect, or?

So some sort of config option could be good in this case.

@klacke
Copy link
Collaborator

klacke commented Feb 23, 2011

I know of no good ways to to this, it'll require some hackery.

@klacke klacke closed this as completed Nov 7, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants