(c *Client, r *Response)
| 408 | } |
| 409 | |
| 410 | func handleDownload(c *Client, r *Response) (err error) { |
| 411 | if r.Response == nil || !r.Request.isSaveResponse { |
| 412 | return nil |
| 413 | } |
| 414 | var body io.ReadCloser |
| 415 | |
| 416 | if r.body != nil { // already read |
| 417 | body = io.NopCloser(bytes.NewReader(r.body)) |
| 418 | } else { |
| 419 | body = r.Body |
| 420 | } |
| 421 | |
| 422 | var output io.Writer |
| 423 | if r.Request.outputFile != "" { |
| 424 | file := r.Request.outputFile |
| 425 | if c.outputDirectory != "" && !filepath.IsAbs(file) { |
| 426 | file = c.outputDirectory + string(filepath.Separator) + file |
| 427 | } |
| 428 | |
| 429 | file = filepath.Clean(file) |
| 430 | |
| 431 | if err = util.CreateDirectory(filepath.Dir(file)); err != nil { |
| 432 | return err |
| 433 | } |
| 434 | output, err = os.Create(file) |
| 435 | if err != nil { |
| 436 | return |
| 437 | } |
| 438 | } else { |
| 439 | output = r.Request.output // must not nil |
| 440 | } |
| 441 | |
| 442 | defer func() { |
| 443 | body.Close() |
| 444 | closeq(output) |
| 445 | }() |
| 446 | |
| 447 | _, err = io.Copy(output, body) |
| 448 | r.setReceivedAt() |
| 449 | return |
| 450 | } |
| 451 | |
| 452 | // generate URL |
| 453 | func parseRequestURL(c *Client, r *Request) error { |
nothing calls this directly
no test coverage detected
searching dependent graphs…