mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
Adding a unixproxy mechanism
This commit is contained in:
@@ -43,26 +43,35 @@ func New(opts map[string]interface{}) *Cli {
|
|||||||
endpoint, _ := opts["endpoint"].(string)
|
endpoint, _ := opts["endpoint"].(string)
|
||||||
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
|
url, _ := url.Parse(strings.TrimRight(endpoint, "/"))
|
||||||
|
|
||||||
transport := &http.Transport{
|
|
||||||
TLSClientConfig: &tls.Config{},
|
|
||||||
}
|
|
||||||
|
|
||||||
if project, ok := opts["project"].(string); ok {
|
if project, ok := opts["project"].(string); ok {
|
||||||
opts["project"] = strings.ToUpper(project)
|
opts["project"] = strings.ToUpper(project)
|
||||||
}
|
}
|
||||||
|
|
||||||
if insecureSkipVerify, ok := opts["insecure"].(bool); ok {
|
var ua *http.Client
|
||||||
transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify
|
if unixProxyPath, ok := opts["unixproxy"].(string); ok {
|
||||||
|
ua = &http.Client{
|
||||||
|
Jar: cookieJar,
|
||||||
|
Transport: UnixProxy(unixProxyPath),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
transport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{},
|
||||||
|
}
|
||||||
|
if insecureSkipVerify, ok := opts["insecure"].(bool); ok {
|
||||||
|
transport.TLSClientConfig.InsecureSkipVerify = insecureSkipVerify
|
||||||
|
}
|
||||||
|
|
||||||
|
ua = &http.Client{
|
||||||
|
Jar: cookieJar,
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cli := &Cli{
|
cli := &Cli{
|
||||||
endpoint: url,
|
endpoint: url,
|
||||||
opts: opts,
|
opts: opts,
|
||||||
cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
|
cookieFile: filepath.Join(homedir, ".jira.d", "cookies.js"),
|
||||||
ua: &http.Client{
|
ua: ua,
|
||||||
Jar: cookieJar,
|
|
||||||
Transport: transport,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.ua.Jar.SetCookies(url, cli.loadCookies())
|
cli.ua.Jar.SetCookies(url, cli.loadCookies())
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user