1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package com.squareup.okhttp.internal.http; 18 19 import com.squareup.okhttp.Handshake; 20 import com.squareup.okhttp.OkHttpClient; 21 import java.net.URL; 22 import javax.net.ssl.HostnameVerifier; 23 import javax.net.ssl.SSLSocketFactory; 24 25 public final class HttpsURLConnectionImpl extends DelegatingHttpsURLConnection { 26 private final HttpURLConnectionImpl delegate; 27 28 public HttpsURLConnectionImpl(URL url, OkHttpClient client) { 29 this(new HttpURLConnectionImpl(url, client)); 30 } 31 32 public HttpsURLConnectionImpl(HttpURLConnectionImpl delegate) { 33 super(delegate); 34 this.delegate = delegate; 35 } 36 37 @Override protected Handshake handshake() { 38 if (delegate.httpEngine == null) { 39 throw new IllegalStateException("Connection has not yet been established"); 40 } 41 42 // If there's a response, get the handshake from there so that caching 43 // works. Otherwise get the handshake from the connection because we might 44 // have not connected yet. 45 return delegate.httpEngine.hasResponse() 46 ? delegate.httpEngine.getResponse().handshake() 47 : delegate.handshake; 48 } 49 50 @Override public void setHostnameVerifier(HostnameVerifier hostnameVerifier) { 51 delegate.client.setHostnameVerifier(hostnameVerifier); 52 } 53 54 @Override public HostnameVerifier getHostnameVerifier() { 55 return delegate.client.getHostnameVerifier(); 56 } 57 58 @Override public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) { 59 delegate.client.setSslSocketFactory(sslSocketFactory); 60 } 61 62 @Override public SSLSocketFactory getSSLSocketFactory() { 63 return delegate.client.getSslSocketFactory(); 64 } 65 66 @Override public void setFixedLengthStreamingMode(long contentLength) { 67 delegate.setFixedLengthStreamingMode(contentLength); 68 } 69 } 70