On desktop Java the system default hostname verifier doesn't do
anything. Instead HttpURLConnection does its own hostname verification
and the pluggable verifier simply supplements that.
Android's hostname verifier does everything directly.
This change copies Android's hostname verifier into OkHttp. This way
we can do hostname verification on the desktop, which wasn't possible
previously. It also brings along Android's hostname verifier tests.
Two of these tests fail on desktop Java due to differences in support
for non-ASCII subject alt names. Without our own certificate parsing
we simply live with the difference.
This is currently an underpowered API; in practice the only thing
you can do is disable spdy/3. In the future we may support more
transports (spdy/4, http/2.0) and I don't want to make that an
API change.
We'll likely explode later when attempting to use the socket.
But that will fail with an IOException, unlike this which was
failing with a NullPointerException.
This introduces failure recovery in the output stream. It means
we should be able to recover from any kind of failure that could
be triggered by aggressive connection pooling.
The recovery buffer is 8 KiB. I anticipate this should be more
than enough to detect that an HTTP post is going to a black hole.
Previously we attempted to avoid buffers in some situations
and create aggressive buffers in other situations. This was
a bad policy, and meant we had some subtle performance bugs.
The one that prompted this is that chunked uploads make
separate network writes for the chunk size, chunk, and newline
separators.
This avoids that problem and the corresponding complexity.
Unfortunately getting the MTU isn't a standard API until
Java 6 / Gingerbread. I tested my own networks and saw 1500
in use (for 3G and WiFi) and 1400 (for VPN over WiFi).
We now forbid empty header names, and '\0' characters in names
or values. This should improve the experience for SPDY users,
who will see the failure when they add the header rather than
when the request is made.
This is the first step in a change that'll permit the underlying
socket stream to change out-from-under-you while you're uploading
POST data to a server.
It'll recover from failures writing the request body that occur
within the first N bytes, where N will be determined by the number
of bytes that can be written without positive confirmation.
See https://github.com/square/okhttp/issues/137