【发布时间】:2018-07-13 09:52:47
【问题描述】:
我目前正在用 C 构建一个 HTTP 服务器。
请注意这段代码:
#define CHUNK 0x4000
z_stream strm;
unsigned char out[CHUNK];
int ret;
char buff[200];
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
int windowsBits = 15;
int GZIP_ENCODING = 16;
ret = deflateInit2(&strm, Z_BEST_SPEED, Z_DEFLATED, windowsBits | GZIP_ENCODING, 1,
Z_DEFAULT_STRATEGY);
fill(buff); //fill buff with infos
do {
strm.next_in = (z_const unsigned char *)buff;
strm.avail_in = strlen(buff);
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, Z_FINISH);
} while (strm.avail_out == 0);
send_to_client(out); //sending a part of the gzip encoded string
fill(buff);
}while(strlen(buff)!=0);
这个想法是:我正在尝试一个一个地发送 gzip'ed 缓冲区,这(当它们被连接时)是一个整体请求。
但是:目前,我的客户端(浏览器)只获取第一个缓冲区的信息。不过完全没有错误。
我如何完成这项工作,如何在循环中压缩一些缓冲区,以便我可以每次(在循环中)发送它们?
【问题讨论】:
标签: c http compression gzip zlib