use of retrofit2.Response in project okhttp by square.
the class HttpLoggingInterceptorTest method headersResponseBody.
@Test
public void headersResponseBody() throws IOException {
setLevel(Level.HEADERS);
server.enqueue(new MockResponse().setBody("Hello!").setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 6").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
}
use of retrofit2.Response in project okhttp by square.
the class HttpLoggingInterceptorTest method headersGet.
@Test
public void headersGet() throws IOException {
setLevel(Level.HEADERS);
server.enqueue(new MockResponse());
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP").assertNoMoreLogs();
}
use of retrofit2.Response in project okhttp by square.
the class HttpLoggingInterceptorTest method bodyPost.
@Test
public void bodyPost() throws IOException {
setLevel(Level.BODY);
server.enqueue(new MockResponse());
Request request = request().post(RequestBody.create(PLAIN, "Hi?")).build();
Response response = client.newCall(request).execute();
response.body().close();
applicationLogs.assertLogEqual("--> POST " + url + " http/1.1").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("Content-Length: 3").assertLogEqual("").assertLogEqual("Hi?").assertLogEqual("--> END POST (3-byte body)").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
networkLogs.assertLogEqual("--> POST " + url + " http/1.1").assertLogEqual("Content-Type: text/plain; charset=utf-8").assertLogEqual("Content-Length: 3").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("").assertLogEqual("Hi?").assertLogEqual("--> END POST (3-byte body)").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
}
use of retrofit2.Response in project okhttp by square.
the class HttpLoggingInterceptorTest method basicChunkedResponseBody.
@Test
public void basicChunkedResponseBody() throws IOException {
setLevel(Level.BASIC);
server.enqueue(new MockResponse().setChunkedBody("Hello!", 2).setHeader("Content-Type", PLAIN));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogMatch("<-- 200 OK " + url + " \\(\\d+ms, unknown-length body\\)").assertNoMoreLogs();
}
use of retrofit2.Response in project okhttp by square.
the class HttpLoggingInterceptorTest method bodyGetNoBody.
private void bodyGetNoBody(int code) throws IOException {
server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + code + " No Content"));
Response response = client.newCall(request().build()).execute();
response.body().close();
applicationLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
networkLogs.assertLogEqual("--> GET " + url + " http/1.1").assertLogEqual("Host: " + host).assertLogEqual("Connection: Keep-Alive").assertLogEqual("Accept-Encoding: gzip").assertLogMatch("User-Agent: okhttp/.+").assertLogEqual("--> END GET").assertLogMatch("<-- " + code + " No Content " + url + " \\(\\d+ms\\)").assertLogEqual("Content-Length: 0").assertLogEqual("<-- END HTTP (0-byte body)").assertNoMoreLogs();
}
Aggregations