1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.client5.http.impl.cache;
28
29 import static org.junit.jupiter.api.Assertions.assertFalse;
30
31 import java.time.Instant;
32
33 import org.apache.hc.client5.http.utils.DateUtils;
34 import org.apache.hc.core5.http.HttpResponse;
35 import org.apache.hc.core5.http.HttpStatus;
36 import org.apache.hc.core5.http.support.BasicResponseBuilder;
37 import org.junit.jupiter.api.BeforeEach;
38 import org.junit.jupiter.api.Test;
39
40 class TestResponseCacheConformance {
41
42 private ResponseCacheConformance impl;
43
44 @BeforeEach
45 void setUp() {
46 impl = ResponseCacheConformance.INSTANCE;
47 }
48
49 private void shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
50 final String entityHeader, final String entityHeaderValue) throws Exception {
51 final HttpResponse response = BasicResponseBuilder.create(HttpStatus.SC_NOT_MODIFIED)
52 .addHeader("Date", DateUtils.formatStandardDate(Instant.now()))
53 .addHeader("Etag", "\"etag\"")
54 .addHeader(entityHeader, entityHeaderValue)
55 .build();
56 impl.process(response, null, null);
57 assertFalse(response.containsHeader(entityHeader));
58 }
59
60 @Test
61 void shouldStripContentEncodingFromOrigin304ResponseToStrongValidation() throws Exception {
62 shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
63 "Content-Encoding", "gzip");
64 }
65
66 @Test
67 void shouldStripContentLanguageFromOrigin304ResponseToStrongValidation() throws Exception {
68 shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
69 "Content-Language", "en");
70 }
71
72 @Test
73 void shouldStripContentLengthFromOrigin304ResponseToStrongValidation() throws Exception {
74 shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
75 "Content-Length", "128");
76 }
77
78 @Test
79 void shouldStripContentMD5FromOrigin304ResponseToStrongValidation() throws Exception {
80 shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
81 "Content-MD5", "Q2hlY2sgSW50ZWdyaXR5IQ==");
82 }
83
84 @Test
85 void shouldStripContentTypeFromOrigin304ResponseToStrongValidation() throws Exception {
86 shouldStripEntityHeaderFromOrigin304ResponseToStrongValidation(
87 "Content-Type", "text/html;charset=utf-8");
88 }
89
90 }