OkHeaders.java
8.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.Authenticator;
import com.squareup.okhttp.Challenge;
import com.squareup.okhttp.Headers;
import com.squareup.okhttp.Headers.Builder;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Request.Builder;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.internal.Platform;
import com.squareup.okhttp.internal.Util;
import java.io.IOException;
import java.net.Proxy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
public final class OkHeaders
{
private static final Comparator<String> FIELD_NAME_COMPARATOR = new Comparator()
{
public final int compare(String paramAnonymousString1, String paramAnonymousString2)
{
if (paramAnonymousString1 == paramAnonymousString2) {
return 0;
}
if (paramAnonymousString1 == null) {
return -1;
}
if (paramAnonymousString2 == null) {
return 1;
}
return String.CASE_INSENSITIVE_ORDER.compare(paramAnonymousString1, paramAnonymousString2);
}
};
static final String PREFIX = Platform.get().getPrefix();
public static final String RECEIVED_MILLIS = PREFIX + "-Received-Millis";
public static final String SELECTED_PROTOCOL = PREFIX + "-Selected-Protocol";
public static final String SENT_MILLIS = PREFIX + "-Sent-Millis";
public static void addCookies(Request.Builder paramBuilder, Map<String, List<String>> paramMap)
{
paramMap = paramMap.entrySet().iterator();
while (paramMap.hasNext())
{
Map.Entry localEntry = (Map.Entry)paramMap.next();
String str = (String)localEntry.getKey();
if ((("Cookie".equalsIgnoreCase(str)) || ("Cookie2".equalsIgnoreCase(str))) && (!((List)localEntry.getValue()).isEmpty())) {
paramBuilder.addHeader(str, buildCookieHeader((List)localEntry.getValue()));
}
}
}
private static String buildCookieHeader(List<String> paramList)
{
if (paramList.size() == 1) {
return (String)paramList.get(0);
}
StringBuilder localStringBuilder = new StringBuilder();
int j = paramList.size();
int i = 0;
while (i < j)
{
if (i > 0) {
localStringBuilder.append("; ");
}
localStringBuilder.append((String)paramList.get(i));
i += 1;
}
return localStringBuilder.toString();
}
public static long contentLength(Headers paramHeaders)
{
return stringToLong(paramHeaders.get("Content-Length"));
}
public static long contentLength(Request paramRequest)
{
return contentLength(paramRequest.headers());
}
public static long contentLength(Response paramResponse)
{
return contentLength(paramResponse.headers());
}
public static boolean hasVaryAll(Headers paramHeaders)
{
return varyFields(paramHeaders).contains("*");
}
public static boolean hasVaryAll(Response paramResponse)
{
return hasVaryAll(paramResponse.headers());
}
static boolean isEndToEnd(String paramString)
{
return (!"Connection".equalsIgnoreCase(paramString)) && (!"Keep-Alive".equalsIgnoreCase(paramString)) && (!"Proxy-Authenticate".equalsIgnoreCase(paramString)) && (!"Proxy-Authorization".equalsIgnoreCase(paramString)) && (!"TE".equalsIgnoreCase(paramString)) && (!"Trailers".equalsIgnoreCase(paramString)) && (!"Transfer-Encoding".equalsIgnoreCase(paramString)) && (!"Upgrade".equalsIgnoreCase(paramString));
}
public static List<Challenge> parseChallenges(Headers paramHeaders, String paramString)
{
ArrayList localArrayList = new ArrayList();
int k = paramHeaders.size();
int i = 0;
while (i < k)
{
if (paramString.equalsIgnoreCase(paramHeaders.name(i)))
{
String str1 = paramHeaders.value(i);
int j = 0;
while (j < str1.length())
{
int m = HeaderParser.skipUntil(str1, j, " ");
String str2 = str1.substring(j, m).trim();
j = HeaderParser.skipWhitespace(str1, m);
if (!str1.regionMatches(true, j, "realm=\"", 0, 7)) {
break;
}
j += 7;
m = HeaderParser.skipUntil(str1, j, "\"");
String str3 = str1.substring(j, m);
j = HeaderParser.skipWhitespace(str1, HeaderParser.skipUntil(str1, m + 1, ",") + 1);
localArrayList.add(new Challenge(str2, str3));
}
}
i += 1;
}
return localArrayList;
}
public static Request processAuthHeader(Authenticator paramAuthenticator, Response paramResponse, Proxy paramProxy)
throws IOException
{
if (paramResponse.code() == 407) {
return paramAuthenticator.authenticateProxy(paramProxy, paramResponse);
}
return paramAuthenticator.authenticate(paramProxy, paramResponse);
}
private static long stringToLong(String paramString)
{
if (paramString == null) {
return -1L;
}
try
{
long l = Long.parseLong(paramString);
return l;
}
catch (NumberFormatException paramString) {}
return -1L;
}
public static Map<String, List<String>> toMultimap(Headers paramHeaders, String paramString)
{
TreeMap localTreeMap = new TreeMap(FIELD_NAME_COMPARATOR);
int j = paramHeaders.size();
int i = 0;
while (i < j)
{
String str1 = paramHeaders.name(i);
String str2 = paramHeaders.value(i);
ArrayList localArrayList = new ArrayList();
List localList = (List)localTreeMap.get(str1);
if (localList != null) {
localArrayList.addAll(localList);
}
localArrayList.add(str2);
localTreeMap.put(str1, Collections.unmodifiableList(localArrayList));
i += 1;
}
if (paramString != null) {
localTreeMap.put(null, Collections.unmodifiableList(Collections.singletonList(paramString)));
}
return Collections.unmodifiableMap(localTreeMap);
}
public static Set<String> varyFields(Headers paramHeaders)
{
Object localObject2 = Collections.emptySet();
int k = paramHeaders.size();
int i = 0;
while (i < k)
{
Object localObject3 = localObject2;
if ("Vary".equalsIgnoreCase(paramHeaders.name(i)))
{
localObject3 = paramHeaders.value(i);
Object localObject1 = localObject2;
if (((Set)localObject2).isEmpty()) {
localObject1 = new TreeSet(String.CASE_INSENSITIVE_ORDER);
}
localObject2 = ((String)localObject3).split(",");
int m = localObject2.length;
int j = 0;
for (;;)
{
localObject3 = localObject1;
if (j >= m) {
break;
}
((Set)localObject1).add(localObject2[j].trim());
j += 1;
}
}
i += 1;
localObject2 = localObject3;
}
return (Set<String>)localObject2;
}
private static Set<String> varyFields(Response paramResponse)
{
return varyFields(paramResponse.headers());
}
public static Headers varyHeaders(Headers paramHeaders1, Headers paramHeaders2)
{
paramHeaders2 = varyFields(paramHeaders2);
if (paramHeaders2.isEmpty()) {
return new Headers.Builder().build();
}
Headers.Builder localBuilder = new Headers.Builder();
int i = 0;
int j = paramHeaders1.size();
while (i < j)
{
String str = paramHeaders1.name(i);
if (paramHeaders2.contains(str)) {
localBuilder.add(str, paramHeaders1.value(i));
}
i += 1;
}
return localBuilder.build();
}
public static Headers varyHeaders(Response paramResponse)
{
return varyHeaders(paramResponse.networkResponse().request().headers(), paramResponse.headers());
}
public static boolean varyMatches(Response paramResponse, Headers paramHeaders, Request paramRequest)
{
paramResponse = varyFields(paramResponse).iterator();
while (paramResponse.hasNext())
{
String str = (String)paramResponse.next();
if (!Util.equal(paramHeaders.values(str), paramRequest.headers(str))) {
return false;
}
}
return true;
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/http/OkHeaders.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/