From 174a8913afe4e335441e3a8a77c91e6a4b4b718c Mon Sep 17 00:00:00 2001
From: ian <ian@virtualfunc.com>
Date: Fri, 26 Jul 2019 15:03:31 -0500
Subject: [PATCH] recognize server closing http connection
---
libavformat/http.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/libavformat/http.c b/libavformat/http.c
index 579debc..3bf2434 100644
|
a
|
b
|
int ff_http_do_new_request(URLContext *h, const char *uri)
|
| 332 | 332 | return AVERROR(EINVAL); |
| 333 | 333 | } |
| 334 | 334 | |
| | 335 | // read headers if not already loaded (this is needed to check if connection is closing) |
| | 336 | if (!s->end_header) { |
| | 337 | int new_location; |
| | 338 | http_read_header(h, &new_location); |
| | 339 | |
| | 340 | if (s->willclose) { |
| | 341 | ret = ffurl_closep(&s->hd); |
| | 342 | |
| | 343 | if (ret < 0) |
| | 344 | return ret; |
| | 345 | } |
| | 346 | } |
| | 347 | |
| 335 | 348 | if (!s->end_chunked_post) { |
| 336 | 349 | ret = http_shutdown(h, h->flags); |
| 337 | 350 | if (ret < 0) |
| 338 | 351 | return ret; |
| 339 | 352 | } |
| 340 | 353 | |
| 341 | | if (s->willclose) |
| 342 | | return AVERROR_EOF; |
| 343 | | |
| 344 | 354 | s->end_chunked_post = 0; |
| 345 | 355 | s->chunkend = 0; |
| 346 | 356 | s->off = 0; |
| … |
… |
static int process_line(URLContext *h, char *line, int line_count,
|
| 990 | 1000 | } else if (!av_strcasecmp(tag, "Proxy-Authenticate")) { |
| 991 | 1001 | ff_http_auth_handle_header(&s->proxy_auth_state, tag, p); |
| 992 | 1002 | } else if (!av_strcasecmp(tag, "Connection")) { |
| 993 | | if (!strcmp(p, "close")) |
| | 1003 | if (strstr(p, "close") != NULL) |
| 994 | 1004 | s->willclose = 1; |
| 995 | 1005 | } else if (!av_strcasecmp(tag, "Server")) { |
| 996 | 1006 | if (!av_strcasecmp(p, "AkamaiGHost")) { |
| … |
… |
static int http_shutdown(URLContext *h, int flags)
|
| 1637 | 1647 | s->hd->flags |= AVIO_FLAG_NONBLOCK; |
| 1638 | 1648 | read_ret = ffurl_read(s->hd, buf, sizeof(buf)); |
| 1639 | 1649 | s->hd->flags &= ~AVIO_FLAG_NONBLOCK; |
| | 1650 | |
| 1640 | 1651 | if (read_ret < 0 && read_ret != AVERROR(EAGAIN)) { |
| 1641 | 1652 | av_log(h, AV_LOG_ERROR, "URL read error: %s\n", av_err2str(read_ret)); |
| 1642 | 1653 | ret = read_ret; |