@@ -178,23 +178,19 @@ func (r *proxyHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
178
178
179
179
// newRequestForProxy returns a shallow copy of the original request with a context that may include a timeout for discovery requests
180
180
func newRequestForProxy (location * url.URL , req * http.Request , enableAggregatedDiscoveryTimeout bool ) (* http.Request , context.CancelFunc ) {
181
- newCtx := context . Background ()
181
+ newCtx := req . Context ()
182
182
cancelFn := func () {}
183
183
184
- // if the original request has a deadline, we should honor that deadline for our proxied request
185
- if deadline , ok := req .Context ().Deadline (); ok {
186
- newCtx , cancelFn = context .WithDeadline (newCtx , deadline )
187
-
188
- // trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three
189
- // segments that we are going to proxy, we have a discovery request.
190
- } else if enableAggregatedDiscoveryTimeout && len (strings .Split (strings .Trim (req .URL .Path , "/" ), "/" )) == 3 {
184
+ // trim leading and trailing slashes. Then "/apis/group/version" requests are for discovery, so if we have exactly three
185
+ // segments that we are going to proxy, we have a discovery request.
186
+ if enableAggregatedDiscoveryTimeout && len (strings .Split (strings .Trim (req .URL .Path , "/" ), "/" )) == 3 {
191
187
// discovery requests are used by kubectl and others to determine which resources a server has. This is a cheap call that
192
188
// should be fast for every aggregated apiserver. Latency for aggregation is expected to be low (as for all extensions)
193
189
// so forcing a short timeout here helps responsiveness of all clients.
194
190
newCtx , cancelFn = context .WithTimeout (newCtx , aggregatedDiscoveryTimeout )
195
191
}
196
192
197
- // WithContext creates a shallow clone of the request with the new context.
193
+ // WithContext creates a shallow clone of the request with the same context.
198
194
newReq := req .WithContext (newCtx )
199
195
newReq .Header = utilnet .CloneHeader (req .Header )
200
196
newReq .URL = location
0 commit comments