1 /* 2 * Copyright (C) 2014 Square, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.squareup.okhttp.internal; 17 18 import com.squareup.okhttp.Address; 19 import com.squareup.okhttp.Call; 20 import com.squareup.okhttp.Callback; 21 import com.squareup.okhttp.ConnectionPool; 22 import com.squareup.okhttp.ConnectionSpec; 23 import com.squareup.okhttp.Headers; 24 import com.squareup.okhttp.HttpUrl; 25 import com.squareup.okhttp.OkHttpClient; 26 import com.squareup.okhttp.internal.http.StreamAllocation; 27 import com.squareup.okhttp.internal.io.RealConnection; 28 import java.net.MalformedURLException; 29 import java.net.UnknownHostException; 30 import java.util.logging.Logger; 31 import javax.net.ssl.SSLSocket; 32 33 /** 34 * Escalate internal APIs in {@code com.squareup.okhttp} so they can be used 35 * from OkHttp's implementation packages. The only implementation of this 36 * interface is in {@link com.squareup.okhttp.OkHttpClient}. 37 */ 38 public abstract class Internal { 39 public static final Logger logger = Logger.getLogger(OkHttpClient.class.getName()); 40 41 public static void initializeInstanceForTests() { 42 // Needed in tests to ensure that the instance is actually pointing to something. 43 new OkHttpClient(); 44 } 45 46 public static Internal instance; 47 48 public abstract void addLenient(Headers.Builder builder, String line); 49 50 public abstract void addLenient(Headers.Builder builder, String name, String value); 51 52 public abstract void setCache(OkHttpClient client, InternalCache internalCache); 53 54 public abstract InternalCache internalCache(OkHttpClient client); 55 56 public abstract RealConnection get( 57 ConnectionPool pool, Address address, StreamAllocation streamAllocation); 58 59 public abstract void put(ConnectionPool pool, RealConnection connection); 60 61 public abstract boolean connectionBecameIdle(ConnectionPool pool, RealConnection connection); 62 63 public abstract RouteDatabase routeDatabase(ConnectionPool connectionPool); 64 65 public abstract void apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, 66 boolean isFallback); 67 68 public abstract HttpUrl getHttpUrlChecked(String url) 69 throws MalformedURLException, UnknownHostException; 70 71 // TODO delete the following when web sockets move into the main package. 72 public abstract void callEnqueue(Call call, Callback responseCallback, boolean forWebSocket); 73 public abstract StreamAllocation callEngineGetStreamAllocation(Call call); 74 } 75