1
0
mirror of https://github.com/cloudflare/gortr.git synced 2024-05-19 06:50:10 +00:00

Merge pull request #23 from cloudflare/feature/proxy-headers

Proxy update
This commit is contained in:
lspgn
2019-07-31 15:20:57 -07:00
committed by GitHub
2 changed files with 39 additions and 2 deletions

View File

@@ -131,6 +131,17 @@ $ docker-compose -f docker-compose-pkg.yml up
You can find both files in the `dist/` directory.
### Usage with a proxy
This was tested with a basic Squid proxy. The `User-Agent` header is passed
in the CONNECT.
You have to export the following two variables in order for GoRTR to use the proxy.
```
export HTTP_PROXY=schema://host:port
export HTTPS_PROXY=schema://host:port
```
### With SSL
You can run GoRTR and listen for TLS connections only (just pass `-bind ""`).

View File

@@ -136,13 +136,39 @@ func fetchFile(file string, ua string) ([]byte, error) {
var err error
if len(file) > 8 && (file[0:7] == "http://" || file[0:8] == "https://") {
client := &http.Client{}
// Copying base of DefaultTransport from https://golang.org/src/net/http/transport.go
// There is a proposal for a Clone of
tr := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
DualStack: true,
}).DialContext,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
ProxyConnectHeader: map[string][]string{},
}
// Keep User-Agent in proxy request
tr.ProxyConnectHeader.Set("User-Agent", ua)
client := &http.Client{Transport: tr}
req, err := http.NewRequest("GET", file, nil)
req.Header.Set("User-Agent", ua)
req.Header.Set("Accept", "text/json")
proxyurl, err := http.ProxyFromEnvironment(req)
if err != nil {
return nil, err
}
proxyreq := http.ProxyURL(proxyurl)
tr.Proxy = proxyreq
if err != nil {
return nil, err
}
req.Header.Set("Accept", "text/json")
fhttp, err := client.Do(req)
if err != nil {