|
|
@ -905,6 +905,7 @@ int SrsHttpResponseReader::initialize(SrsFastBuffer* body)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
int ret = ERROR_SUCCESS;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nb_chunk = 0;
|
|
|
|
nb_left_chunk = 0;
|
|
|
|
nb_left_chunk = 0;
|
|
|
|
nb_total_read = 0;
|
|
|
|
nb_total_read = 0;
|
|
|
|
buffer = body;
|
|
|
|
buffer = body;
|
|
|
@ -999,9 +1000,14 @@ int SrsHttpResponseReader::read_chunked(char* data, int nb_data, int* nb_read)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// all bytes in chunk is left now.
|
|
|
|
// all bytes in chunk is left now.
|
|
|
|
nb_left_chunk = ilength;
|
|
|
|
nb_chunk = nb_left_chunk = ilength;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nb_chunk <= 0) {
|
|
|
|
|
|
|
|
// for the last chunk, eof.
|
|
|
|
|
|
|
|
is_eof = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// for not the last chunk, there must always exists bytes.
|
|
|
|
// left bytes in chunk, read some.
|
|
|
|
// left bytes in chunk, read some.
|
|
|
|
srs_assert(nb_left_chunk);
|
|
|
|
srs_assert(nb_left_chunk);
|
|
|
|
|
|
|
|
|
|
|
@ -1013,19 +1019,16 @@ int SrsHttpResponseReader::read_chunked(char* data, int nb_data, int* nb_read)
|
|
|
|
*nb_read = nb_bytes;
|
|
|
|
*nb_read = nb_bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nb_left_chunk -= nb_bytes;
|
|
|
|
nb_left_chunk -= nb_bytes;
|
|
|
|
|
|
|
|
srs_info("http: read %d bytes of chunk", nb_bytes);
|
|
|
|
|
|
|
|
|
|
|
|
// error or still left bytes in chunk, ignore and read in future.
|
|
|
|
// error or still left bytes in chunk, ignore and read in future.
|
|
|
|
if (nb_left_chunk > 0 || (ret != ERROR_SUCCESS)) {
|
|
|
|
if (nb_left_chunk > 0 || (ret != ERROR_SUCCESS)) {
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
srs_info("http: read %d bytes of chunk", nb_bytes);
|
|
|
|
srs_info("http: read total chunk %dB", nb_chunk);
|
|
|
|
|
|
|
|
|
|
|
|
// read payload when length specifies some payload.
|
|
|
|
|
|
|
|
if (nb_left_chunk <= 0) {
|
|
|
|
|
|
|
|
is_eof = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the CRLF of chunk payload end.
|
|
|
|
// for both the last or not, the CRLF of chunk payload end.
|
|
|
|
if ((ret = buffer->grow(skt, 2)) != ERROR_SUCCESS) {
|
|
|
|
if ((ret = buffer->grow(skt, 2)) != ERROR_SUCCESS) {
|
|
|
|
if (!srs_is_client_gracefully_close(ret)) {
|
|
|
|
if (!srs_is_client_gracefully_close(ret)) {
|
|
|
|
srs_error("read EOF of chunk from server failed. ret=%d", ret);
|
|
|
|
srs_error("read EOF of chunk from server failed. ret=%d", ret);
|
|
|
@ -1064,10 +1067,13 @@ int SrsHttpResponseReader::read_specified(char* data, int nb_data, int* nb_read)
|
|
|
|
// increase the total read to determine whether EOF.
|
|
|
|
// increase the total read to determine whether EOF.
|
|
|
|
nb_total_read += nb_bytes;
|
|
|
|
nb_total_read += nb_bytes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for not chunked
|
|
|
|
|
|
|
|
if (!owner->is_chunked()) {
|
|
|
|
// when read completed, eof.
|
|
|
|
// when read completed, eof.
|
|
|
|
if (nb_total_read >= (int)owner->content_length()) {
|
|
|
|
if (nb_total_read >= (int)owner->content_length()) {
|
|
|
|
is_eof = true;
|
|
|
|
is_eof = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|