File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -72,8 +72,8 @@ struct phr_chunked_decoder {
7272 * repeatedly call the function while it returns -2 (incomplete) every time
7373 * supplying newly arrived data. If the end of the chunked-encoded data is
7474 * found, the function returns a non-negative number indicating the number of
75- * octets left undecoded at the tail of the supplied buffer. Returns -1 on
76- * error.
75+ * octets left undecoded, that starts from the offset returned by `*bufsz`.
76+ * Returns -1 on error.
7777 */
7878ssize_t phr_decode_chunked (struct phr_chunked_decoder * decoder , char * buf , size_t * bufsz );
7979
Original file line number Diff line number Diff line change @@ -437,6 +437,25 @@ static void test_chunked_consume_trailer(void)
437437 }
438438}
439439
440+ static void test_chunked_leftdata (void )
441+ {
442+ #define NEXT_REQ "GET / HTTP/1.1\r\n\r\n"
443+
444+ struct phr_chunked_decoder dec = {0 };
445+ dec .consume_trailer = 1 ;
446+ char buf [] = "5\r\nabcde\r\n0\r\n\r\n" NEXT_REQ ;
447+ size_t bufsz = sizeof (buf ) - 1 ;
448+
449+ ssize_t ret = phr_decode_chunked (& dec , buf , & bufsz );
450+ ok (ret >= 0 );
451+ ok (bufsz == 5 );
452+ ok (memcmp (buf , "abcde" , 5 ) == 0 );
453+ ok (ret == sizeof (NEXT_REQ ) - 1 );
454+ ok (memcmp (buf + bufsz , NEXT_REQ , sizeof (NEXT_REQ ) - 1 ) == 0 );
455+
456+ #undef NEXT_REQ
457+ }
458+
440459int main (void )
441460{
442461 long pagesize = sysconf (_SC_PAGESIZE );
@@ -452,6 +471,7 @@ int main(void)
452471 subtest ("headers" , test_headers );
453472 subtest ("chunked" , test_chunked );
454473 subtest ("chunked-consume-trailer" , test_chunked_consume_trailer );
474+ subtest ("chunked-leftdata" , test_chunked_leftdata );
455475
456476 munmap (inputbuf - pagesize * 2 , pagesize * 3 );
457477
You can’t perform that action at this time.
0 commit comments