MCPcopy Index your code
hub / github.com/keploy/keploy / upstreamRequestURL

Function upstreamRequestURL

pkg/agent/proxy/integrations/http/upstream_error.go:119–139  ·  view source on GitHub ↗

upstreamRequestURL extracts a best-effort URL string from a raw HTTP request buffer. Falls back to the dest-socket address if the request cannot be parsed (e.g. truncated / non-HTTP bytes). The returned string is log-only; callers must not depend on its format.

(rawReq []byte, destAddr net.Addr)

Source from the content-addressed store, hash-verified

117// cannot be parsed (e.g. truncated / non-HTTP bytes). The returned string
118// is log-only; callers must not depend on its format.
119func upstreamRequestURL(rawReq []byte, destAddr net.Addr) string {
120 if len(rawReq) > 0 {
121 req, err := nhttp.ReadRequest(bufio.NewReader(bytes.NewReader(rawReq)))
122 if err == nil && req != nil {
123 host := req.Host
124 if host == "" && destAddr != nil {
125 host = destAddr.String()
126 }
127 path := "/"
128 if req.URL != nil && req.URL.RequestURI() != "" {
129 path = req.URL.RequestURI()
130 }
131 scheme := "http"
132 return fmt.Sprintf("%s://%s%s", scheme, host, path)
133 }
134 }
135 if destAddr != nil {
136 return destAddr.String()
137 }
138 return "unknown"
139}
140
141// parseRequestMethodAndURL extracts (method, request-uri) from a raw HTTP/1.x
142// request buffer on a best-effort basis. Both return values are "" if the

Callers 1

encodeHTTPMethod · 0.85

Calls 1

StringMethod · 0.45

Tested by

no test coverage detected