1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-27 04:22:07 +03:00
Commit Graph

53 Commits

Author SHA1 Message Date
Jesse Wilson
51e5320e7b Don't drop out of connect if the first request fails.
This fixes a break caused by the recent try-harder-on-IP-addresses
change, where if the first connect failed we returned rather than
trying until we reached a connection or an error.
2012-11-11 12:45:50 -08:00
Jesse Wilson
3355d0c99b New route selector to support multiple routes. 2012-11-10 13:05:53 -08:00
Jesse Wilson
e5b78cabad Fix some bugs from exercising HttpConnection + SPDY.
I was trying to reproduce a connectivity problem and
I found other related problems along the way:
 - We were unnecessarily creating new HttpConnection instances.
 - We were using "" as the file instead of "/" for SPDY.
2012-11-07 14:18:12 -08:00
Jake Wharton
0ce37b70f8 Correct checkstyle errors. 2012-11-05 21:35:22 -08:00
Jesse Wilson
40ff765470 Make HttpConnection.connect return full working connections.
Previously the returned connections required the caller to
do extra work: setting up tunnels (which could require auth)
and performing an SSL handshake. With this change we make a
complete working connection in HttpConnection.connect().

This will make it easier to fix fallback when a single domain
has multiple IP addresses and some of those addresses are not
reachable.

This will also make it easier to do SPDY through HTTP proxies.
2012-11-05 20:25:52 -08:00
Jake Wharton
f1eacbff7e Merge pull request #48 from square/jwilson/recycle_gzip
Fix connection recycling for TLS+gzip+chunked.
2012-10-27 19:41:27 -07:00
Jesse Wilson
2f5e25e4dc Fix connection recycling for TLS+gzip+chunked.
We had a bug where the underlying SSLInputStream always returned
0 for InputStream.available(). This prevented us from ever reading
the "end of stream" chunk, which prevented connection recycling.
http://code.google.com/p/android/issues/detail?id=38817

Also fix a nearby bug where we were fast-forwarding the gzipped
stream when we should have been fast-forwarding the transfer
stream when we were preparing to recycle a connection.
2012-10-25 12:03:13 -04:00
Jesse Wilson
cbb33cbd05 Fix a severe bug where multiple TLS tunnels were attempted.
The previous code would attempt a TLS tunnel on reused
HTTPS connections, even after the tunnel had been established.
This is a severe protocol error!
2012-10-24 22:15:51 -04:00
Jesse Wilson
99fb988657 Tests and code for various SPDY close scenarios.
Writing this change has led me to believe that the
concurrency here is just plain awful, and I need to
find a better solution than what I have. In particular,
there are too many threads:
 - the internal reader thread
 - application reader threads
 - application writer threads
And too many locks:
 - the SpdyWriter I/O write lock
 - the SpdyConnection internal state lock
 - each SpdyStream's internal state lock

What's currently very wrong is the internal reader thread
is updating state in the SpdyStream, and reading bytes from
the network into a particular stream. It is an error to hold
the SpdyStream's lock while reading, but we're doing it because
we need to hold the state on the buffer, position and limit.
We need to rethink this!

Chrome doesn't run into this problem because it can 'fire and
forget' events. We can't do that because SPDY writes need to
throw IOExceptions if the writes fail.
2012-10-02 18:51:46 -04:00
Jesse Wilson
961d797e9c Use callbacks rather than fields to handle incoming frames. 2012-09-30 12:05:54 -04:00
Jesse Wilson
d2fc60ad18 Support noop frames. Make ping sending a blocking (synchronous) call.
Although blocking calls don't fit the SPDY model very well, they
make exception transparency easy. In this case, a NOOP or a PING
will throw if it cannot be sent. This is good.
2012-09-29 14:25:08 -04:00
Patrick Forhan
8fe93f33dc Merge pull request #43 from square/jwilson/strictstatuscode
Be strict and careful when parsing the response status line.
2012-09-28 08:01:08 -07:00
Jesse Wilson
48b087d327 Be strict and careful when parsing the response status line.
The current status line parsing is lenient and sloppy; a
holdover from an ancient version of this library. The new
code is strict and provides a helpful message if a bogus
status line is encountered.

To make this possible the RawHeaders class needs a hint
about whether it's looking for a request line (from an
HTTP request) or a status line (from an HTTP response).
The old sloppy code used the same APIs for both.
2012-09-28 10:53:54 -04:00
Jesse Wilson
747da632ad Support reply with fin for no response body. 2012-09-27 12:19:40 -04:00
Jesse Wilson
1ef44259dc Missed my period. 2012-09-26 14:40:18 -04:00
Jesse Wilson
853c4012b7 Abandon foolish consistency with SpdyReader for sending frames.
Setting fields and then calling a method is just not as usable
as calling a method that takes arguments.

Also move Settings into their own class, so we can sling them
around without a bunch of ceremony.
2012-09-26 11:58:14 -04:00
Jesse Wilson
68ebb704fb Address some todos around stream failures and peer errors. 2012-09-25 17:32:28 -04:00
Jesse Wilson
60b3a6dd62 Be more careful about synchronization.
SpdyConnection needs to guard its own state separately from
the SpdyWriter, which permits slow blocking calls. Split these
into multiple independent locks.

Also use independent right-sized thread pools for reading (exactly
one thread all the time) delayed writing (0 or 1 threads) and
callbacks (any number of threads).
2012-09-25 14:29:25 -04:00
Jake Wharton
1853b5b108 Merge pull request #35 from square/jwilson/ping
Implement TYPE_PING.
2012-09-24 22:21:23 -07:00
Jake Wharton
9ecb2a883b Merge pull request #31 from square/jwilson/auth
Fix Authenticator callbacks to include full information.
2012-09-24 22:19:46 -07:00
Jesse Wilson
b3405b09cd Fix a bug where String.substring() parameters were flipped. 2012-09-25 01:07:18 -04:00
Jesse Wilson
2bd54fa72f Implement TYPE_PING.
Though it isn't particularly useful in practice, it's
going to be extremely handy for testing since it makes
a happens-before relationship very easy to create.
2012-09-25 00:34:47 -04:00
Jake Wharton
5f239296e9 Correct checkstyle. 2012-09-24 13:16:16 -07:00
Jesse Wilson
7a7ad1cdb2 Handle incoming SETTINGS frames in SPDY. 2012-09-21 17:28:07 -04:00
Jesse Wilson
5d4e9ac850 Fix Authenticator callbacks to include full information.
These were passing the wrong parameters for proxies, and not
including enough information for origin servers.

Related to: http://code.google.com/p/android/issues/detail?id=18856
2012-09-20 20:33:00 -04:00
Jake Wharton
a40fb20544 Merge pull request #30 from square/jwilson/tunnelconnect
Fix a bug in tunnel construction and 'Connection: close' headers.
2012-09-20 13:54:26 -07:00
Jesse Wilson
b8c51dc5bd Fix a bug in tunnel construction and 'Connection: close' headers.
http://code.google.com/p/android/issues/detail?id=37221
2012-09-20 16:47:52 -04:00
Jake Wharton
83d3e2ff5e Merge pull request #29 from square/jwilson/tunnel
Fix TLS requiresTunnel which was being computed incorrectly.
2012-09-20 13:04:25 -07:00
Jesse Wilson
5aa2456a14 Fix TLS requiresTunnel which was being computed incorrectly.
We were only returning 'true' once we were already in a tunnel.
This was bogus. In theory a TLS tunnel sending extra data could
be corrupted due to this bug.

Also migrate one of the TLS tunnel tests to use SslContextBuilder
instead of TestSSLContext.
2012-09-20 16:01:17 -04:00
Jake Wharton
00c0da5ec5 Fix checkstyle errors. 2012-09-19 16:05:25 -07:00
Jake Wharton
e60321991c Merge pull request #26 from square/jwilson/faster
Merge: Performance improvements: DiskLruCache, HttpResponseCache.
2012-09-19 14:28:55 -07:00
edenman
86c58deebb Merge pull request #27 from square/jwilson/crime
Disable SSL compression
2012-09-19 14:28:47 -07:00
Jesse Wilson
d79a5e23a7 Disable SSL compression
Original AOSP/libcore commit from Brian Carlstrom:
Bug: 7079965
Change-Id: I8e060a827613e212bbcced66507fbf124bb04543
2012-09-19 17:27:12 -04:00
Jesse Wilson
761619286a Merge: Performance improvements: DiskLruCache, HttpResponseCache.
Original AOSP/libcore commit from Vladimir Marko:
Add StrictLineReader for efficient reading of lines
consistent with Streams.readAsciiLine(). Use this to improve
DiskLruCache.readJournal() and initialization of
HttpResponseCache$Entry from InputStream.

(cherry-pick of e03b551079aae1204e505f1dc24f2b986ef82ec0.)

Bug: 6739304
Change-Id: If3083031f1368a9bbbd405c91553d7a205fd4e39
2012-09-19 17:18:48 -04:00
Jake Wharton
51a46a4db6 Merge pull request #25 from square/jwilson/cache504
Merge: HttpResponseCache should return 504, not 502.
2012-09-19 14:17:47 -07:00
Jesse Wilson
8d06f68600 Merge: HttpResponseCache should return 504, not 502.
Original AOSP/libcore commit from Elliott Hughes:
The RFC seems pretty clear on this issue.

Bug: http://code.google.com/p/android/issues/detail?id=28294
Change-Id: Ia9a979e1fbbd8b38b1607059c042e0fc9ca44270
2012-09-19 16:48:48 -04:00
Jake Wharton
18e203a53e Merge pull request #24 from square/jwilson/closeguard
Merge: Fix HttpURLConnection CloseGuard warning due to lack of close on ...
2012-09-19 13:27:26 -07:00
Jesse Wilson
1594066552 Merge: Fix HttpURLConnection CloseGuard warning due to lack of close on GZIPInputStream
Original AOSP/libcore commit by Brian Carlstrom:
java.lang.Throwable: Explicit termination method 'end' not called
  at dalvik.system.CloseGuard.open(CloseGuard.java:184)
  at java.util.zip.Inflater.<init>(Inflater.java:82)
  at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:96)
  at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:81)
  at libcore.net.http.HttpEngine.initContentStream(HttpEngine.java:523)
  at libcore.net.http.HttpEngine.readResponse(HttpEngine.java:831)
  at libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
  at libcore.net.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:486)
  at ...

Bug: 6602529
Change-Id: I9b49cbca561f8780d08844e566820087fdffc4d7
2012-09-19 16:23:53 -04:00
Jake Wharton
729e930a1b Merge pull request #21 from square/jwilson/fast
Merge: Improve HttpResponseCache performance.
2012-09-19 13:17:07 -07:00
Jake Wharton
19d8cf1c0f Merge pull request #23 from square/jwilson/deleted
Merge: Tolerate cache files being removed from underneath DiskLruCache
2012-09-19 13:13:58 -07:00
Jesse Wilson
1bc9e2ef26 Merge: Tolerate cache files being removed from underneath DiskLruCache
Original AOSP/libcore commit by Brian Carlstrom:
Bug: 6777079
Change-Id: I2f950ab6d847dd63061aeb449fc5d46ab9e6c50a
2012-09-19 16:09:34 -04:00
Jesse Wilson
faeff7f105 Merge: TLS + SNI + proxy => bug
Original AOSP/libcore commit from Brian Carlstrom;
The SNI at the TLS layer is the hostname of the proxy instead
of the hostname in the URL.
2012-09-19 15:48:02 -04:00
Jesse Wilson
ac21c32677 Merge: Improve HttpResponseCache performance.
Original AOSP/libcore commit from Vladimir Marko:
Avoid writing to HttpResponseCache.CacheRequestImpl.cacheOut
one byte at a time via inefficient FilterOutputStream write.

(cherry-picked from 91cc423115fdfa682d9c4cd025dee06aaa145b3c.)

Bug: 6738383
Change-Id: Ia657d7417cc292746968809f6896a5e790f1394d
2012-09-19 15:40:11 -04:00
Jesse Wilson
85e568e52d Merge: HttpEngine should not attempt to cache proxy CONNECT responses
Original AOSP/libcore commit from Brian Carlstrom:
This fixes an issue where a bad proxy repsonse that included a body
would turn into an IllegalStateException instead of an IOException.

Bug: 6754912

Change-Id: I204ad975820693d6add2780d7b77360463e33710
2012-09-19 15:33:48 -04:00
Jesse Wilson
43a332bca4 Fail gracefully on a 401 response code with no WWW-Authenticate header.
This is more lenient than necessary; the HTTP spec says this:
  10.4.2 401 Unauthorized
     The request requires user authentication. The response MUST include a
     WWW-Authenticate header field (section 14.47) containing a challenge
     applicable to the requested resource.

Not throwing will still cause the request to fail, since the 401
response code triggers an IOException. But this type of failure is
more recoverable and allows the caller to inspect the headers and
response body.
2012-08-15 15:55:48 -04:00
Jesse Wilson
187d3306cb Add a missing copyright header for Libcore. 2012-08-09 14:51:32 -04:00
Jesse Wilson
df2e128cc9 Fill out known issues in the OkHttp README.
This keeps me honest about how my SPDY work is left
to implement.
2012-08-02 16:40:09 -04:00
Jesse Wilson
66220f81e3 Support Froyo.
This makes a bunch of sad changes for compatibility:
 - Using String.length() rather than String.isEmpty()
 - Using String.getBytes(String) rather than String.getBytes(Charset)
 - Using new String(..., String) rather than new String(..., Charset)
 - Avoiding TimeUnit.DAYS

I've tested this and the HTTP tests run perfectly fine on Froyo.
The HTTPS tests time out due to a bug in Froyo that prevents
its TLS library from working as a server. I manually verified
that TLS works as a client without problem.

I also tested this on Gingerbread. It passes all tests except
for testConnectViaHttpProxyToHttpsUsingProxySystemProperty, which
fails because of a bug in Gingerbread's java.net.ProxySelector.

This change introduces caching reflective objects for NPN access.
That'll make clients that make multiple SSL connections slightly
more efficient.
2012-08-01 20:09:14 -04:00
Jesse Wilson
3ff6ca140d Uncomment more HTTPS tests.
Also:
 - bump mockwebserver to current.
 - create a uniform API for creating connections
2012-08-01 14:41:29 -04:00
Jesse Wilson
33a0c620e1 Use bouncy castle to generate certs for TLS.
Because there are no platform APIs to generate certificates,
this needs a third party library (bouncy castle) to do the
heavy lifting.

Each target platform has its own built-in crypto library:
 - The JVM has its own internal crypto library. It uses
   key stores like "JCA".
 - Android has its own internal crypto library that's
   based on bouncy castle. It is repackaged in com.android
   and is not used by this code.

With this change, okhttp brings its own copy of bouncy castle
for cert generation. Once the certificate is generated we're
done with bouncy castle, and use the platform libraries for TLS.
This approach allows us to use one codebase on either platform.
2012-08-01 12:50:04 -04:00