What's required to build a complete HTTP reverse proxy in go? -


a naive reverse proxy this:

package main  import (     "net/http"     "net/http/httputil"     "net/url"     "fmt" )  func main() {      // new functionality written in go     http.handlefunc("/new", func(w http.responsewriter, r *http.request) {         fmt.fprint(w, "new function")     })      // don't in go, pass old platform     u, _ := url.parse("http://www.google.com/")     http.handle("/", httputil.newsinglehostreverseproxy(u))      // start server     http.listenandserve(":8080", nil) } 

but, incomplete. depending on website might not useful back. https redirect. complain direct ip access. suspect virtual hosts don't work? not sure.

what true reverse proxy makes complete?

the simplest way implement reverse http proxy in go httputil.reverseproxy type in standard library.

this gives flexibility set director function can modify incoming requests, , transport possibly modify requests and/or responses on-the-fly.

it should able handle vast majority of reverse proxy situations. use great success in project of mine.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -