winlin

fix #399, disconnect when not keep alive.

... ... @@ -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();
... ...
... ... @@ -495,6 +495,11 @@ private:
*/
bool chunked;
/**
* whether the request indicates should keep alive
* for the http connection.
*/
bool keep_alive;
/**
* uri parser
*/
SrsHttpUri* _uri;
... ... @@ -539,6 +544,10 @@ public:
*/
virtual bool is_chunked();
/**
* whether should keep the connection alive.
*/
virtual bool is_keep_alive();
/**
* the uri contains the host and path.
*/
virtual std::string uri();
... ...
... ... @@ -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;
... ...
... ... @@ -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;
... ...