use of com.amazonaws.services.s3.Headers in project okhttp by square.
the class JavaApiConverter method createJavaCacheResponse.
/**
* Creates a {@link java.net.CacheResponse} of the correct (sub)type using information gathered
* from the supplied {@link Response}.
*/
public static CacheResponse createJavaCacheResponse(final Response response) {
final Headers headers = withSyntheticHeaders(response);
final ResponseBody body = response.body();
if (response.request().isHttps()) {
final Handshake handshake = response.handshake();
return new SecureCacheResponse() {
@Override
public String getCipherSuite() {
return handshake != null ? handshake.cipherSuite().javaName() : null;
}
@Override
public List<Certificate> getLocalCertificateChain() {
if (handshake == null)
return null;
// Java requires null, not an empty list here.
List<Certificate> certificates = handshake.localCertificates();
return certificates.size() > 0 ? certificates : null;
}
@Override
public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
if (handshake == null)
return null;
// Java requires null, not an empty list here.
List<Certificate> certificates = handshake.peerCertificates();
return certificates.size() > 0 ? certificates : null;
}
@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
if (handshake == null)
return null;
return handshake.peerPrincipal();
}
@Override
public Principal getLocalPrincipal() {
if (handshake == null)
return null;
return handshake.localPrincipal();
}
@Override
public Map<String, List<String>> getHeaders() throws IOException {
// Java requires that the entry with a null key be the status line.
return JavaNetHeaders.toMultimap(headers, StatusLine.get(response).toString());
}
@Override
public InputStream getBody() throws IOException {
if (body == null)
return null;
return body.byteStream();
}
};
} else {
return new CacheResponse() {
@Override
public Map<String, List<String>> getHeaders() throws IOException {
// Java requires that the entry with a null key be the status line.
return JavaNetHeaders.toMultimap(headers, StatusLine.get(response).toString());
}
@Override
public InputStream getBody() throws IOException {
if (body == null)
return null;
return body.byteStream();
}
};
}
}
use of com.amazonaws.services.s3.Headers in project okhttp by square.
the class MockWebServerTest method headersToList.
private List<String> headersToList(MockResponse response) {
Headers headers = response.getHeaders();
int size = headers.size();
List<String> headerList = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
headerList.add(headers.name(i) + ": " + headers.value(i));
}
return headerList;
}
use of com.amazonaws.services.s3.Headers in project retrofit by square.
the class ResponseTest method successWithHeaders.
@Test
public void successWithHeaders() {
Object body = new Object();
Headers headers = Headers.of("foo", "bar");
Response<Object> response = Response.success(body, headers);
assertThat(response.raw()).isNotNull();
assertThat(response.code()).isEqualTo(200);
assertThat(response.message()).isEqualTo("OK");
assertThat(response.headers().toMultimap()).isEqualTo(headers.toMultimap());
assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isSameAs(body);
assertThat(response.errorBody()).isNull();
}
use of com.amazonaws.services.s3.Headers in project realm-java by realm.
the class HttpUtils method stopSyncServer.
public static void stopSyncServer() throws Exception {
Request request = new Request.Builder().url(STOP_SERVER).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful())
throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
RealmLog.debug(response.body().string());
}
use of com.amazonaws.services.s3.Headers in project realm-java by realm.
the class HttpUtils method startSyncServer.
public static void startSyncServer() throws Exception {
Request request = new Request.Builder().url(START_SERVER).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful())
throw new IOException("Unexpected code " + response);
Headers responseHeaders = response.headers();
for (int i = 0; i < responseHeaders.size(); i++) {
RealmLog.debug(responseHeaders.name(i) + ": " + responseHeaders.value(i));
}
RealmLog.debug(response.body().string());
// FIXME: Server ready checking should be done in the control server side!
if (!waitAuthServerReady()) {
stopSyncServer();
throw new RuntimeException("Auth server cannot be started.");
}
}
Aggregations