Request returns an HTTP response with header and body from the FastCGI responder.
(p map[string]string, req io.Reader)
| 211 | // Request returns an HTTP response with header and body |
| 212 | // from the FastCGI responder. |
| 213 | func (c *client) Request(p map[string]string, req io.Reader) (resp *http.Response, err error) { |
| 214 | r, err := c.Do(p, req) |
| 215 | if err != nil { |
| 216 | return resp, err |
| 217 | } |
| 218 | |
| 219 | rb := bufio.NewReader(r) |
| 220 | tp := textproto.NewReader(rb) |
| 221 | resp = new(http.Response) |
| 222 | |
| 223 | // Parse the response headers. |
| 224 | mimeHeader, err := tp.ReadMIMEHeader() |
| 225 | if err != nil && err != io.EOF { |
| 226 | return resp, err |
| 227 | } |
| 228 | resp.Header = http.Header(mimeHeader) |
| 229 | |
| 230 | if resp.Header.Get("Status") != "" { |
| 231 | statusNumber, statusInfo, statusIsCut := strings.Cut(resp.Header.Get("Status"), " ") |
| 232 | resp.StatusCode, err = strconv.Atoi(statusNumber) |
| 233 | if err != nil { |
| 234 | return resp, err |
| 235 | } |
| 236 | if statusIsCut { |
| 237 | resp.Status = statusInfo |
| 238 | } |
| 239 | } else { |
| 240 | resp.StatusCode = http.StatusOK |
| 241 | } |
| 242 | |
| 243 | // TODO: fixTransferEncoding ? |
| 244 | resp.TransferEncoding = resp.Header["Transfer-Encoding"] |
| 245 | resp.ContentLength, _ = strconv.ParseInt(resp.Header.Get("Content-Length"), 10, 64) |
| 246 | |
| 247 | // wrap the response body in our closer |
| 248 | closer := clientCloser{ |
| 249 | rwc: c.rwc, |
| 250 | r: r.(*streamReader), |
| 251 | Reader: rb, |
| 252 | status: resp.StatusCode, |
| 253 | logger: noopLogger, |
| 254 | } |
| 255 | if chunked(resp.TransferEncoding) { |
| 256 | closer.Reader = httputil.NewChunkedReader(rb) |
| 257 | } |
| 258 | if c.stderr { |
| 259 | closer.logger = c.logger |
| 260 | } |
| 261 | resp.Body = closer |
| 262 | |
| 263 | return resp, err |
| 264 | } |
| 265 | |
| 266 | // Get issues a GET request to the fcgi responder. |
| 267 | func (c *client) Get(p map[string]string, body io.Reader, l int64) (resp *http.Response, err error) { |