1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

HTTP: Enable infinite_chunked by default

This commit is contained in:
winlin 2020-06-30 19:29:23 +08:00
parent 9e447e541b
commit a273298e63
5 changed files with 75 additions and 100 deletions

View file

@ -449,15 +449,11 @@ public:
//
// There are some modes to determine the length of body:
// 1. content-length and chunked.
// 2. user confirmed infinite chunked.
// 3. no body or user not confirmed infinite chunked.
// 2. infinite chunked.
// 3. no body.
// For example:
// ISrsHttpMessage* r = ...;
// while (!r->eof()) r->read(); // Read in mode 1 or 3.
// For some server, we can confirm the body is infinite chunked:
// ISrsHttpMessage* r = ...;
// r->enter_infinite_chunked();
// while (!r->eof()) r->read(); // Read in mode 2
// @rmark for mode 2, the infinite chunked, all left data is body.
class ISrsHttpMessage
{
@ -492,10 +488,6 @@ public:
// @return the REST id; -1 if not matched.
virtual std::string parse_rest_id(std::string pattern) = 0;
public:
// The left all data is chunked body, the infinite chunked mode,
// which is chunked encoding without chunked header.
// @remark error when message is in chunked or content-length specified.
virtual srs_error_t enter_infinite_chunked() = 0;
// Read body to string.
// @remark for small http body.
virtual srs_error_t body_read_all(std::string& body) = 0;

View file

@ -291,7 +291,6 @@ SrsHttpMessage::SrsHttpMessage(ISrsReader* reader, SrsFastStream* buffer) : ISrs
{
owner_conn = NULL;
chunked = false;
infinite_chunked = false;
_uri = new SrsHttpUri();
_body = new SrsHttpResponseReader(this, reader, buffer);
@ -476,11 +475,6 @@ bool SrsHttpMessage::is_keep_alive()
return _keep_alive;
}
bool SrsHttpMessage::is_infinite_chunked()
{
return infinite_chunked;
}
string SrsHttpMessage::uri()
{
std::string uri = _uri->get_schema();
@ -550,23 +544,6 @@ std::string SrsHttpMessage::parse_rest_id(string pattern)
return "";
}
srs_error_t SrsHttpMessage::enter_infinite_chunked()
{
srs_error_t err = srs_success;
if (infinite_chunked) {
return err;
}
if (is_chunked() || content_length() != -1) {
return srs_error_new(ERROR_HTTP_DATA_INVALID, "not infinited chunked");
}
infinite_chunked = true;
return err;
}
srs_error_t SrsHttpMessage::body_read_all(string& body)
{
srs_error_t err = srs_success;
@ -975,17 +952,10 @@ srs_error_t SrsHttpResponseReader::read(void* data, size_t nb_data, ssize_t* nb_
return read_specified(data, nb_data, nb_read);
}
// infinite chunked mode, directly read.
if (owner->is_infinite_chunked()) {
srs_assert(!owner->is_chunked() && owner->content_length() == -1);
return read_specified(data, nb_data, nb_read);
}
// infinite chunked mode, but user not set it,
// we think there is no data left.
is_eof = true;
return err;
// Infinite chunked mode.
// If not chunked encoding, and no content-length, it's infinite chunked.
// In this mode, all body is data and never EOF util socket closed.
return read_specified(data, nb_data, nb_read);
}
srs_error_t SrsHttpResponseReader::read_chunked(void* data, size_t nb_data, ssize_t* nb_read)

View file

@ -99,8 +99,6 @@ private:
// The body object, reader object.
// @remark, user can get body in string by get_body().
SrsHttpResponseReader* _body;
// Whether the body is infinite chunked.
bool infinite_chunked;
// Use a buffer to read and send ts file.
// The transport connection, can be NULL.
ISrsConnection* owner_conn;
@ -157,9 +155,6 @@ public:
virtual bool is_http_options();
// Whether body is chunked encoding, for reader only.
virtual bool is_chunked();
// Whether body is infinite chunked encoding.
// @remark set by enter_infinite_chunked.
virtual bool is_infinite_chunked();
// Whether should keep the connection alive.
virtual bool is_keep_alive();
// The uri contains the host and path.
@ -173,8 +168,6 @@ public:
virtual std::string ext();
// Get the RESTful matched id.
virtual std::string parse_rest_id(std::string pattern);
public:
virtual srs_error_t enter_infinite_chunked();
public:
// Read body to string.
// @remark for small http body.