mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
fix #399, disconnect when not keep alive.
This commit is contained in:
parent
46a81372e7
commit
c17a1198cb
4 changed files with 30 additions and 0 deletions
|
@ -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();
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue