forked from go-jira/jira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unixproxy.go
41 lines (34 loc) · 839 Bytes
/
unixproxy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package jiracli
import (
"fmt"
"net"
"net/http"
"os"
"time"
)
type transport struct {
shadow *http.Transport
}
func newUnixProxyTransport(path string) *transport {
dial := func(network, addr string) (net.Conn, error) {
return net.Dial("unix", path)
}
shadow := &http.Transport{
Dial: dial,
DialTLS: dial,
DisableKeepAlives: true,
ResponseHeaderTimeout: 30 * time.Second,
ExpectContinueTimeout: 10 * time.Second,
}
return &transport{shadow}
}
func unixProxy(path string) *transport {
return newUnixProxyTransport(os.ExpandEnv(path))
}
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
req2 := *req
url2 := *req.URL
req2.URL = &url2
req2.URL.Opaque = fmt.Sprintf("//%s%s", req.URL.Host, req.URL.EscapedPath())
return t.shadow.RoundTrip(&req2)
}