chore: remove unnecessary code (#2754)

This commit is contained in:
chen quan 2023-01-05 22:12:07 +08:00 committed by GitHub
parent 69d355eb4b
commit 21c49009c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"net/http/httptrace"
nurl "net/url" nurl "net/url"
"strings" "strings"
@ -176,11 +175,6 @@ func request(r *http.Request, cli client) (*http.Response, error) {
respHandlers[i] = h respHandlers[i] = h
} }
clientTrace := httptrace.ContextClientTrace(ctx)
if clientTrace != nil {
ctx = httptrace.WithClientTrace(ctx, clientTrace)
}
r = r.WithContext(ctx) r = r.WithContext(ctx)
propagator.Inject(ctx, propagation.HeaderCarrier(r.Header)) propagator.Inject(ctx, propagation.HeaderCarrier(r.Header))

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"net/http/httptrace" "net/http/httptrace"
"strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -205,12 +206,14 @@ func TestDo_WithClientHttpTrace(t *testing.T) {
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})) svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
defer svr.Close() defer svr.Close()
enter := false
_, err := Do(httptrace.WithClientTrace(context.Background(), _, err := Do(httptrace.WithClientTrace(context.Background(),
&httptrace.ClientTrace{ &httptrace.ClientTrace{
DNSStart: func(info httptrace.DNSStartInfo) { GetConn: func(hostPort string) {
assert.Equal(t, "localhost", info.Host) assert.Equal(t, "127.0.0.1", strings.Split(hostPort, ":")[0])
enter = true
}, },
}), http.MethodGet, svr.URL, nil) }), http.MethodGet, svr.URL, nil)
assert.Nil(t, err) assert.Nil(t, err)
assert.True(t, enter)
} }