MCPcopy Index your code
hub / github.com/imroc/req / handleMultiPart

Function handleMultiPart

middleware.go:151–185  ·  view source on GitHub ↗
(c *Client, r *Request)

Source from the content-addressed store, hash-verified

149}
150
151func 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
187func handleFormData(r *Request) {
188 r.SetContentType(header.FormContentType)

Callers 1

parseRequestBodyFunction · 0.85

Calls 4

writeMultiPartFunction · 0.85
SetContentTypeMethod · 0.80
BytesMethod · 0.80
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…