handle206Response reads a 206 response and send each part as a separate ReadCloser to the streams chan.
(streams chan io.ReadCloser, errs chan error, body io.ReadCloser, chunks []private.ImageSourceChunk, mediaType string, params map[string]string)
| 313 | |
| 314 | // handle206Response reads a 206 response and send each part as a separate ReadCloser to the streams chan. |
| 315 | func handle206Response(streams chan io.ReadCloser, errs chan error, body io.ReadCloser, chunks []private.ImageSourceChunk, mediaType string, params map[string]string) { |
| 316 | defer close(streams) |
| 317 | defer close(errs) |
| 318 | if !strings.HasPrefix(mediaType, "multipart/") { |
| 319 | streams <- body |
| 320 | return |
| 321 | } |
| 322 | boundary, found := params["boundary"] |
| 323 | if !found { |
| 324 | errs <- errors.New("could not find boundary") |
| 325 | body.Close() |
| 326 | return |
| 327 | } |
| 328 | buffered := makeBufferedNetworkReader(body, 64, 16384) |
| 329 | defer buffered.Close() |
| 330 | mr := multipart.NewReader(buffered, boundary) |
| 331 | parts := 0 |
| 332 | for { |
| 333 | p, err := mr.NextPart() |
| 334 | if err != nil { |
| 335 | if err != io.EOF { |
| 336 | errs <- err |
| 337 | } |
| 338 | if parts != len(chunks) { |
| 339 | errs <- errors.New("invalid number of chunks returned by the server") |
| 340 | } |
| 341 | return |
| 342 | } |
| 343 | if parts >= len(chunks) { |
| 344 | errs <- errors.New("too many parts returned by the server") |
| 345 | break |
| 346 | } |
| 347 | s := signalCloseReader{ |
| 348 | closed: make(chan struct{}), |
| 349 | stream: p, |
| 350 | } |
| 351 | streams <- s |
| 352 | // NextPart() cannot be called while the current part |
| 353 | // is being read, so wait until it is closed |
| 354 | <-s.closed |
| 355 | parts++ |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | var multipartByteRangesRe = regexp.Delayed("multipart/byteranges; boundary=([A-Za-z-0-9:]+)") |
| 360 |
searching dependent graphs…