-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d23899
commit 5b9c0dd
Showing
2 changed files
with
60 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package jira | ||
|
||
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) | ||
} |