HttpTransport.java
3.49 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
package com.squareup.okhttp.internal.http;
import com.squareup.okhttp.Connection;
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.Route;
import java.io.IOException;
import java.net.Proxy;
import okio.Okio;
import okio.Sink;
import okio.Source;
public final class HttpTransport
implements Transport
{
private final HttpConnection httpConnection;
private final HttpEngine httpEngine;
public HttpTransport(HttpEngine paramHttpEngine, HttpConnection paramHttpConnection)
{
this.httpEngine = paramHttpEngine;
this.httpConnection = paramHttpConnection;
}
private Source getTransferStream(Response paramResponse)
throws IOException
{
if (!HttpEngine.hasBody(paramResponse)) {
return this.httpConnection.newFixedLengthSource(0L);
}
if ("chunked".equalsIgnoreCase(paramResponse.header("Transfer-Encoding"))) {
return this.httpConnection.newChunkedSource(this.httpEngine);
}
long l = OkHeaders.contentLength(paramResponse);
if (l != -1L) {
return this.httpConnection.newFixedLengthSource(l);
}
return this.httpConnection.newUnknownLengthSource();
}
public final boolean canReuseConnection()
{
if ("close".equalsIgnoreCase(this.httpEngine.getRequest().header("Connection"))) {}
while (("close".equalsIgnoreCase(this.httpEngine.getResponse().header("Connection"))) || (this.httpConnection.isClosed())) {
return false;
}
return true;
}
public final Sink createRequestBody(Request paramRequest, long paramLong)
throws IOException
{
if ("chunked".equalsIgnoreCase(paramRequest.header("Transfer-Encoding"))) {
return this.httpConnection.newChunkedSink();
}
if (paramLong != -1L) {
return this.httpConnection.newFixedLengthSink(paramLong);
}
throw new IllegalStateException("Cannot stream a request body without chunked encoding or a known content length!");
}
public final void disconnect(HttpEngine paramHttpEngine)
throws IOException
{
this.httpConnection.closeIfOwnedBy(paramHttpEngine);
}
public final void finishRequest()
throws IOException
{
this.httpConnection.flush();
}
public final ResponseBody openResponseBody(Response paramResponse)
throws IOException
{
Source localSource = getTransferStream(paramResponse);
return new RealResponseBody(paramResponse.headers(), Okio.buffer(localSource));
}
public final Response.Builder readResponseHeaders()
throws IOException
{
return this.httpConnection.readResponse();
}
public final void releaseConnectionOnIdle()
throws IOException
{
if (canReuseConnection())
{
this.httpConnection.poolOnIdle();
return;
}
this.httpConnection.closeOnIdle();
}
public final void writeRequestBody(RetryableSink paramRetryableSink)
throws IOException
{
this.httpConnection.writeRequestBody(paramRetryableSink);
}
public final void writeRequestHeaders(Request paramRequest)
throws IOException
{
this.httpEngine.writingRequestHeaders();
String str = RequestLine.get(paramRequest, this.httpEngine.getConnection().getRoute().getProxy().type());
this.httpConnection.writeRequest(paramRequest.headers(), str);
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/squareup/okhttp/internal/http/HttpTransport.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/