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

Method PostFile

modules/caddyhttp/reverseproxy/fastcgi/client.go:323–360  ·  view source on GitHub ↗

PostFile issues a POST to the fcgi responder in multipart(RFC 2046) standard, with form as a string key to a list values (url.Values), and/or with file as a string key to a list file path.

(p map[string]string, data url.Values, file map[string]string)

Source from the content-addressed store, hash-verified

321// with form as a string key to a list values (url.Values),
322// and/or with file as a string key to a list file path.
323func (c *client) PostFile(p map[string]string, data url.Values, file map[string]string) (resp *http.Response, err error) {
324 buf := &bytes.Buffer{}
325 writer := multipart.NewWriter(buf)
326 bodyType := writer.FormDataContentType()
327
328 for key, val := range data {
329 for _, v0 := range val {
330 err = writer.WriteField(key, v0)
331 if err != nil {
332 return resp, err
333 }
334 }
335 }
336
337 for key, val := range file {
338 fd, e := os.Open(val)
339 if e != nil {
340 return nil, e
341 }
342 defer fd.Close()
343
344 part, e := writer.CreateFormFile(key, filepath.Base(val))
345 if e != nil {
346 return nil, e
347 }
348 _, err = io.Copy(part, fd)
349 if err != nil {
350 return resp, err
351 }
352 }
353
354 err = writer.Close()
355 if err != nil {
356 return resp, err
357 }
358
359 return c.Post(p, "POST", bodyType, buf, int64(buf.Len()))
360}
361
362// SetReadTimeout sets the read timeout for future calls that read from the
363// fcgi responder. A zero value for t means no timeout will be set.

Callers 1

sendFcgiFunction · 0.95

Calls 4

PostMethod · 0.95
OpenMethod · 0.80
CloseMethod · 0.45
LenMethod · 0.45

Tested by 1

sendFcgiFunction · 0.76