(ctx *context, requestContext stdlibcontext.Context)
| 1052 | } |
| 1053 | |
| 1054 | func (p *Proxy) makeBackendRequest(ctx *context, requestContext stdlibcontext.Context) (*http.Response, *proxyError) { |
| 1055 | requestStopWatch, responseStopWatch := newStopWatch(), newStopWatch() |
| 1056 | requestStopWatch.Start() |
| 1057 | |
| 1058 | defer func() { |
| 1059 | requestStopWatch.Stop() |
| 1060 | responseStopWatch.Stop() |
| 1061 | ctx.proxyRequestElapsed = requestStopWatch.Elapsed() |
| 1062 | ctx.proxyResponseElapsed = responseStopWatch.Elapsed() |
| 1063 | }() |
| 1064 | |
| 1065 | payloadProtocol := getUpgradeRequest(ctx.Request()) |
| 1066 | |
| 1067 | req, endpointMetrics, err := p.mapRequest(ctx, requestContext) |
| 1068 | if err != nil { |
| 1069 | return nil, &proxyError{err: fmt.Errorf("could not map backend request: %w", err)} |
| 1070 | } |
| 1071 | |
| 1072 | if res, ok := p.rejectBackend(ctx, req); ok { |
| 1073 | return res, nil |
| 1074 | } |
| 1075 | |
| 1076 | if endpointMetrics != nil { |
| 1077 | endpointMetrics.IncInflightRequest() |
| 1078 | defer endpointMetrics.DecInflightRequest() |
| 1079 | } |
| 1080 | |
| 1081 | if p.experimentalUpgrade && payloadProtocol != "" { |
| 1082 | // see also https://github.com/golang/go/blob/9159cd4ec6b0e9475dc9c71c830035c1c4c13483/src/net/http/httputil/reverseproxy.go#L423-L428 |
| 1083 | req.Header.Set("Connection", "Upgrade") |
| 1084 | req.Header.Set("Upgrade", payloadProtocol) |
| 1085 | p.makeUpgradeRequest(ctx, req) |
| 1086 | |
| 1087 | // We are not owner of the connection anymore. |
| 1088 | return nil, &proxyError{handled: true} |
| 1089 | } |
| 1090 | |
| 1091 | roundTripper, err := p.getRoundTripper(ctx, req) |
| 1092 | if err != nil { |
| 1093 | return nil, &proxyError{err: fmt.Errorf("failed to get roundtripper: %w", err), code: http.StatusBadGateway} |
| 1094 | } |
| 1095 | |
| 1096 | bag := ctx.StateBag() |
| 1097 | spanName, ok := bag[tracingfilter.OpenTracingProxySpanKey].(string) |
| 1098 | if !ok { |
| 1099 | spanName = "proxy" |
| 1100 | } |
| 1101 | |
| 1102 | proxySpanOpts := []ot.StartSpanOption{ot.Tags{ |
| 1103 | SpanKindTag: SpanKindClient, |
| 1104 | }} |
| 1105 | if parentSpan := ot.SpanFromContext(req.Context()); parentSpan != nil { |
| 1106 | proxySpanOpts = append(proxySpanOpts, ot.ChildOf(parentSpan.Context())) |
| 1107 | } |
| 1108 | ctx.proxySpan = p.tracing.tracer.StartSpan(spanName, proxySpanOpts...) |
| 1109 | |
| 1110 | u := cloneURL(req.URL) |
| 1111 | u.RawQuery = "" |
no test coverage detected