HTTP Headers

56 views
Skip to first unread message

Robert Mulley

unread,
Apr 18, 2013, 2:56:52 PM4/18/13
to golang...@googlegroups.com
It's possible I missed this somewhere, but I've been looking and was unable to find it documented anywhere.  Does GoWeb provided a method for retrieving HTTP Headers?  For example, I would like to have users send an authorization header when accessing my REST API.  I thought something like the line below would work, but now luck.  Any ideas?  Thanks.

c.Header.Get("data")

Tyler Bunnell

unread,
Apr 18, 2013, 3:12:34 PM4/18/13
to golang...@googlegroups.com
Headers are part of the ResponseWriter inside the context.

c.ResponseWriter.Header().Set()/Get()

That should get you heading in the right direction. :)

http://golang.org/pkg/net/http/


On Apr 18, 2013, at 12:56 PM, Robert Mulley <rmu...@gmail.com> wrote:

> It's possible I missed this somewhere, but I've been looking and was unable to find it documented anywhere. Does GoWeb provided a method for retrieving HTTP Headers? For example, I would like to have users send an authorization header when accessing my REST API. I thought something like the line below would work, but now luck. Any ideas? Thanks.
>
> c.Header.Get("data")
>
> --
> You received this message because you are subscribed to the Google Groups "goweb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to golang-goweb...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Robert Mulley

unread,
Apr 18, 2013, 3:58:36 PM4/18/13
to golang...@googlegroups.com
Thanks Tyler.  It looks like I'm able to set the headers, but unable to get any of them.  As an explanation, here is what's happening step-by-step:

1) Using Chrome Poster in Google Chrome, I make a request to a URL.  I've set a header called data.  This is an API call so I expect a response of a JSON containing certain data.

2) The server takes the request, and outputs the data header which is blank.

3) A dummy header is set for testing purposes. The correct JSON response as well as the dummy header are all returned fine.

It seems like this should be a pretty simple task, and I'm not sure why I'm unable see any of the HTTP headers in Go.

Tyler Bunnell

unread,
Apr 18, 2013, 9:55:02 PM4/18/13
to golang...@googlegroups.com
Get those out of context.Request.Header

Robert Mulley

unread,
Apr 19, 2013, 12:08:07 PM4/19/13
to golang...@googlegroups.com
I was able to retrieve the data header via: c.Request.Header["Data"][0].

Thanks for all the help!
Reply all
Reply to author
Forward
0 new messages