This function is used for reading http reply headers.
Unified · Split
| @@ -324,13 +324,35 @@ static inline int has_header(const char *str, const char *header) · 323 unmodified lines | ||
| 324 | 324 | return av_stristart(str, header + 2, NULL) || av_stristr(str, header); |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | +static int http_read_header(URLContext *h, int *new_location) | |
| 328 | +{ | |
| 329 | + HTTPContext *s = h->priv_data; | |
| 330 | + char line[1024]; | |
| 331 | + int err = 0; | |
| 332 | + | |
| 333 | + for (;;) { | |
| 334 | + if (http_get_line(s, line, sizeof(line)) < 0) | |
| 335 | + return AVERROR(EIO); | |
| 336 | + | |
| 337 | + av_dlog(NULL, "header='%s'\n", line); | |
| 338 | + | |
| 339 | + err = process_line(h, line, s->line_count, new_location); | |
| 340 | + if (err < 0) | |
| 341 | + return err; | |
| 342 | + if (err == 0) | |
| 343 | + break; | |
| 344 | + s->line_count++; | |
| 345 | + } | |
| 346 | + | |
| 347 | + return err; | |
| 348 | +} | |
| 349 | + | |
| 327 | 350 | static int http_connect(URLContext *h, const char *path, const char *local_path, |
| 328 | 351 | const char *hoststr, const char *auth, |
| 329 | 352 | const char *proxyauth, int *new_location) |
| 330 | 353 | { |
| 331 | 354 | HTTPContext *s = h->priv_data; |
| 332 | 355 | int post, err; |
| 333 | − char line[1024]; | |
| 334 | 356 | char headers[1024] = ""; |
| 335 | 357 | char *authstr = NULL, *proxyauthstr = NULL; |
| 336 | 358 | int64_t off = s->off; |
| @@ -403,19 +425,9 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, · 66 unmodified lines | ||
| 403 | 425 | s->chunksize = -1; |
| 404 | 426 | |
| 405 | 427 | /* wait for header */ |
| 406 | − for(;;) { | |
| 407 | − if (http_get_line(s, line, sizeof(line)) < 0) | |
| 408 | − return AVERROR(EIO); | |
| 409 | − | |
| 410 | − av_dlog(NULL, "header='%s'\n", line); | |
| 411 | − | |
| 412 | − err = process_line(h, line, s->line_count, new_location); | |
| 413 | − if (err < 0) | |
| 414 | − return err; | |
| 415 | − if (err == 0) | |
| 416 | − break; | |
| 417 | − s->line_count++; | |
| 418 | − } | |
| 428 | + err = http_read_header(h, new_location); | |
| 429 | + if (err < 0) | |
| 430 | + return err; | |
| 419 | 431 | |
| 420 | 432 | return (off == s->off) ? 0 : -1; |
| 421 | 433 | } |
| @@ -603,10 +615,11 @@ static int http_proxy_open(URLContext *h, const char *uri, int flags) · 181 unmodified lines | ||
| 603 | 615 | HTTPContext *s = h->priv_data; |
| 604 | 616 | char hostname[1024], hoststr[1024]; |
| 605 | 617 | char auth[1024], pathbuf[1024], *path; |
| 606 | − char line[1024], lower_url[100]; | |
| 618 | + char lower_url[100]; | |
| 607 | 619 | int port, ret = 0, attempts = 0; |
| 608 | 620 | HTTPAuthType cur_auth_type; |
| 609 | 621 | char *authstr; |
| 622 | + int new_loc; | |
| 610 | 623 | |
| 611 | 624 | h->is_streamed = 1; |
| 612 | 625 | |
| @@ -647,30 +660,19 @@ redo: · 34 unmodified lines | ||
| 647 | 660 | s->filesize = -1; |
| 648 | 661 | cur_auth_type = s->proxy_auth_state.auth_type; |
| 649 | 662 | |
| 650 | − for (;;) { | |
| 651 | − int new_loc; | |
| 652 | − // Note: This uses buffering, potentially reading more than the | |
| 653 | − // HTTP header. If tunneling a protocol where the server starts | |
| 654 | − // the conversation, we might buffer part of that here, too. | |
| 655 | − // Reading that requires using the proper ffurl_read() function | |
| 656 | − // on this URLContext, not using the fd directly (as the tls | |
| 657 | − // protocol does). This shouldn't be an issue for tls though, | |
| 658 | − // since the client starts the conversation there, so there | |
| 659 | − // is no extra data that we might buffer up here. | |
| 660 | − if (http_get_line(s, line, sizeof(line)) < 0) { | |
| 661 | − ret = AVERROR(EIO); | |
| 662 | − goto fail; | |
| 663 | − } | |
| 664 | − | |
| 665 | − av_dlog(h, "header='%s'\n", line); | |
| 663 | + /* Note: This uses buffering, potentially reading more than the | |
| 664 | + * HTTP header. If tunneling a protocol where the server starts | |
| 665 | + * the conversation, we might buffer part of that here, too. | |
| 666 | + * Reading that requires using the proper ffurl_read() function | |
| 667 | + * on this URLContext, not using the fd directly (as the tls | |
| 668 | + * protocol does). This shouldn't be an issue for tls though, | |
| 669 | + * since the client starts the conversation there, so there | |
| 670 | + * is no extra data that we might buffer up here. | |
| 671 | + */ | |
| 672 | + ret = http_read_header(h, &new_loc); | |
| 673 | + if (ret < 0) | |
| 674 | + goto fail; | |
| 666 | 675 | |
| 667 | − ret = process_line(h, line, s->line_count, &new_loc); | |
| 668 | − if (ret < 0) | |
| 669 | − goto fail; | |
| 670 | − if (ret == 0) | |
| 671 | − break; | |
| 672 | − s->line_count++; | |
| 673 | − } | |
| 674 | 676 | attempts++; |
| 675 | 677 | if (s->http_code == 407 && |
| 676 | 678 | (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && |