FramedTransport.java
10.3 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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.Headers;
import com.squareup.okhttp.Headers.Builder;
import com.squareup.okhttp.HttpUrl;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Protocol;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.squareup.okhttp.Response.Builder;
import com.squareup.okhttp.ResponseBody;
import com.squareup.okhttp.internal.Util;
import com.squareup.okhttp.internal.framed.ErrorCode;
import com.squareup.okhttp.internal.framed.FramedConnection;
import com.squareup.okhttp.internal.framed.FramedStream;
import com.squareup.okhttp.internal.framed.Header;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import okio.ByteString;
import okio.Okio;
import okio.Sink;
import okio.Timeout;
public final class FramedTransport
implements Transport
{
private static final ByteString CONNECTION = ByteString.encodeUtf8("connection");
private static final ByteString ENCODING;
private static final ByteString HOST = ByteString.encodeUtf8("host");
private static final List<ByteString> HTTP_2_SKIPPED_REQUEST_HEADERS = Util.immutableList(new ByteString[] { CONNECTION, HOST, KEEP_ALIVE, PROXY_CONNECTION, TE, TRANSFER_ENCODING, ENCODING, UPGRADE, Header.TARGET_METHOD, Header.TARGET_PATH, Header.TARGET_SCHEME, Header.TARGET_AUTHORITY, Header.TARGET_HOST, Header.VERSION });
private static final List<ByteString> HTTP_2_SKIPPED_RESPONSE_HEADERS = Util.immutableList(new ByteString[] { CONNECTION, HOST, KEEP_ALIVE, PROXY_CONNECTION, TE, TRANSFER_ENCODING, ENCODING, UPGRADE });
private static final ByteString KEEP_ALIVE = ByteString.encodeUtf8("keep-alive");
private static final ByteString PROXY_CONNECTION = ByteString.encodeUtf8("proxy-connection");
private static final List<ByteString> SPDY_3_SKIPPED_REQUEST_HEADERS;
private static final List<ByteString> SPDY_3_SKIPPED_RESPONSE_HEADERS;
private static final ByteString TE;
private static final ByteString TRANSFER_ENCODING = ByteString.encodeUtf8("transfer-encoding");
private static final ByteString UPGRADE;
private final FramedConnection framedConnection;
private final HttpEngine httpEngine;
private FramedStream stream;
static
{
TE = ByteString.encodeUtf8("te");
ENCODING = ByteString.encodeUtf8("encoding");
UPGRADE = ByteString.encodeUtf8("upgrade");
SPDY_3_SKIPPED_REQUEST_HEADERS = Util.immutableList(new ByteString[] { CONNECTION, HOST, KEEP_ALIVE, PROXY_CONNECTION, TRANSFER_ENCODING, Header.TARGET_METHOD, Header.TARGET_PATH, Header.TARGET_SCHEME, Header.TARGET_AUTHORITY, Header.TARGET_HOST, Header.VERSION });
SPDY_3_SKIPPED_RESPONSE_HEADERS = Util.immutableList(new ByteString[] { CONNECTION, HOST, KEEP_ALIVE, PROXY_CONNECTION, TRANSFER_ENCODING });
}
public FramedTransport(HttpEngine paramHttpEngine, FramedConnection paramFramedConnection)
{
this.httpEngine = paramHttpEngine;
this.framedConnection = paramFramedConnection;
}
public static List<Header> http2HeadersList(Request paramRequest)
{
Headers localHeaders = paramRequest.headers();
ArrayList localArrayList = new ArrayList(localHeaders.size() + 4);
localArrayList.add(new Header(Header.TARGET_METHOD, paramRequest.method()));
localArrayList.add(new Header(Header.TARGET_PATH, RequestLine.requestPath(paramRequest.httpUrl())));
localArrayList.add(new Header(Header.TARGET_AUTHORITY, Util.hostHeader(paramRequest.httpUrl())));
localArrayList.add(new Header(Header.TARGET_SCHEME, paramRequest.httpUrl().scheme()));
int i = 0;
int j = localHeaders.size();
while (i < j)
{
paramRequest = ByteString.encodeUtf8(localHeaders.name(i).toLowerCase(Locale.US));
if (!HTTP_2_SKIPPED_REQUEST_HEADERS.contains(paramRequest)) {
localArrayList.add(new Header(paramRequest, localHeaders.value(i)));
}
i += 1;
}
return localArrayList;
}
private static String joinOnNull(String paramString1, String paramString2)
{
return paramString1 + '\000' + paramString2;
}
public static Response.Builder readHttp2HeadersList(List<Header> paramList)
throws IOException
{
Object localObject = null;
Headers.Builder localBuilder = new Headers.Builder();
localBuilder.set(OkHeaders.SELECTED_PROTOCOL, Protocol.HTTP_2.toString());
int j = paramList.size();
int i = 0;
if (i < j)
{
ByteString localByteString = ((Header)paramList.get(i)).name;
String str = ((Header)paramList.get(i)).value.utf8();
if (localByteString.equals(Header.RESPONSE_STATUS)) {
localObject = str;
}
for (;;)
{
i += 1;
break;
if (!HTTP_2_SKIPPED_RESPONSE_HEADERS.contains(localByteString)) {
localBuilder.add(localByteString.utf8(), str);
}
}
}
if (localObject == null) {
throw new ProtocolException("Expected ':status' header not present");
}
paramList = StatusLine.parse("HTTP/1.1 " + (String)localObject);
return new Response.Builder().protocol(Protocol.HTTP_2).code(paramList.code).message(paramList.message).headers(localBuilder.build());
}
public static Response.Builder readSpdy3HeadersList(List<Header> paramList)
throws IOException
{
Object localObject1 = null;
Object localObject2 = "HTTP/1.1";
Headers.Builder localBuilder = new Headers.Builder();
localBuilder.set(OkHeaders.SELECTED_PROTOCOL, Protocol.SPDY_3.toString());
int n = paramList.size();
int i = 0;
while (i < n)
{
ByteString localByteString = ((Header)paramList.get(i)).name;
String str2 = ((Header)paramList.get(i)).value.utf8();
int j = 0;
if (j < str2.length())
{
int m = str2.indexOf(0, j);
int k = m;
if (m == -1) {
k = str2.length();
}
String str1 = str2.substring(j, k);
if (localByteString.equals(Header.RESPONSE_STATUS)) {
localObject1 = str1;
}
for (;;)
{
j = k + 1;
break;
if (localByteString.equals(Header.VERSION)) {
localObject2 = str1;
} else if (!SPDY_3_SKIPPED_RESPONSE_HEADERS.contains(localByteString)) {
localBuilder.add(localByteString.utf8(), str1);
}
}
}
i += 1;
}
if (localObject1 == null) {
throw new ProtocolException("Expected ':status' header not present");
}
paramList = StatusLine.parse((String)localObject2 + " " + (String)localObject1);
return new Response.Builder().protocol(Protocol.SPDY_3).code(paramList.code).message(paramList.message).headers(localBuilder.build());
}
public static List<Header> spdy3HeadersList(Request paramRequest)
{
Headers localHeaders = paramRequest.headers();
ArrayList localArrayList = new ArrayList(localHeaders.size() + 5);
localArrayList.add(new Header(Header.TARGET_METHOD, paramRequest.method()));
localArrayList.add(new Header(Header.TARGET_PATH, RequestLine.requestPath(paramRequest.httpUrl())));
localArrayList.add(new Header(Header.VERSION, "HTTP/1.1"));
localArrayList.add(new Header(Header.TARGET_HOST, Util.hostHeader(paramRequest.httpUrl())));
localArrayList.add(new Header(Header.TARGET_SCHEME, paramRequest.httpUrl().scheme()));
paramRequest = new LinkedHashSet();
int k = localHeaders.size();
int i = 0;
if (i < k)
{
ByteString localByteString = ByteString.encodeUtf8(localHeaders.name(i).toLowerCase(Locale.US));
String str;
if (!SPDY_3_SKIPPED_REQUEST_HEADERS.contains(localByteString))
{
str = localHeaders.value(i);
if (!paramRequest.add(localByteString)) {
break label236;
}
localArrayList.add(new Header(localByteString, str));
}
label236:
label319:
for (;;)
{
i += 1;
break;
int j = 0;
for (;;)
{
if (j >= localArrayList.size()) {
break label319;
}
if (((Header)localArrayList.get(j)).name.equals(localByteString))
{
localArrayList.set(j, new Header(localByteString, joinOnNull(((Header)localArrayList.get(j)).value.utf8(), str)));
break;
}
j += 1;
}
}
}
return localArrayList;
}
public final boolean canReuseConnection()
{
return true;
}
public final Sink createRequestBody(Request paramRequest, long paramLong)
throws IOException
{
return this.stream.getSink();
}
public final void disconnect(HttpEngine paramHttpEngine)
throws IOException
{
if (this.stream != null) {
this.stream.close(ErrorCode.CANCEL);
}
}
public final void finishRequest()
throws IOException
{
this.stream.getSink().close();
}
public final ResponseBody openResponseBody(Response paramResponse)
throws IOException
{
return new RealResponseBody(paramResponse.headers(), Okio.buffer(this.stream.getSource()));
}
public final Response.Builder readResponseHeaders()
throws IOException
{
if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
return readHttp2HeadersList(this.stream.getResponseHeaders());
}
return readSpdy3HeadersList(this.stream.getResponseHeaders());
}
public final void releaseConnectionOnIdle() {}
public final void writeRequestBody(RetryableSink paramRetryableSink)
throws IOException
{
paramRetryableSink.writeToSocket(this.stream.getSink());
}
public final void writeRequestHeaders(Request paramRequest)
throws IOException
{
if (this.stream != null) {
return;
}
this.httpEngine.writingRequestHeaders();
boolean bool = this.httpEngine.permitsRequestBody(paramRequest);
if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {}
for (paramRequest = http2HeadersList(paramRequest);; paramRequest = spdy3HeadersList(paramRequest))
{
this.stream = this.framedConnection.newStream(paramRequest, bool, true);
this.stream.readTimeout().timeout(this.httpEngine.client.getReadTimeout(), TimeUnit.MILLISECONDS);
return;
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/http/FramedTransport.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/