Chained HTTP proxy that supports arbitrary TCP traffic tunneled over HTTP proxies using encapsulated HTTP requests
Go
Permalink
Failed to load latest commit information.
test Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
.gitignore Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
.travis.yml Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
LICENSE Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
README.md Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_impl.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_impl_reads.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_impl_requests.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_impl_writes.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_intf.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
conn_test.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
lazyconn.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
metrics.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
proxy.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
proxy_test.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016
request_strategy.go Squashed commits, full commit log available in https://github.com/get… Mar 17, 2016

README.md

enproxy Travis CI Status Coverage Status GoDoc

enproxy provides an implementation of net.Conn that sends and receives data to/ from a proxy using HTTP request/response pairs that encapsulate the data. This is useful when you need to tunnel arbitrary protocols over an HTTP proxy that doesn't support HTTP CONNECT. Content distribution networks are one example of such a proxy.

To open such a connection:

conn := &enproxy.Conn{
  Addr:   addr,
  Config: &enproxy.Config{
    DialProxy: func(addr string) (net.Conn, error) {
      // This opens a TCP connection to the proxy
      return net.Dial("tcp", proxyAddress)
    },
    NewRequest: func(method string, body io.Reader) (req *http.Request, err error) {
      // This is called for every request from enproxy.Conn to the proxy
      return http.NewRequest(method, "http://"+proxyAddress+"/", body)
    },
  },
}
err := conn.Connect()
if err == nil {
  // start using conn as any other net.Conn
}

To start the corresponding proxy server:

proxy := &enproxy.Proxy{}
err := proxy.ListenAndServe(proxyAddress)
if err != nil {
  log.Fatalf("Unable to listen and serve: %s", err)
}

Debugging

enproxy allows tracing various global metrics about connections, which can be useful when debugging issues like file descriptor leaks. To enable this tracing, just set the environment variable TRACE_CONN_STATE=true. This will cause the program to output information like the below every 5 seconds:

---- Enproxy Connections----
Open:                        34
Closing:                      0
Blocked on Closing:           0
Blocked on Read:             33
Reading:                     33
Reading Finishing:            0
Blocked on Write:             0
Writing:                     33
  Selecting:                 33
  Writing:                    0
    Write Pipe Open:          0
    Request Pending:          0
      Submitting Req.:        0
      Processing Req.:        1
        Posting Req. Fin:     0
        Posting Resp:         0       
        Dialing First:        0
        Redialing:            0
    Doing Write:              0
  Posting Response:           0
  Writing Empty:              0
  Finishing Body:             0
  Finishing:                  0
Requesting:                  33
Requesting Finishing:         0