From c17a1198cb9992198422e63c1c1eadc3b5e235d8 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 22 May 2015 16:27:48 +0800 Subject: [PATCH] fix #399, disconnect when not keep alive. --- trunk/src/app/srs_app_http.cpp | 9 +++++++++ trunk/src/app/srs_app_http.hpp | 9 +++++++++ trunk/src/app/srs_app_http_api.cpp | 6 ++++++ trunk/src/app/srs_app_http_conn.cpp | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/trunk/src/app/srs_app_http.cpp b/trunk/src/app/srs_app_http.cpp index d2d503008..ff7bf19b9 100644 --- a/trunk/src/app/srs_app_http.cpp +++ b/trunk/src/app/srs_app_http.cpp @@ -1082,6 +1082,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c) { conn = c; chunked = false; + keep_alive = true; _uri = new SrsHttpUri(); _body = new SrsHttpResponseReader(this, io); _http_ts_send_buffer = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE]; @@ -1106,6 +1107,9 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body, std::string transfer_encoding = get_request_header("Transfer-Encoding"); chunked = (transfer_encoding == "chunked"); + // whether keep alive. + keep_alive = http_should_keep_alive(header); + // set the buffer. if ((ret = _body->initialize(body)) != ERROR_SUCCESS) { return ret; @@ -1232,6 +1236,11 @@ bool SrsHttpMessage::is_chunked() return chunked; } +bool SrsHttpMessage::is_keep_alive() +{ + return keep_alive; +} + string SrsHttpMessage::uri() { std::string uri = _uri->get_schema(); diff --git a/trunk/src/app/srs_app_http.hpp b/trunk/src/app/srs_app_http.hpp index 190999b50..07b9fee08 100644 --- a/trunk/src/app/srs_app_http.hpp +++ b/trunk/src/app/srs_app_http.hpp @@ -494,6 +494,11 @@ private: * whether the body is chunked. */ bool chunked; + /** + * whether the request indicates should keep alive + * for the http connection. + */ + bool keep_alive; /** * uri parser */ @@ -538,6 +543,10 @@ public: * whether body is chunked encoding, for reader only. */ virtual bool is_chunked(); + /** + * whether should keep the connection alive. + */ + virtual bool is_keep_alive(); /** * the uri contains the host and path. */ diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 5b2f169d6..43652643d 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -555,6 +555,12 @@ int SrsHttpApi::do_cycle() if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { return ret; } + + // donot keep alive, disconnect it. + // @see https://github.com/simple-rtmp-server/srs/issues/399 + if (!req->is_keep_alive()) { + break; + } } return ret; diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp index 4350cd15d..5c99f79ef 100644 --- a/trunk/src/app/srs_app_http_conn.cpp +++ b/trunk/src/app/srs_app_http_conn.cpp @@ -1412,6 +1412,12 @@ int SrsHttpConn::do_cycle() if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { return ret; } + + // donot keep alive, disconnect it. + // @see https://github.com/simple-rtmp-server/srs/issues/399 + if (!req->is_keep_alive()) { + break; + } } return ret;