MCPcopy Index your code
hub / github.com/zalando/skipper / mapRequest

Method mapRequest

proxy/proxy.go:660–724  ·  view source on GitHub ↗

creates an outgoing http request to be forwarded to the route endpoint based on the augmented incoming request

(ctx *context, requestContext stdlibcontext.Context)

Source from the content-addressed store, hash-verified

658// creates an outgoing http request to be forwarded to the route endpoint
659// based on the augmented incoming request
660func (p *Proxy) mapRequest(ctx *context, requestContext stdlibcontext.Context) (*http.Request, routing.Metrics, error) {
661 var endpointMetrics routing.Metrics
662 r := ctx.request
663 rt := ctx.route
664 host := ctx.outgoingHost
665 stateBag := ctx.StateBag()
666 u := r.URL
667
668 switch rt.BackendType {
669 case eskip.DynamicBackend:
670 setRequestURLFromRequest(u, r)
671 setRequestURLForDynamicBackend(u, stateBag)
672 case eskip.LBBackend:
673 endpoint := p.selectEndpoint(ctx)
674 endpointMetrics = endpoint.Metrics
675 u.Scheme = endpoint.Scheme
676 u.Host = endpoint.Host
677 case eskip.NetworkBackend:
678 endpointMetrics = p.registry.GetMetrics(rt.Host)
679 fallthrough
680 default:
681 u.Scheme = rt.Scheme
682 u.Host = rt.Host
683 }
684
685 body := r.Body
686 if r.ContentLength == 0 {
687 body = nil
688 }
689
690 rr, err := http.NewRequestWithContext(requestContext, r.Method, u.String(), body)
691 if err != nil {
692 return nil, nil, err
693 }
694
695 rr.ContentLength = r.ContentLength
696 if p.flags.HopHeadersRemoval() {
697 rr.Header = cloneHeaderExcluding(r.Header, hopHeaders)
698 } else {
699 rr.Header = cloneHeader(r.Header)
700 }
701 // Disable default net/http user agent when user agent is not specified
702 if _, ok := rr.Header["User-Agent"]; !ok {
703 rr.Header["User-Agent"] = []string{""}
704 }
705 rr.Host = host
706
707 // If there is basic auth configured in the URL we add them as headers
708 if u.User != nil {
709 up := u.User.String()
710 upBase64 := base64.StdEncoding.EncodeToString([]byte(up))
711 rr.Header.Add("Authorization", fmt.Sprintf("Basic %s", upBase64))
712 }
713
714 ctxspan := ot.SpanFromContext(r.Context())
715 if ctxspan != nil {
716 rr = rr.WithContext(ot.ContextWithSpan(rr.Context(), ctxspan))
717 }

Callers 2

makeBackendRequestMethod · 0.95
doMethod · 0.95

Calls 12

selectEndpointMethod · 0.95
setRequestURLFromRequestFunction · 0.85
cloneHeaderExcludingFunction · 0.85
cloneHeaderFunction · 0.85
forwardToProxyFunction · 0.85
GetMetricsMethod · 0.80
HopHeadersRemovalMethod · 0.80
ContextMethod · 0.80
StateBagMethod · 0.65
StringMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected