void test_spdylay_gzip_inflate(void) { spdylay_gzip *inflater; uint8_t in[4096], out[4096], *inptr; size_t inlen = sizeof(in); size_t inproclen, outproclen; const char *inputptr = input; inlen = deflate_data(in, inlen, (const uint8_t*)input, sizeof(input)-1); CU_ASSERT(0 == spdylay_gzip_inflate_new(&inflater)); /* First 16 bytes */ inptr = in; inproclen = inlen; outproclen = 16; CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(16 == outproclen); CU_ASSERT(inproclen > 0); CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); /* Next 32 bytes */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = 32; CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(32 == outproclen); CU_ASSERT(inproclen > 0); CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); /* Rest */ inptr += inproclen; inlen -= inproclen; inproclen = inlen; inputptr += outproclen; outproclen = sizeof(out); CU_ASSERT(0 == spdylay_gzip_inflate(inflater, out, &outproclen, inptr, &inproclen)); CU_ASSERT(sizeof(input)-49 == outproclen); CU_ASSERT(inproclen > 0); CU_ASSERT(0 == memcmp(inputptr, out, outproclen)); inlen -= inproclen; CU_ASSERT(0 == inlen); spdylay_gzip_inflate_del(inflater); }
/* * Check response is content-encoding: gzip. We need this because SPDY * client is required to support gzip. */ static void check_gzip(struct Request *req, char **nv) { int gzip = 0; size_t i; for(i = 0; nv[i]; i += 2) { if(strcmp("content-encoding", nv[i]) == 0) { gzip = strcmp("gzip", nv[i+1]) == 0; break; } } if(gzip) { int rv; if(req->inflater) { return; } rv = spdylay_gzip_inflate_new(&req->inflater); if(rv != 0) { die("Can't allocate inflate stream."); } } }