HttpEngine newEngine(Connection connection) throws IOException { String protocol = request.url().getProtocol(); RawHeaders requestHeaders = request.rawHeaders(); if (protocol.equals("http")) { return new HttpEngine(client, this, request.method(), requestHeaders, connection, null); } else if (protocol.equals("https")) { return new HttpsEngine(client, this, request.method(), requestHeaders, connection, null); } else { throw new AssertionError(); } }
/** * Returns the SSL socket used by {@code httpConnection} for HTTPS, nor null * if the connection isn't using HTTPS. Since we permit redirects across * protocols (HTTP to HTTPS or vice versa), the implementation type of the * connection doesn't necessarily match the implementation type of its HTTP * engine. */ private SSLSocket getSslSocket(HttpURLConnection httpConnection) { HttpEngine engine = httpConnection instanceof HttpsURLConnectionImpl ? ((HttpsURLConnectionImpl) httpConnection).getHttpEngine() : ((HttpURLConnectionImpl) httpConnection).getHttpEngine(); return engine instanceof HttpsEngine ? ((HttpsEngine) engine).getSslSocket() : null; }