Creating an HTTP Proxy Server in Go

913 views
Skip to first unread message

DM

unread,
Sep 18, 2015, 7:51:03 AM9/18/15
to golang-nuts
I want to create a http proxy server in go that will receive a request and send the request to another server with all the headers and then return the response it receives to the caller. Can some one let me know how this can be done efficiently?

Giulio Iotti

unread,
Sep 18, 2015, 8:08:41 AM9/18/15
to golang-nuts
On Friday, September 18, 2015 at 1:51:03 PM UTC+2, DM wrote:
I want to create a http proxy server in go that will receive a request and send the request to another server with all the headers and then return the response it receives to the caller. Can some one let me know how this can be done efficiently?

That's a reverse proxy, please google for recipes on how to make one.


-- 
Giulio Iotti

Brad Fitzpatrick

unread,
Sep 18, 2015, 12:20:13 PM9/18/15
to DM, golang-nuts
This is actually included with Go already: http://golang.org/pkg/net/http/httputil/#ReverseProxy


On Fri, Sep 18, 2015 at 4:51 AM, DM <subhara...@gmail.com> wrote:
I want to create a http proxy server in go that will receive a request and send the request to another server with all the headers and then return the response it receives to the caller. Can some one let me know how this can be done efficiently?

--
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.

Guillaume J. Charmes

unread,
Sep 18, 2015, 1:23:48 PM9/18/15
to Brad Fitzpatrick, DM, golang-nuts
Or if you want I created a small utils to extend the reverse proxy from the stdlib: https://github.com/creack/goproxy

Debraj Manna

unread,
Sep 20, 2015, 9:28:39 AM9/20/15
to golang-nuts

Thanks :)

Nathan Fisher

unread,
Sep 20, 2015, 1:00:51 PM9/20/15
to DM, golang-nuts
Hello,

I implemented a configurable HTTPS proxy for local development of multiple web-services and a single static site. The built-in libraries make it really easy if you're already familiar with the HTTP server module. The only thing to be aware of with the proxy is that it forwards the external hostname. If you're proxy is found at "yolo.appspot.com" and the proxy URL is specified as "junctionbox.ca:80" it'll use the IP resolved for "junctionbox.ca" and the HOST header will be "yolo.appspot.com".

Nathan

On Fri, 18 Sep 2015 at 12:51 DM <subhara...@gmail.com> wrote:
I want to create a http proxy server in go that will receive a request and send the request to another server with all the headers and then return the response it receives to the caller. Can some one let me know how this can be done efficiently?

--
Reply all
Reply to author
Forward
0 new messages