(c *Client, r *Request)
| 149 | } |
| 150 | |
| 151 | func handleMultiPart(c *Client, r *Request) (err error) { |
| 152 | var b string |
| 153 | if c.multipartBoundaryFunc != nil { |
| 154 | b = c.multipartBoundaryFunc() |
| 155 | } |
| 156 | |
| 157 | if r.forceChunkedEncoding { |
| 158 | pr, pw := io.Pipe() |
| 159 | r.GetBody = func() (io.ReadCloser, error) { |
| 160 | return pr, nil |
| 161 | } |
| 162 | w := multipart.NewWriter(pw) |
| 163 | if len(b) > 0 { |
| 164 | w.SetBoundary(b) |
| 165 | } |
| 166 | r.SetContentType(w.FormDataContentType()) |
| 167 | go func() { |
| 168 | writeMultiPart(r, w) |
| 169 | pw.Close() // close pipe writer so that pipe reader could get EOF, and stop upload |
| 170 | }() |
| 171 | } else { |
| 172 | buf := new(bytes.Buffer) |
| 173 | w := multipart.NewWriter(buf) |
| 174 | if len(b) > 0 { |
| 175 | w.SetBoundary(b) |
| 176 | } |
| 177 | writeMultiPart(r, w) |
| 178 | r.GetBody = func() (io.ReadCloser, error) { |
| 179 | return io.NopCloser(bytes.NewReader(buf.Bytes())), nil |
| 180 | } |
| 181 | r.Body = buf.Bytes() |
| 182 | r.SetContentType(w.FormDataContentType()) |
| 183 | } |
| 184 | return |
| 185 | } |
| 186 | |
| 187 | func handleFormData(r *Request) { |
| 188 | r.SetContentType(header.FormContentType) |
no test coverage detected
searching dependent graphs…