winlin

fix #400, parse when got entire http header, by feilong. 2.0.164.

@@ -562,6 +562,7 @@ Supported operating systems and hardware: @@ -562,6 +562,7 @@ Supported operating systems and hardware:
562 562
563 ### SRS 2.0 history 563 ### SRS 2.0 history
564 564
  565 +* v2.0, 2015-05-22, for [#400](https://github.com/simple-rtmp-server/srs/issues/400), parse when got entire http header, by feilong. 2.0.164.
565 * v2.0, 2015-05-19, merge from bravo system, add the rtmfp to bms(commercial srs). 2.0.163. 566 * v2.0, 2015-05-19, merge from bravo system, add the rtmfp to bms(commercial srs). 2.0.163.
566 * v2.0, 2015-05-10, support push flv stream over HTTP POST to SRS. 567 * v2.0, 2015-05-10, support push flv stream over HTTP POST to SRS.
567 * v2.0, 2015-04-20, support ingest hls live stream to RTMP. 568 * v2.0, 2015-04-20, support ingest hls live stream to RTMP.
@@ -1447,10 +1447,17 @@ int SrsHttpParser::parse_message_imp(SrsStSocket* skt) @@ -1447,10 +1447,17 @@ int SrsHttpParser::parse_message_imp(SrsStSocket* skt)
1447 while (true) { 1447 while (true) {
1448 ssize_t nparsed = 0; 1448 ssize_t nparsed = 0;
1449 1449
1450 - // when buffer not empty, parse it.  
1451 - if (buffer->size() > 0) { 1450 + // when got entire http header, parse it.
  1451 + // @see https://github.com/simple-rtmp-server/srs/issues/400
  1452 + char* start = buffer->bytes();
  1453 + char* end = start + buffer->size();
  1454 + for (char* p = start; p <= end - 4; p++) {
  1455 + // SRS_HTTP_CRLFCRLF "\r\n\r\n" // 0x0D0A0D0A
  1456 + if (p[0] == SRS_CONSTS_CR && p[1] == SRS_CONSTS_LF && p[2] == SRS_CONSTS_CR && p[3] == SRS_CONSTS_LF) {
1452 nparsed = http_parser_execute(&parser, &settings, buffer->bytes(), buffer->size()); 1457 nparsed = http_parser_execute(&parser, &settings, buffer->bytes(), buffer->size());
1453 srs_info("buffer=%d, nparsed=%d, header=%d", buffer->size(), (int)nparsed, header_parsed); 1458 srs_info("buffer=%d, nparsed=%d, header=%d", buffer->size(), (int)nparsed, header_parsed);
  1459 + break;
  1460 + }
1454 } 1461 }
1455 1462
1456 // consume the parsed bytes. 1463 // consume the parsed bytes.
@@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 // current release version 31 // current release version
32 #define VERSION_MAJOR 2 32 #define VERSION_MAJOR 2
33 #define VERSION_MINOR 0 33 #define VERSION_MINOR 0
34 -#define VERSION_REVISION 163 34 +#define VERSION_REVISION 164
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"