1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 /* 3 * Copyright (C) 2013 Square, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * 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.android.okhttp; 18 19 import java.net.InetSocketAddress; 20 import java.net.Proxy; 21 22 /** 23 * The concrete route used by a connection to reach an abstract origin server. 24 * When creating a connection the client has many options: 25 * <ul> 26 * <li><strong>HTTP proxy:</strong> a proxy server may be explicitly 27 * configured for the client. Otherwise the {@linkplain java.net.ProxySelector 28 * proxy selector} is used. It may return multiple proxies to attempt. 29 * <li><strong>IP address:</strong> whether connecting directly to an origin 30 * server or a proxy, opening a socket requires an IP address. The DNS 31 * server may return multiple IP addresses to attempt. 32 * </ul> 33 * Each route is a specific selection of these options. 34 * @hide This class is not part of the Android public SDK API 35 */ 36 public final class Route { 37 final Address address; 38 final Proxy proxy; 39 final InetSocketAddress inetSocketAddress; 40 41 public Route(Address address, Proxy proxy, InetSocketAddress inetSocketAddress) { 42 if (address == null) { 43 throw new NullPointerException("address == null"); 44 } 45 if (proxy == null) { 46 throw new NullPointerException("proxy == null"); 47 } 48 if (inetSocketAddress == null) { 49 throw new NullPointerException("inetSocketAddress == null"); 50 } 51 this.address = address; 52 this.proxy = proxy; 53 this.inetSocketAddress = inetSocketAddress; 54 } 55 56 public Address getAddress() { 57 return address; 58 } 59 60 /** 61 * Returns the {@link Proxy} of this route. 62 * 63 * <strong>Warning:</strong> This may disagree with {@link Address#getProxy} 64 * when it is null. When the address's proxy is null, the proxy selector is 65 * used. 66 */ 67 public Proxy getProxy() { 68 return proxy; 69 } 70 71 public InetSocketAddress getSocketAddress() { 72 return inetSocketAddress; 73 } 74 75 /** 76 * Returns true if this route tunnels HTTPS through an HTTP proxy. See <a 77 * href="http://www.ietf.org/rfc/rfc2817.txt">RFC 2817, Section 5.2</a>. 78 */ 79 public boolean requiresTunnel() { 80 return address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP; 81 } 82 83 @Override public boolean equals(Object obj) { 84 if (obj instanceof Route) { 85 Route other = (Route) obj; 86 return address.equals(other.address) 87 && proxy.equals(other.proxy) 88 && inetSocketAddress.equals(other.inetSocketAddress); 89 } 90 return false; 91 } 92 93 @Override public int hashCode() { 94 int result = 17; 95 result = 31 * result + address.hashCode(); 96 result = 31 * result + proxy.hashCode(); 97 result = 31 * result + inetSocketAddress.hashCode(); 98 return result; 99 } 100 } 101