Skip to content
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
4 changes: 2 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ func New(cfg config.Proxy, bp httputil.BufferPool, prov service.Authorizationd,
u := *r.URL
u.Scheme = scheme
u.Host = host
req, err := http.NewRequest(r.Method, u.String(), r.Body)
req, err := http.NewRequestWithContext(r.Context(), r.Method, u.String(), r.Body)
if err != nil {
glg.Error(errors.Wrap(err, "NewRequest returned error"))
glg.Error(errors.Wrap(err, "NewRequestWithContext returned error"))
r.URL.Scheme = scheme
return
}
Expand Down
18 changes: 18 additions & 0 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,24 @@ func TestNew(t *testing.T) {
}
}

func TestNew_DirectorPreservesRequestContext(t *testing.T) {
proxy := New(config.Proxy{
Host: "127.0.0.1",
Port: 8080,
}, nil, nil, nil).(*httputil.ReverseProxy)

ctx, cancel := context.WithCancel(context.Background())
req := httptest.NewRequest(http.MethodGet, "http://example.com", nil).WithContext(ctx)
proxy.Director(req)
cancel()

select {
case <-req.Context().Done():
case <-time.After(time.Second):
t.Fatal("request context was not canceled")
}
}

func Test_updateDialContext(t *testing.T) {
type args struct {
cfg *http.Transport
Expand Down
Loading