MCPcopy
hub / github.com/caddyserver/caddy / Do

Method Do

modules/caddyhttp/reverseproxy/fastcgi/client.go:140–180  ·  modules/caddyhttp/reverseproxy/fastcgi/client.go::client.Do

Do makes the request and returns an io.Reader that translates the data read from the FastCGI responder out of FastCGI packets before returning it.

(p map[string]string, req io.Reader)

Source from the content-addressed store, hash-verified

138// Do makes the request and returns an io.Reader that translates the data read
139// from the FastCGI responder out of FastCGI packets before returning it.
140func (c *client) Do(p map[string]string, req io.Reader) (r io.Reader, err error) {
141 // check for CONTENT_LENGTH, since the lack of it or wrong value will cause the backend to hang
142 if clStr, ok := p["CONTENT_LENGTH"]; !ok {
143 return nil, caddyhttp.Error(http.StatusLengthRequired, nil)
144 } else if _, err := strconv.ParseUint(clStr, 10, 64); err != nil {
145 // stdlib won't return a negative Content-Length, but we check just in case,
146 // the most likely cause is from a missing content length, which is -1
147 return nil, caddyhttp.Error(http.StatusLengthRequired, err)
148 }
149
150 writer := &streamWriter{c: c}
151 writer.buf = bufPool.Get().(*bytes.Buffer)
152 writer.buf.Reset()
153 defer bufPool.Put(writer.buf)
154
155 err = writer.writeBeginRequest(uint16(Responder), 0)
156 if err != nil {
157 return r, err
158 }
159
160 writer.recType = Params
161 err = writer.writePairs(p)
162 if err != nil {
163 return r, err
164 }
165
166 writer.recType = Stdin
167 if req != nil {
168 _, err = io.Copy(writer, req)
169 if err != nil {
170 return nil, err
171 }
172 }
173 err = writer.FlushStream()
174 if err != nil {
175 return nil, err
176 }
177
178 r = &streamReader{c: c}
179 return r, err
180}
181
182// clientCloser is an io.ReadCloser. It wraps an io.Reader with a Closer
183// that closes the client connection.

Callers 15

RequestMethod · 0.95
GetCertificateMethod · 0.80
ProvisionMethod · 0.80
initReverseProxyMetricsFunction · 0.80
fillDynamicHostMethod · 0.80
doActiveHealthCheckMethod · 0.80
correctPasswordMethod · 0.80
AdminAPIRequestFunction · 0.80
initServerMethod · 0.80

Calls 6

writeBeginRequestMethod · 0.95
writePairsMethod · 0.95
FlushStreamMethod · 0.95
ErrorFunction · 0.92
GetMethod · 0.65
ResetMethod · 0.65

Tested by 2

TestLargeHttpRequestFunction · 0.64