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

What is the best way to access request headers? #1114

Closed
jeffbski opened this issue Oct 22, 2013 · 5 comments
Closed

What is the best way to access request headers? #1114

jeffbski opened this issue Oct 22, 2013 · 5 comments
Labels
feature New functionality or improvement
Milestone

Comments

@jeffbski
Copy link
Contributor

In reading through the docs it wasn't clear what is the best way to access the request headers (or what is the hapi way).

I realize that one can go to request.raw.req.headers but from the docs, we are told to avoid using raw where possible, so is there a better way?

I understand that it is nice to abstract things away where possible, and for some things like auth, one could read the headers in a plugin and then set something in the artifacts.

Maybe that's the recommended approach for other things too, read them in a plugin and set some business state in a plugin?

Thanks in advance for any suggestions or advice. I am enjoying using Hapi.

@jeffbski
Copy link
Contributor Author

Some examples of headers that are commonly needed are:

  • range
  • content-md5
  • accept-language
  • accept
  • if-match, if-none-match, if-* for put, post, delete
  • referer
  • upgrade
  • custom headers added by an authorizing proxy for user and role (this one might be done as good auth plugin but still could be good to have direct read access)

So it would be good to have a Hapi strategy for accessing these and any others needed.

Thoughts?

@0xgeert
Copy link

0xgeert commented Oct 24, 2013

I'm not familiar with another method (don't believe it exists), but using
raw.req.headers for reads (as opposed to CUD) doesn't have side-effects
so is perfectly save.
In fact the reference makes use of them:
https://github.com/spumko/hapi/blob/master/docs/Reference.md#stream

On Thu, Oct 24, 2013 at 5:27 PM, Jeff Barczewski
notifications@github.comwrote:

Some examples of headers that are commonly needed are:

  • range
  • content-md5
  • accept-language
  • accept
  • if-match, if-none-match, if-* for put, post, delete
  • referer
  • upgrade
  • custom headers added by an authorizing proxy for user and role (this
    one might be done as good auth plugin but still could be good to have
    direct read access)

So it would be good to have a Hapi strategy for accessing these and any
others needed.

Thoughts?


Reply to this email directly or view it on GitHubhttps://github.com//issues/1114#issuecomment-27002119
.

@hueniverse
Copy link
Contributor

Just use request.raw.req.headers. Raw is fully supported. I'll add request.headers but that will just be a reference to the above.

@jeffbski
Copy link
Contributor Author

Thanks Eran. Adding request.headers will be great so we don't have to access core object which could change in future. Good to have a light abstraction for some key things.

jmonster pushed a commit to jmonster/hapi that referenced this issue Feb 10, 2014
@Marsup Marsup added feature New functionality or improvement and removed request labels Sep 20, 2019
@lock
Copy link

lock bot commented Jan 9, 2020

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.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature New functionality or improvement
Projects
None yet
Development

No branches or pull requests

4 participants