[FFmpeg-cvslog] lavf/http: Rudimentary error handling for HTTP requests received from clients.

Stephan Holljes git at videolan.org
Sat Jun 6 12:51:41 CEST 2015


ffmpeg | branch: master | Stephan Holljes <klaxa1337 at googlemail.com> | Thu Jun  4 01:20:28 2015 +0200| [8cfaa76a5e77a8cf9768a5315646647610ff49c7] | committer: Nicolas George

lavf/http: Rudimentary error handling for HTTP requests received from clients.

Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=8cfaa76a5e77a8cf9768a5315646647610ff49c7
---

 libavformat/http.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/libavformat/http.c b/libavformat/http.c
index e51f524..a5b3e29 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -299,6 +299,23 @@ int ff_http_averror(int status_code, int default_averror)
         return default_averror;
 }
 
+static void handle_http_errors(URLContext *h, int error)
+{
+    static const char bad_request[] = "HTTP/1.1 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n400 Bad Request\r\n";
+    static const char internal_server_error[] = "HTTP/1.1 500 Internal server error\r\nContent-Type: text/plain\r\n\r\n500 Internal server error\r\n";
+    HTTPContext *s = h->priv_data;
+    if (h->is_connected) {
+        switch(error) {
+            case AVERROR_HTTP_BAD_REQUEST:
+                ffurl_write(s->hd, bad_request, strlen(bad_request));
+                break;
+            default:
+                av_log(h, AV_LOG_ERROR, "Unhandled HTTP error.\n");
+                ffurl_write(s->hd, internal_server_error, strlen(internal_server_error));
+        }
+    }
+}
+
 static int http_listen(URLContext *h, const char *uri, int flags,
                        AVDictionary **options) {
     HTTPContext *s = h->priv_data;
@@ -325,6 +342,7 @@ static int http_listen(URLContext *h, const char *uri, int flags,
     return 0;
 
 fail:
+    handle_http_errors(h, ret);
     av_dict_free(&s->chained_options);
     return ret;
 }



More information about the ffmpeg-cvslog mailing list