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

merge from srs2

This commit is contained in:
winlin 2016-01-13 12:46:23 +08:00
commit 266397acee
4 changed files with 88 additions and 15 deletions

View file

@ -1414,8 +1414,12 @@ int SrsHttpApi::process_request(ISrsHttpResponseWriter* w, ISrsHttpMessage* r)
{
int ret = ERROR_SUCCESS;
srs_trace("HTTP %s %s, content-length=%"PRId64"",
r->method_str().c_str(), r->url().c_str(), r->content_length());
SrsHttpMessage* hm = dynamic_cast<SrsHttpMessage*>(r);
srs_assert(hm);
srs_trace("HTTP API %s %s, content-length=%"PRId64", chunked=%d/%d",
r->method_str().c_str(), r->url().c_str(), r->content_length(),
hm->is_chunked(), hm->is_infinite_chunked());
// method is OPTIONS and enable crossdomain, required crossdomain header.
if (r->is_http_options() && _srs_config->get_http_api_crossdomain()) {

View file

@ -357,15 +357,29 @@ int SrsHttpResponseReader::read(char* data, int nb_data, int* nb_read)
}
// read by specified content-length
int max = (int)owner->content_length() - (int)nb_total_read;
if (max <= 0) {
is_eof = true;
return ret;
if (owner->content_length() != -1) {
int max = (int)owner->content_length() - (int)nb_total_read;
if (max <= 0) {
is_eof = true;
return ret;
}
// change the max to read.
nb_data = srs_min(nb_data, max);
return read_specified(data, nb_data, nb_read);
}
// change the max to read.
nb_data = srs_min(nb_data, max);
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 ret;
}
int SrsHttpResponseReader::read_chunked(char* data, int nb_data, int* nb_read)
@ -505,6 +519,7 @@ SrsHttpMessage::SrsHttpMessage(ISrsProtocolReaderWriter* io, SrsConnection* c) :
{
conn = c;
chunked = false;
infinite_chunked = false;
keep_alive = true;
_uri = new SrsHttpUri();
_body = new SrsHttpResponseReader(this, io);
@ -660,6 +675,11 @@ 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();
@ -714,6 +734,25 @@ int SrsHttpMessage::parse_rest_id(string pattern)
return -1;
}
int SrsHttpMessage::enter_infinite_chunked()
{
int ret = ERROR_SUCCESS;
if (infinite_chunked) {
return ret;
}
if (is_chunked() || content_length() != -1) {
ret = ERROR_HTTP_DATA_INVALID;
srs_error("infinite chunkted not supported in specified codec. ret=%d", ret);
return ret;
}
infinite_chunked = true;
return ret;
}
int SrsHttpMessage::body_read_all(string& body)
{
int ret = ERROR_SUCCESS;

View file

@ -152,9 +152,6 @@ typedef std::pair<std::string, std::string> SrsHttpHeaderField;
// The field semantics differ slightly between client and server
// usage. In addition to the notes on the fields below, see the
// documentation for Request.Write and RoundTripper.
/**
* the http message, request or response.
*/
class SrsHttpMessage : public ISrsHttpMessage
{
private:
@ -179,6 +176,10 @@ private:
* whether the body is chunked.
*/
bool chunked;
/**
* whether the body is infinite chunked.
*/
bool infinite_chunked;
/**
* whether the request indicates should keep alive
* for the http connection.
@ -231,6 +232,11 @@ public:
* 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.
*/
@ -251,6 +257,8 @@ public:
* get the RESTful matched id.
*/
virtual int parse_rest_id(std::string pattern);
public:
virtual int enter_infinite_chunked();
public:
/**
* read body to string.