Search in sources :

Example 11 with StatusLine

use of okhttp3.internal.http.StatusLine in project apollo-android by apollographql.

the class ResponseHeaderRecord method writeTo.

void writeTo(Sink sink) throws IOException {
    BufferedSink bufferedSink = Okio.buffer(sink);
    bufferedSink.writeUtf8(url).writeByte('\n');
    bufferedSink.writeUtf8(requestMethod).writeByte('\n');
    bufferedSink.writeDecimalLong(varyHeaders.size()).writeByte('\n');
    for (int i = 0, size = varyHeaders.size(); i < size; i++) {
        bufferedSink.writeUtf8(varyHeaders.name(i)).writeUtf8(": ").writeUtf8(varyHeaders.value(i)).writeByte('\n');
    }
    bufferedSink.writeUtf8(new StatusLine(protocol, code, message).toString()).writeByte('\n');
    bufferedSink.writeDecimalLong(responseHeaders.size() + 2).writeByte('\n');
    for (int i = 0, size = responseHeaders.size(); i < size; i++) {
        bufferedSink.writeUtf8(responseHeaders.name(i)).writeUtf8(": ").writeUtf8(responseHeaders.value(i)).writeByte('\n');
    }
    bufferedSink.writeUtf8(SENT_MILLIS).writeUtf8(": ").writeDecimalLong(sentRequestMillis).writeByte('\n');
    bufferedSink.writeUtf8(RECEIVED_MILLIS).writeUtf8(": ").writeDecimalLong(receivedResponseMillis).writeByte('\n');
    if (isHttps()) {
        bufferedSink.writeByte('\n');
        bufferedSink.writeUtf8(handshake.cipherSuite().javaName()).writeByte('\n');
        writeCertList(bufferedSink, handshake.peerCertificates());
        writeCertList(bufferedSink, handshake.localCertificates());
        // The handshake's TLS version is null on HttpsURLConnection and on older cached responses.
        if (handshake.tlsVersion() != null) {
            bufferedSink.writeUtf8(handshake.tlsVersion().javaName()).writeByte('\n');
        }
    }
    bufferedSink.close();
}
Also used : StatusLine(okhttp3.internal.http.StatusLine) BufferedSink(okio.BufferedSink)

Aggregations

Headers (okhttp3.Headers)6 Response (okhttp3.Response)5 StatusLine (okhttp3.internal.http.StatusLine)5 Test (org.junit.Test)5 CacheResponse (java.net.CacheResponse)4 SecureCacheResponse (java.net.SecureCacheResponse)4 URI (java.net.URI)4 Request (okhttp3.Request)4 IOException (java.io.IOException)3 HttpURLConnection (java.net.HttpURLConnection)3 Certificate (java.security.cert.Certificate)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)3 Handshake (okhttp3.Handshake)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ProtocolException (java.net.ProtocolException)2 ResponseCache (java.net.ResponseCache)2 URL (java.net.URL)2 URLConnection (java.net.URLConnection)2