12. 압축¶
compression()을 켜면 요청에 Accept-Encoding: gzip, deflate를 붙이고 응답이
gzip 또는 deflate로 인코딩됐으면 투명하게 해제한다.
HttpResponse<Report> response = ZLinkHttpClient.create("https://api.internal")
.compression()
.get("/large-report")
.submit(Report.class)
.toCompletableFuture().join();
래퍼 통제 해제¶
java.net.http는 응답을 자동 해제하지 않는다. 그래서 래퍼가 java.util.zip으로 해제를
통제한다. 이유는 의미론을 zlink 계약에 맞추기 위해서다:
- gzip + deflate 모두 처리한다(deflate는 zlib-wrap/raw 둘 다 감지).
- 해제 후
content-encoding헤더를 제거한다. - decoded 크기를
maxResponseBodySize로 강제한다. download(sink)streaming chunk는 해제하지 않는다(받은 그대로 전달).
본문이 손상됐으면 decode 실패 예외, decoded 크기가 한도를 넘으면 request 실패 예외로 보고된다.