Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: h2o/picohttpparser
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: c383cbf2f5fd148758a0bf41aa555c95a0f9cb84
Choose a base ref
..
head repository: h2o/picohttpparser
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5c4fe2c2a0cd46c8f3969f0224931f6ef4b2340c
Choose a head ref
Showing with 22 additions and 2 deletions.
  1. +2 −2 picohttpparser.h
  2. +20 −0 test.c
4 changes: 2 additions & 2 deletions picohttpparser.h
Original file line number Diff line number Diff line change
@@ -72,8 +72,8 @@ struct phr_chunked_decoder {
* repeatedly call the function while it returns -2 (incomplete) every time
* supplying newly arrived data. If the end of the chunked-encoded data is
* found, the function returns a non-negative number indicating the number of
* octets left undecoded at the tail of the supplied buffer. Returns -1 on
* error.
* octets left undecoded, that starts from the offset returned by `*bufsz`.
* Returns -1 on error.
*/
ssize_t phr_decode_chunked(struct phr_chunked_decoder *decoder, char *buf, size_t *bufsz);

20 changes: 20 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
@@ -437,6 +437,25 @@ static void test_chunked_consume_trailer(void)
}
}

static void test_chunked_leftdata(void)
{
#define NEXT_REQ "GET / HTTP/1.1\r\n\r\n"

struct phr_chunked_decoder dec = {0};
dec.consume_trailer = 1;
char buf[] = "5\r\nabcde\r\n0\r\n\r\n" NEXT_REQ;
size_t bufsz = sizeof(buf) - 1;

ssize_t ret = phr_decode_chunked(&dec, buf, &bufsz);
ok(ret >= 0);
ok(bufsz == 5);
ok(memcmp(buf, "abcde", 5) == 0);
ok(ret == sizeof(NEXT_REQ) - 1);
ok(memcmp(buf + bufsz, NEXT_REQ, sizeof(NEXT_REQ) - 1) == 0);

#undef NEXT_REQ
}

int main(void)
{
long pagesize = sysconf(_SC_PAGESIZE);
@@ -452,6 +471,7 @@ int main(void)
subtest("headers", test_headers);
subtest("chunked", test_chunked);
subtest("chunked-consume-trailer", test_chunked_consume_trailer);
subtest("chunked-leftdata", test_chunked_leftdata);

munmap(inputbuf - pagesize * 2, pagesize * 3);