winlin

fix #399, disconnect when not keep alive.

@@ -1082,6 +1082,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c) @@ -1082,6 +1082,7 @@ SrsHttpMessage::SrsHttpMessage(SrsStSocket* io, SrsConnection* c)
1082 { 1082 {
1083 conn = c; 1083 conn = c;
1084 chunked = false; 1084 chunked = false;
  1085 + keep_alive = true;
1085 _uri = new SrsHttpUri(); 1086 _uri = new SrsHttpUri();
1086 _body = new SrsHttpResponseReader(this, io); 1087 _body = new SrsHttpResponseReader(this, io);
1087 _http_ts_send_buffer = new char[SRS_HTTP_TS_SEND_BUFFER_SIZE]; 1088 _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, @@ -1106,6 +1107,9 @@ int SrsHttpMessage::update(string url, http_parser* header, SrsFastBuffer* body,
1106 std::string transfer_encoding = get_request_header("Transfer-Encoding"); 1107 std::string transfer_encoding = get_request_header("Transfer-Encoding");
1107 chunked = (transfer_encoding == "chunked"); 1108 chunked = (transfer_encoding == "chunked");
1108 1109
  1110 + // whether keep alive.
  1111 + keep_alive = http_should_keep_alive(header);
  1112 +
1109 // set the buffer. 1113 // set the buffer.
1110 if ((ret = _body->initialize(body)) != ERROR_SUCCESS) { 1114 if ((ret = _body->initialize(body)) != ERROR_SUCCESS) {
1111 return ret; 1115 return ret;
@@ -1232,6 +1236,11 @@ bool SrsHttpMessage::is_chunked() @@ -1232,6 +1236,11 @@ bool SrsHttpMessage::is_chunked()
1232 return chunked; 1236 return chunked;
1233 } 1237 }
1234 1238
  1239 +bool SrsHttpMessage::is_keep_alive()
  1240 +{
  1241 + return keep_alive;
  1242 +}
  1243 +
1235 string SrsHttpMessage::uri() 1244 string SrsHttpMessage::uri()
1236 { 1245 {
1237 std::string uri = _uri->get_schema(); 1246 std::string uri = _uri->get_schema();
@@ -495,6 +495,11 @@ private: @@ -495,6 +495,11 @@ private:
495 */ 495 */
496 bool chunked; 496 bool chunked;
497 /** 497 /**
  498 + * whether the request indicates should keep alive
  499 + * for the http connection.
  500 + */
  501 + bool keep_alive;
  502 + /**
498 * uri parser 503 * uri parser
499 */ 504 */
500 SrsHttpUri* _uri; 505 SrsHttpUri* _uri;
@@ -539,6 +544,10 @@ public: @@ -539,6 +544,10 @@ public:
539 */ 544 */
540 virtual bool is_chunked(); 545 virtual bool is_chunked();
541 /** 546 /**
  547 + * whether should keep the connection alive.
  548 + */
  549 + virtual bool is_keep_alive();
  550 + /**
542 * the uri contains the host and path. 551 * the uri contains the host and path.
543 */ 552 */
544 virtual std::string uri(); 553 virtual std::string uri();
@@ -555,6 +555,12 @@ int SrsHttpApi::do_cycle() @@ -555,6 +555,12 @@ int SrsHttpApi::do_cycle()
555 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { 555 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
556 return ret; 556 return ret;
557 } 557 }
  558 +
  559 + // donot keep alive, disconnect it.
  560 + // @see https://github.com/simple-rtmp-server/srs/issues/399
  561 + if (!req->is_keep_alive()) {
  562 + break;
  563 + }
558 } 564 }
559 565
560 return ret; 566 return ret;
@@ -1412,6 +1412,12 @@ int SrsHttpConn::do_cycle() @@ -1412,6 +1412,12 @@ int SrsHttpConn::do_cycle()
1412 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) { 1412 if ((ret = process_request(&writer, req)) != ERROR_SUCCESS) {
1413 return ret; 1413 return ret;
1414 } 1414 }
  1415 +
  1416 + // donot keep alive, disconnect it.
  1417 + // @see https://github.com/simple-rtmp-server/srs/issues/399
  1418 + if (!req->is_keep_alive()) {
  1419 + break;
  1420 + }
1415 } 1421 }
1416 1422
1417 return ret; 1423 return ret;