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 | return av_stristart(str, header + 2, NULL) || av_stristr(str, header); | 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 | static int http_connect(URLContext *h, const char *path, const char *local_path, | 350 | static int http_connect(URLContext *h, const char *path, const char *local_path, |
| 328 | const char *hoststr, const char *auth, | 351 | const char *hoststr, const char *auth, |
| 329 | const char *proxyauth, int *new_location) | 352 | const char *proxyauth, int *new_location) |
| 330 | { | 353 | { |
| 331 | HTTPContext *s = h->priv_data; | 354 | HTTPContext *s = h->priv_data; |
| 332 | int post, err; | 355 | int post, err; |
| 333 | char line[1024]; | ||
| 334 | char headers[1024] = ""; | 356 | char headers[1024] = ""; |
| 335 | char *authstr = NULL, *proxyauthstr = NULL; | 357 | char *authstr = NULL, *proxyauthstr = NULL; |
| 336 | int64_t off = s->off; | 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 | s->chunksize = -1; | 425 | s->chunksize = -1; |
| 404 | 426 | ||
| 405 | /* wait for header */ | 427 | /* wait for header */ |
| 406 | for(;;) { | 428 | err = http_read_header(h, new_location); |
| 407 | if (http_get_line(s, line, sizeof(line)) < 0) | 429 | if (err < 0) |
| 408 | return AVERROR(EIO); | 430 | return err; |
| 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 | } | ||
| 419 | 431 | ||
| 420 | return (off == s->off) ? 0 : -1; | 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 | HTTPContext *s = h->priv_data; | 615 | HTTPContext *s = h->priv_data; |
| 604 | char hostname[1024], hoststr[1024]; | 616 | char hostname[1024], hoststr[1024]; |
| 605 | char auth[1024], pathbuf[1024], *path; | 617 | char auth[1024], pathbuf[1024], *path; |
| 606 | char line[1024], lower_url[100]; | 618 | char lower_url[100]; |
| 607 | int port, ret = 0, attempts = 0; | 619 | int port, ret = 0, attempts = 0; |
| 608 | HTTPAuthType cur_auth_type; | 620 | HTTPAuthType cur_auth_type; |
| 609 | char *authstr; | 621 | char *authstr; |
| 622 | int new_loc; | ||
| 610 | 623 | ||
| 611 | h->is_streamed = 1; | 624 | h->is_streamed = 1; |
| 612 | 625 | ||
| @@ -647,30 +660,19 @@ redo: · 34 unmodified lines | |||
| 647 | s->filesize = -1; | 660 | s->filesize = -1; |
| 648 | cur_auth_type = s->proxy_auth_state.auth_type; | 661 | cur_auth_type = s->proxy_auth_state.auth_type; |
| 649 | 662 | ||
| 650 | for (;;) { | 663 | /* Note: This uses buffering, potentially reading more than the |
| 651 | int new_loc; | 664 | * HTTP header. If tunneling a protocol where the server starts |
| 652 | // Note: This uses buffering, potentially reading more than the | 665 | * the conversation, we might buffer part of that here, too. |
| 653 | // HTTP header. If tunneling a protocol where the server starts | 666 | * Reading that requires using the proper ffurl_read() function |
| 654 | // the conversation, we might buffer part of that here, too. | 667 | * on this URLContext, not using the fd directly (as the tls |
| 655 | // Reading that requires using the proper ffurl_read() function | 668 | * protocol does). This shouldn't be an issue for tls though, |
| 656 | // on this URLContext, not using the fd directly (as the tls | 669 | * since the client starts the conversation there, so there |
| 657 | // protocol does). This shouldn't be an issue for tls though, | 670 | * is no extra data that we might buffer up here. |
| 658 | // since the client starts the conversation there, so there | 671 | */ |
| 659 | // is no extra data that we might buffer up here. | 672 | ret = http_read_header(h, &new_loc); |
| 660 | if (http_get_line(s, line, sizeof(line)) < 0) { | 673 | if (ret < 0) |
| 661 | ret = AVERROR(EIO); | 674 | goto fail; |
| 662 | goto fail; | ||
| 663 | } | ||
| 664 | |||
| 665 | av_dlog(h, "header='%s'\n", line); | ||
| 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 | attempts++; | 676 | attempts++; |
| 675 | if (s->http_code == 407 && | 677 | if (s->http_code == 407 && |
| 676 | (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && | 678 | (cur_auth_type == HTTP_AUTH_NONE || s->proxy_auth_state.stale) && |