okhttp gzip压缩/解压 (示例)//zip压缩GzipSink gzipSink = new GzipSink(Okio.sink(file));BufferedSink bufferedSink = Okio.buffer(gzipSink);bufferedSink.writeUtf8("this is zip file");bufferedSink.flush();bufferedSink.close();//读取zipGzipSource gzipSource = new GzipSource(Okio.source(file));BufferedSource bufferedSource = Okio.buffer(gzipSource);String s = bufferedSource.readUtf8();okhttp框架-如何对请求(request)数据进行GZIP压缩-GzipRequestInterceptor
OkHttpClient okHttpClient = new OkHttpClient.Builder() .addInterceptor(new GzipRequestInterceptor())//开启Gzip压缩....build();GzipRequestInterceptorhttps://github.com/square/okhttp\issues/350#issuecomment-123105641class GzipRequestInterceptor implements Interceptor {@Override public Response intercept(Chain chain) throws IOException { Request originalRequest = chain.request(); if (originalRequest.body() == null || originalRequest.header("Content-Encoding") != null) {return chain.proceed(originalRequest);}Request compressedRequest = originalRequest.newBuilder() .header("Content-Encoding", "gzip") .method(originalRequest.method(), forceContentLength(gzip(originalRequest.body()))) .build(); return chain.proceed(compressedRequest);}/** https://github.com/square/okhttp\issues/350 */private RequestBody forceContentLength(final RequestBody requestBody) throws IOException {final Buffer buffer = new Buffer();requestBody.writeTo(buffer);return new RequestBody() {@Overridepublic MediaType contentType() {return requestBody.contentType();}@Overridepublic long contentLength() {return buffer.size();}@Overridepublic void writeTo(BufferedSink sink) throws IOException {sink.write(buffer.snapshot());}};}private RequestBody gzip(final RequestBody body) {return new RequestBody() {@Overridepublic MediaType contentType() {return body.contentType();}@Overridepublic long contentLength() {return -1; // We don't know the compressed length in advance!}@Overridepublic void writeTo(BufferedSink sink) throws IOException {BufferedSink gzipSink = Okio.buffer(new GzipSink(sink));body.writeTo(gzipSink);gzipSink.close();}};}}okhttp框架-如何对请求数据进行GZIP压缩
https://cloud.tencent.com/info/61307ab74137a46628c2ea2ca42a6eb4.html
Okhttp3请求网络开启Gzip压缩 - CSDN博客
https://blog.csdn.net/aiynmimi/article/details/77453809
四. Nginx的Gzip可以对服务器端响应内容进行压缩从而减少一定的客户端响应时间gzip on;gzip_min_length 1k;gzip_buffers 4 32k;gzip_types text/plain application/x-JavaScript application/javascript text/xml text/css;gzip_vary on;API网关那些儿 | I'm Yunlong
http://ylzheng.com/2017/03/14/the-things-about-api-gateway
source: //liuxiang.github.io/2018/08/13/HTTP%20gzip压缩
推荐阅读
- netty系列之:性能为王!创建多路复用http2服务器
- 长链接、短链接与连接池
- Linux上使用tinyproxy快速搭建HTTP/HTTPS代理器
- wireshark 如何抓包https
- 2021年年度最佳开源软件
- 面试官问 HTTPS 是怎么从 HTTP 转过来的,我有点懵
- gif图片太大怎么压缩?动图压缩超容易
- 视频怎么压缩变小?教你学会压缩视频
- pdf格式怎么压缩变小?三步就可完成pdf的压缩
- PPT太大怎么压缩变小?不如用这几招来压缩PPT
