http: 支持 Content-Encoding: gzip
2015-08-24 19:42
711 查看
curl -v --compressed http://localhost:8080/upload/a.out -o a.out
请求:
Accept-Encoding: gzip, deflate
响应:
Content-Encoding: gzip
gzip -9c xx.txt > xx.gz
开头是标记0x1f,0x8b,然后0x08表示使用deflate,前10个字节通常为:
1f 8b 08 00 00 00 00 00 00 03
中间是deflate的raw data
最后的8个字节是crc32和原始长度。
deflate 开头两个字节是0x78,0x9c, 参考文件[1]就是这种格式,
我写成gzip, curl可以收,但是chrome报错。
调用zlib,生成数据的差异只是在deflateInit(inflate)和deflateInit2(gzip)[2],其他相同。这点害的我调试了好久。
调试发现chsum 的crc根本对不上,下面的/bin/crc32和*.gz对得上:
[1] http://www.zlib.net/zpipe.c [2] http://lxr.free-electrons.com/source/include/linux/zlib.h
请求:
Accept-Encoding: gzip, deflate
响应:
Content-Encoding: gzip
gzip -9c xx.txt > xx.gz
开头是标记0x1f,0x8b,然后0x08表示使用deflate,前10个字节通常为:
1f 8b 08 00 00 00 00 00 00 03
中间是deflate的raw data
最后的8个字节是crc32和原始长度。
deflate 开头两个字节是0x78,0x9c, 参考文件[1]就是这种格式,
我写成gzip, curl可以收,但是chrome报错。
调用zlib,生成数据的差异只是在deflateInit(inflate)和deflateInit2(gzip)[2],其他相同。这点害的我调试了好久。
调试发现chsum 的crc根本对不上,下面的/bin/crc32和*.gz对得上:
#!/usr/bin/perl -w eval 'exec /usr/bin/perl -w -S $0 ${1+"$@"}' if 0; # not running under some shell # computes and prints to stdout the CRC-32 values of the given files use lib qw( blib/lib lib ); use Archive::Zip; use FileHandle; my $totalFiles = scalar(@ARGV); foreach my $file (@ARGV) { if ( -d $file ) { warn "$0: ${file}: Is a directory\n"; next; } my $fh = FileHandle->new(); if ( !$fh->open( $file, 'r' ) ) { warn "$0: $!\n"; next; } binmode($fh); my $buffer; my $bytesRead; my $crc = 0; while ( $bytesRead = $fh->read( $buffer, 32768 ) ) { $crc = Archive::Zip::computeCRC32( $buffer, $crc ); } printf( "%08x", $crc ); print("\t$file") if ( $totalFiles > 1 ); print("\n"); }
[1] http://www.zlib.net/zpipe.c [2] http://lxr.free-electrons.com/source/include/linux/zlib.h
相关文章推荐
- java要看的书(转http://www.cnblogs.com/lanhj/category/534902.html)
- iOS开发——网络篇——NSURLSession,下载、上传代理方法,利用NSURLSession断点下载,AFN基本使用,网络检测,NSURLConnection补充
- http的状态响应码
- 网络爬虫:采用“负载均衡”策略来优化网络爬虫
- 网络爬虫:采用“负载均衡”策略来优化网络爬虫
- HTTP Status 500 - Unable to instantiate Action
- 图表控件TeeChart干货分享(绘制2D、3D实时曲线---VC++示例源代码--网络首发)
- 如何使Fiddler能捕获LoadRunner的http请求
- TCP 3次握手模式(3-WAY HANDSHAKE)
- android网络编程所涉及到的知识
- 黑马程序员-----网络编程(2)
- C#网络编程实例
- Volley网络通信框架学习笔记(一)
- Tcp Wrapper <备忘>
- TCP计时器浅解析
- 嵌入式Linux网络编程 之 多线程聊天
- 嵌入式Linux网络编程 之 简单的TCP网络编程
- Nginx模块参考手册:HTTP核心模块
- 使用UTL_HTTP时遭遇ORA-29273
- OC_MediaPlayer_MPMoviePlayerViewController(加载本地/网络视频)