use of mockwebserver3.MockResponse in project okhttp by square.
the class CacheTest method getHeadersDeletesCached100LevelWarnings.
@Test
public void getHeadersDeletesCached100LevelWarnings() throws Exception {
server.enqueue(new MockResponse().addHeader("Warning: 199 test danger").addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").setBody("A"));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
Response response1 = get(server.url("/"));
assertThat(response1.body().string()).isEqualTo("A");
assertThat(response1.header("Warning")).isEqualTo("199 test danger");
Response response2 = get(server.url("/"));
assertThat(response2.body().string()).isEqualTo("A");
assertThat(response2.header("Warning")).isNull();
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class CacheTest method previouslyNotGzippedContentIsNotModifiedAndSpecifiesGzipEncoding.
@Test
public void previouslyNotGzippedContentIsNotModifiedAndSpecifiesGzipEncoding() throws Exception {
server.enqueue(new MockResponse().setBody("ABCABCABC").addHeader("Content-Type: text/plain").addHeader("Last-Modified: " + formatDate(-2, TimeUnit.HOURS)).addHeader("Expires: " + formatDate(-1, TimeUnit.HOURS)));
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED).addHeader("Content-Type: text/plain").addHeader("Content-Encoding: gzip"));
server.enqueue(new MockResponse().setBody("DEFDEFDEF"));
assertThat(get(server.url("/")).body().string()).isEqualTo("ABCABCABC");
assertThat(get(server.url("/")).body().string()).isEqualTo("ABCABCABC");
assertThat(get(server.url("/")).body().string()).isEqualTo("DEFDEFDEF");
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class CacheTest method etagAndExpirationDateInThePast.
/**
* If both If-Modified-Since and If-None-Match conditions apply, send only If-None-Match.
*/
@Test
public void etagAndExpirationDateInThePast() throws Exception {
String lastModifiedDate = formatDate(-2, TimeUnit.HOURS);
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("ETag: v1").addHeader("Last-Modified: " + lastModifiedDate).addHeader("Expires: " + formatDate(-1, TimeUnit.HOURS)));
assertThat(conditionalRequest.getHeader("If-None-Match")).isEqualTo("v1");
assertThat(conditionalRequest.getHeader("If-Modified-Since")).isNull();
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class CacheTest method combinedCacheHeadersCanBeNonAscii.
@Test
public void combinedCacheHeadersCanBeNonAscii() throws Exception {
server.enqueue(new MockResponse().addHeader("Last-Modified: " + formatDate(-1, TimeUnit.HOURS)).addHeader("Cache-Control: max-age=0").addHeaderLenient("Alpha", "α").addHeaderLenient("β", "Beta").setBody("abcd"));
server.enqueue(new MockResponse().addHeader("Transfer-Encoding: none").addHeaderLenient("Gamma", "Γ").addHeaderLenient("Δ", "Delta").setResponseCode(HttpURLConnection.HTTP_NOT_MODIFIED));
Response response1 = get(server.url("/"));
assertThat(response1.header("Alpha")).isEqualTo("α");
assertThat(response1.header("β")).isEqualTo("Beta");
assertThat(response1.body().string()).isEqualTo("abcd");
Response response2 = get(server.url("/"));
assertThat(response2.header("Alpha")).isEqualTo("α");
assertThat(response2.header("β")).isEqualTo("Beta");
assertThat(response2.header("Gamma")).isEqualTo("Γ");
assertThat(response2.header("Δ")).isEqualTo("Delta");
assertThat(response2.body().string()).isEqualTo("abcd");
}
use of mockwebserver3.MockResponse in project okhttp by square.
the class CacheTest method etag.
@Test
public void etag() throws Exception {
RecordedRequest conditionalRequest = assertConditionallyCached(new MockResponse().addHeader("ETag: v1"));
assertThat(conditionalRequest.getHeader("If-None-Match")).isEqualTo("v1");
}
Aggregations