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 initializeInstanceForTests()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 addLenient(Headers.Builder builder, String line)48 public abstract void addLenient(Headers.Builder builder, String line); 49 addLenient(Headers.Builder builder, String name, String value)50 public abstract void addLenient(Headers.Builder builder, String name, String value); 51 setCache(OkHttpClient client, InternalCache internalCache)52 public abstract void setCache(OkHttpClient client, InternalCache internalCache); 53 internalCache(OkHttpClient client)54 public abstract InternalCache internalCache(OkHttpClient client); 55 get( ConnectionPool pool, Address address, StreamAllocation streamAllocation)56 public abstract RealConnection get( 57 ConnectionPool pool, Address address, StreamAllocation streamAllocation); 58 put(ConnectionPool pool, RealConnection connection)59 public abstract void put(ConnectionPool pool, RealConnection connection); 60 connectionBecameIdle(ConnectionPool pool, RealConnection connection)61 public abstract boolean connectionBecameIdle(ConnectionPool pool, RealConnection connection); 62 routeDatabase(ConnectionPool connectionPool)63 public abstract RouteDatabase routeDatabase(ConnectionPool connectionPool); 64 apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, boolean isFallback)65 public abstract void apply(ConnectionSpec tlsConfiguration, SSLSocket sslSocket, 66 boolean isFallback); 67 getHttpUrlChecked(String url)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. callEnqueue(Call call, Callback responseCallback, boolean forWebSocket)72 public abstract void callEnqueue(Call call, Callback responseCallback, boolean forWebSocket); callEngineGetStreamAllocation(Call call)73 public abstract StreamAllocation callEngineGetStreamAllocation(Call call); 74 } 75