[net/http.Request] How to get the original request URL path?

3,063 views
Skip to first unread message

yic...@gmail.com

unread,
Jun 10, 2014, 1:05:23 PM6/10/14
to golan...@googlegroups.com
Hello, 

My Go web service will serve traffic from a redirect, from a url like http://www.original_host.com/original_path/

Any requests that goes to the URL pattern http://www.host.com/map/* will be served by my Golang web service as root path "/".

I am writing the web service using go-martini, but I am having trouble retrieving the original request URL. Inside the go-martini app, it seems the data in http.Request are all in the context of the local/relative path. Is there a way to get the full request path? 

Thanks,
YI

Ken MacDonald

unread,
Jun 10, 2014, 2:33:41 PM6/10/14
to yic...@gmail.com, golang-nuts
Sender := req.Header.Get("X-Real-IP")

This seemed to work for us....


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kevin Gillette

unread,
Jun 10, 2014, 7:06:53 PM6/10/14
to golan...@googlegroups.com, yic...@gmail.com
That's a non-standard header. Certainly not every client (if even very many) will send it.

Matt Silverlock

unread,
Jun 10, 2014, 7:14:21 PM6/10/14
to golan...@googlegroups.com, yic...@gmail.com
More information?
  • Have you tried r.URL.Host + r.URL.Path (see http://golang.org/pkg/net/url/#URL)
  • Or are you having issues getting the *host* due to sitting behind a reverse proxy? In which case you'll need to add (e.g; for nginx) X-Forwarded-For $proxy_add_x_forwarded_for to your webserver config
I am assuming it's the former though.
Reply all
Reply to author
Forward
0 new messages