Home | History | Annotate | Download | only in huc
      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.huc;
     18 
     19 import com.squareup.okhttp.Handshake;
     20 import com.squareup.okhttp.OkHttpClient;
     21 import com.squareup.okhttp.internal.URLFilter;
     22 import java.net.URL;
     23 import javax.net.ssl.HostnameVerifier;
     24 import javax.net.ssl.SSLSocketFactory;
     25 
     26 public final class HttpsURLConnectionImpl extends DelegatingHttpsURLConnection {
     27   private final HttpURLConnectionImpl delegate;
     28 
     29   public HttpsURLConnectionImpl(URL url, OkHttpClient client) {
     30     this(new HttpURLConnectionImpl(url, client));
     31   }
     32 
     33   public HttpsURLConnectionImpl(URL url, OkHttpClient client, URLFilter filter) {
     34     this(new HttpURLConnectionImpl(url, client, filter));
     35   }
     36 
     37   public HttpsURLConnectionImpl(HttpURLConnectionImpl delegate) {
     38     super(delegate);
     39     this.delegate = delegate;
     40   }
     41 
     42   @Override protected Handshake handshake() {
     43     if (delegate.httpEngine == null) {
     44       throw new IllegalStateException("Connection has not yet been established");
     45     }
     46 
     47     // If there's a response, get the handshake from there so that caching
     48     // works. Otherwise get the handshake from the connection because we might
     49     // have not connected yet.
     50     return delegate.httpEngine.hasResponse()
     51         ? delegate.httpEngine.getResponse().handshake()
     52         : delegate.handshake;
     53   }
     54 
     55   @Override public void setHostnameVerifier(HostnameVerifier hostnameVerifier) {
     56     delegate.client.setHostnameVerifier(hostnameVerifier);
     57   }
     58 
     59   @Override public HostnameVerifier getHostnameVerifier() {
     60     return delegate.client.getHostnameVerifier();
     61   }
     62 
     63   @Override public void setSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
     64     delegate.client.setSslSocketFactory(sslSocketFactory);
     65   }
     66 
     67   @Override public SSLSocketFactory getSSLSocketFactory() {
     68     return delegate.client.getSslSocketFactory();
     69   }
     70 
     71   @Override public long getContentLengthLong() {
     72     return delegate.getContentLengthLong();
     73   }
     74 
     75   @Override public void setFixedLengthStreamingMode(long contentLength) {
     76     delegate.setFixedLengthStreamingMode(contentLength);
     77   }
     78 
     79   @Override public long getHeaderFieldLong(String field, long defaultValue) {
     80     return delegate.getHeaderFieldLong(field, defaultValue);
     81   }
     82 }
     83