Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing linting changes #596

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Adding a header to each request
return r, nil
})

# Note that the function is called before the proxy sends the request to the server
> Note that the function is called before the proxy sends the request to the server

For printing the content type of all incoming responses

Expand Down
5 changes: 2 additions & 3 deletions internal/signer/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"net"
"runtime"
"sort"
"strings"
"time"
)

Expand All @@ -25,9 +26,7 @@ func hashSorted(lst []string) []byte {
copy(c, lst)
sort.Strings(c)
h := sha256.New()
for _, s := range c {
h.Write([]byte(s + ","))
}
h.Write([]byte(strings.Join(c, ",")))
return h.Sum(nil)
}

Expand Down
18 changes: 11 additions & 7 deletions proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,16 @@ func TestGoproxyHijackConnect(t *testing.T) {
proxy.OnRequest(goproxy.ReqHostIs(srv.Listener.Addr().String())).
HijackConnect(func(req *http.Request, client net.Conn, ctx *goproxy.ProxyCtx) {
t.Logf("URL %+#v\nSTR %s", req.URL, req.URL.String())
req.URL.Scheme = "http"
req.URL.Path = "/bobo"
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, req.URL.String(), nil)
getReq, err := http.NewRequestWithContext(req.Context(), http.MethodGet, (&url.URL{
Scheme: "http",
Host: req.URL.Host,
Path: "/bobo",
}).String(), nil)
if err != nil {
t.Fatal("Cannot create request", err)
}
resp, err := http.DefaultClient.Do(req)
httpClient := &http.Client{}
resp, err := httpClient.Do(getReq)
panicOnErr(err, "http.Get(CONNECT url)")
panicOnErr(resp.Write(client), "resp.Write(client)")
_ = resp.Body.Close()
Expand Down Expand Up @@ -644,7 +647,7 @@ func TestSelfRequest(t *testing.T) {
proxy := goproxy.NewProxyHttpServer()
_, l := oneShotProxy(proxy)
defer l.Close()
if !strings.Contains(string(getOrFail(t, l.URL, http.DefaultClient)), "non-proxy") {
if !strings.Contains(string(getOrFail(t, l.URL, &http.Client{})), "non-proxy") {
t.Fatal("non proxy requests should fail")
}
}
Expand Down Expand Up @@ -898,13 +901,14 @@ func TestResponseContentLength(t *testing.T) {
defer proxySrv.Close()

// send request
http.DefaultClient.Transport = &http.Transport{
client := &http.Client{}
client.Transport = &http.Transport{
Proxy: func(req *http.Request) (*url.URL, error) {
return url.Parse(proxySrv.URL)
},
}
req, _ := http.NewRequestWithContext(context.Background(), http.MethodGet, srv.URL, nil)
resp, _ := http.DefaultClient.Do(req)
resp, _ := client.Do(req)

body, _ := io.ReadAll(resp.Body)
_ = resp.Body.Close()
Expand Down
Loading