MCPcopy Create free account
hub / github.com/zalando/skipper / cloneRequestForSplit

Function cloneRequestForSplit

proxy/teebody.go:40–66  ·  view source on GitHub ↗

Returns the cloned request and the tee body to be used on the main request.

(u *url.URL, req *http.Request)

Source from the content-addressed store, hash-verified

38
39// Returns the cloned request and the tee body to be used on the main request.
40func cloneRequestForSplit(u *url.URL, req *http.Request) (*http.Request, io.ReadCloser, error) {
41 h := make(http.Header)
42 for k, v := range req.Header {
43 h[k] = v
44 }
45
46 var teeBody io.ReadCloser
47 mainBody := req.Body
48
49 if req.ContentLength != 0 {
50 pr, pw := io.Pipe()
51 teeBody = pr
52 mainBody = &teeTie{mainBody, pw}
53 }
54
55 clone, err := http.NewRequest(req.Method, u.String(), teeBody)
56 if err != nil {
57 return nil, nil, err
58 }
59
60 clone.RequestURI = req.RequestURI
61 clone.Header = h
62 clone.ContentLength = req.ContentLength
63 clone.RemoteAddr = req.RemoteAddr
64
65 return clone, mainBody, nil
66}

Callers 1

SplitMethod · 0.85

Calls 1

StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…