History log of /libcore/luni/src/test/java/libcore/java/net/URLConnectionTest.java
Revision Date Author Comments
5dcc3ce8cae450f7800570b2826f5232096159cd 20-Jan-2017 Yi Kong <yikong@google.com> DO NOT MERGE: Remove StuckServer using backlog and tests relying on it

This cherry-pick contains additional changes to remove more references
to StuckServer. The URLConnectionTest#teestConnectTimeouts() test is
suppressed in M via libcore/expectations/brokentests.txt and is not
expected to work. This change should not be merged into N branches.
(Original commit description follows below.)

StuckServer uses kernel implementation details that have changed on
version > 4.4, and causing tests depending on it to fail. Since we can't
find an alternative method to simulate a stuck server without special
permission, and the test itself is not reliable in that they don't fail
on non-stuck servers, remove them from Libcore tests.

Test: CtsLibcoreTestCases
Test: rm -rf out; m -j30 cts
Bug: 32551747
Bug: 35934294
(cherry picked from commit b5c7cd37726154f8da123e1844b5d60a63a60a2c)

Change-Id: I4dd951e9527b5ee5701c0c3ad3eaa0c6f34e8ef7
3ac6579c2666301209dcb116d60de4ba99d86e09 07-Feb-2017 Tobias Thierer <tobiast@google.com> Expand test coverage for disconnect during connect.

Before this CL, URLConnectionTest.testDisconnectDuringConnect()
tested the case of a HttpURLConnection being disconnected from
the CookieManager while connecting via getInputStream(). The
test missed the bug from http://r.android.com/329002 because
that bug only occurred during getOutputStream(), which was not
tested.

After this CL, connection initiation via the follow methods is
now covered:

- getInputStream()
- getOutputStream()
- getResponseCode()
- getResponseMessage()

Note that getErrorStream() is not used because it is documented
not to initiate a connection.

Bug: 34695782
Test: libcore.java.net.URLConnectionTest
Test: Checked that testDisconnectDuringConnect_getInputStream()
would have found the bug in http://r.android.com/329002
(unsubmitted) because it hangs indefinitely when run against
a build that includes that CL.

Change-Id: I6432a69b2cdac177f01e1ba84f32b99322e7c4e1
f25faf811d480064e13b6bd3b8990d432d1a6510 24-Jan-2017 Tobias Thierer <tobiast@google.com> Test URLConnection.disconnect() while connecting

A HttpURLConnection.disconnect() while establishing a connection
could lead to an infinite busy loop. This CL adds a regression
test that exercises this behavior by disconnecting a connection
from inside the CookieHandler; the CookieHandler is consulted
before the actual connection is established, but late enough
to expose the original bug.

Bug: 33763156
Test: URLConnectionTest

Change-Id: I8e92f8830d6d62922a670e41d612d05f5f8d26b7
e1d31ba3ac95b84d12ac24fae5561e3ac1dc66d7 18-Oct-2016 Tobias Thierer <tobiast@google.com> Update URLConnectionTest due to OkHttp bugfix backport

Applies changes to URLConnectionTest required for a corresponding
external/okhttp commit (backporting upstream commit
7ceaa2387f0be853222f5a1496f1f743fa6f8c6d) that fixes two bugs:

(1.) when attempting to tunnel a https connection over http, the host
header now include the :443, like it should. URLConnectionTest
was previously incorrectly asserting that the :443 was missing;
this CL fixes that assertion.
(2.) A bug in connecting to URLs with literal IPv6 addresses has been
fixed. This probably fixes bug 31917371 but this has not yet been
empirically verified. This CL adds a test to guard against
regression.

More details for (2.):

Between commit c358656c8799d30fd422448153e99a5dd37e298a (OkHttp 2.7.0)
and 7ceaa2387f0be853222f5a1496f1f743fa6f8c6d (OkHttp 3.2.0), upstream
OkHttp had a bug where a roundtrip HttpUrl -> host -> HttpUrl would
fail for literal IPv6 address hosts because the getter would return
the address without [] but the setter would only accept it wrapped in [].

Since Android's HttpURLConnection is derived from OkHttp 2.7.5, this
caused a crash when attempting a HttpURLConnection to a literal IPv6 URL.

Test: cts-tradefed run cts -m CtsLibcoreTestCases

Bug: 31917371

Change-Id: Ib4ee91356e7f11fe6f55e1cfd8f319f714a4567a
0b75bdc577edfee86b48265a945f383dffab100f 18-Oct-2016 Tobias Thierer <tobiast@google.com> Test change for drop of insecure TLS protocol version fallback.

HttpsURLConnection no longer attempts insecure TLS protocol version
fallback; this CL changes the test's expectations accordingly.

Bug: 30185435
Bug: 30694151
Test: cts-tradefed run cts -m CtsLibcoreTestCases \
-t libcore.java.net.URLConnectionTest
Test: cts-tradefed run cts -m CtsLibcoreTestCases -a arm64-v8a

Change-Id: I633b6e5de23aec842429ff4310565a714023df5b
694b7112cb230a0db090d2b8d35166c8ffb19e93 18-Oct-2016 Tobias Thierer <tobiast@google.com> Deduplicate code in URLConnectionTest through a helper method.

This is in preparation for a follow-up CL to modify the shared
code.

Test: cts-tradefed run cts -m CtsLibcoreTestCases \
-t libcore.java.net.URLConnectionTest

Change-Id: I89cce7ed18491f343fa4ee9d0ad721d0e7520541
fc575bca313624a7cba20171fbaa625bbc852cd4 17-Oct-2016 Tobias Thierer <tobiast@google.com> DO NOT MERGE Relax N CTS about whether \t is allowed in header values

Android N's Http(s)URLConnection initially forbade '\t' occurring in header
values when it should be allowed; this was fixed by [1] which will be
part of a future Android release. It's permitted for vendors shipping
Android N to apply this fix. Therefore, this CL relaxes CTS for Android N
to allow either behavior. CTS for APIs > 23 will enforce that \t is
allowed.

[1] AOSP commit dcabb633be0f71e720a856e141867d5d23adff93

Test: vogar libcore.java.net.URLConnectionTest#testRequestHeaderValidation
against (a) N (b) a recent build with http://r.android.com/272102
During local testing, temporarily added log statements after the two
asserts to verify that the correct branch was taken on each device.

Bug: 30799514
Change-Id: I4f37246337045574f5ab498d5e98b9c98e6feb74
f14b48abd257bddff050624b51a73440689fc22f 10-Aug-2016 Neil Fuller <nfuller@google.com> Modify tests to reflect different URL encoding for single quote

Single quotes in query parameters in HttpURLConnection changed
behavior between M and N due to upstream changes in OkHttp:
in N, single quotes started being encoded as %27 when present in
query parameters. Unfortunately, this broke several "iTunes remote"
apps: iTunes appears not to support %27 encoding for single quotes
in its DAAP server.

Bug: 30405333
Test: (old) cts test packages android.core.tests.libcore.package.okhttp
and android.core.tests.libcore.package.libcore

(cherry picked from commit 272317c3807fd40b04353354b540a6e2719e93a8)

Change-Id: I3d19dd880202bdc8e5909482e0e6c5167024d410
8f2073552a3aa97ce95f8380f5cab1742d77de91 14-Sep-2016 Chad Brubaker <cbrubaker@google.com> Drop SSLv3 support

The specific API version in the deprecation doc comments will be added
later, for now listed as TBD.

Bug: 30977793
Test: libcore/run-libcore-tests libcore/luni/src/test/java/libcore/javax/net/ssl/*

Change-Id: I5ebe22421589415a9e9065715262e6860b251b2b
3dd11b3751ef70fb35a629e244911b6f08a6afcb 09-Sep-2016 Tobias Thierer <tobiast@google.com> Update test to allow HTAB in HTTP header values

Bug: 30799514

Test: run cts -m CtsLibcoreTestCases -t libcore.java.net.URLConnectionTest

Change-Id: Iba1cb2f52633d112e2d5a79fd11181c53913f6e2
(cherry picked from commit dcabb633be0f71e720a856e141867d5d23adff93)
dcabb633be0f71e720a856e141867d5d23adff93 09-Sep-2016 Tobias Thierer <tobiast@google.com> Update test to allow HTAB in HTTP header values

Bug: 30799514

Test: run cts -m CtsLibcoreTestCases -t libcore.java.net.URLConnectionTest

Change-Id: Iba1cb2f52633d112e2d5a79fd11181c53913f6e2
272317c3807fd40b04353354b540a6e2719e93a8 10-Aug-2016 Neil Fuller <nfuller@google.com> Modify tests to reflect different URL encoding for single quote

Single quotes in query parameters in HttpURLConnection changed
behavior between M and N due to upstream changes in OkHttp:
in N, single quotes started being encoded as %27 when present in
query parameters. Unfortunately, this broke several "iTunes remote"
apps: iTunes appears not to support %27 encoding for single quotes
in its DAAP server.

Bug: 30405333
Test: (old) cts test packages android.core.tests.libcore.package.okhttp
and android.core.tests.libcore.package.libcore
Change-Id: Id87da28529098f639d3be6aed0626d5e3996739d
0f2730efd5fa2dbc1d7cdfb3d33b5b499eddb8c0 29-Jul-2016 Tobias Thierer <tobiast@google.com> Proxy connect: Test expected normalization for URLs with empty path

This is to prevent accidental future changes to this behavior detail.

Test: cts-tradefed run cts -c libcore.java.net.URLConnectionTest

Bug: 30107354
Change-Id: Idd7414c75adb9f76c85a6f5cc31c783faf99dfd9
a9aa7271b66b750a23d102ad82bec50a131889c5 29-Jul-2016 Tobias Thierer <tobiast@google.com> Revert "Regression test for HTTP proxy request line"

This reverts commit c09900cee5e9f518ff8faa954044ba063a5a3e4e.

Change-Id: I2b93e200cb709e2ee2ed18dc90b898a273f8125b
c09900cee5e9f518ff8faa954044ba063a5a3e4e 13-Jul-2016 Tobias Thierer <tobiast@google.com> Regression test for HTTP proxy request line

Adds a test that demonstrates a regression from M in
the HTTP request line when a proxied connection
is made. It only affects URLs with empty paths (i.e. ones
without even a '/' after the host / authority). For
example, on M the request line for a request to
new URL(http://myhost).openConnection() would be:

GET http://myhost HTTP/1.1

but on N, without this change, it would be:

GET http://myhost/ HTTP/1.1

This change reverts to the M behavior.

Bug: 30107354
Bug: 29983827
Change-Id: Iea34afe3beb67022f746aa1b04262e43d841aacd
(cherry picked from commit d1288ce66ea8cb60353e8b1db9d31c8d5cf28127)
d2e78a951c29949bc1cbb691c42ea4202340f138 12-Jul-2016 Tobias Thierer <tobiast@google.com> Regression test for HTTP proxy request line

Adds a test that demonstrates a regression from M in
the HTTP request line when a proxied connection
is made. It only affects URLs with empty paths (i.e. ones
without even a '/' after the host / authority). For
example, on M the request line for a request to
new URL("http://myhost").openConnection() would be:

GET http://myhost HTTP/1.1

but on N, without this change, it would be:

GET http://myhost/ HTTP/1.1

This change reverts to the M behavior.

Bug: 29983827
Change-Id: Ic457230cb9808546e079680b7ace79423ec30544
(cherry picked from commit d1288ce66ea8cb60353e8b1db9d31c8d5cf28127)
d1288ce66ea8cb60353e8b1db9d31c8d5cf28127 12-Jul-2016 Tobias Thierer <tobiast@google.com> Regression test for HTTP proxy request line

Adds a test that demonstrates a regression from M in
the HTTP request line when a proxied connection
is made. It only affects URLs with empty paths (i.e. ones
without even a '/' after the host / authority). For
example, on M the request line for a request to
new URL("http://myhost").openConnection() would be:

GET http://myhost HTTP/1.1

but on N, without this change, it would be:

GET http://myhost/ HTTP/1.1

This change reverts to the M behavior.

Bug: 29983827
Change-Id: Ic457230cb9808546e079680b7ace79423ec30544
4869d3652a33a16bf96ea4685845c5efd337a7e7 04-Jul-2016 Tobias Thierer <tobiast@google.com> Fix URLConnectionTest asserting on the wrong connection

This was introduced in 321eed87d5dc289ea7c212c2fb743f57cc8d5b15.
I've moved the declarations such that other variable for the
other connection is not visible in each block.

Test: run cts -c libcore.java.net.URLConnectionTest

Change-Id: Idc028b7ee19b93b1431518fde1fd5e290ca8a128
321eed87d5dc289ea7c212c2fb743f57cc8d5b15 02-Jun-2016 Tobias Thierer <tobiast@google.com> URLConnectionTest changes for upgrade to OkHttp 2.7.5

These changes are required due to behavioral changes between OkHttp
2.5 and 2.7.5 which we want to accept for AOSP.

- ProxySelectors now get a URL reconstructed from an Address (without
path, query parameters and fragment) rather than the full request
URL. Proxy selection should not usually depend on those values:
DefaultProxySelector cannot be configured to do so;
PacProxySelector probably can be but it'd be a hack. In the absence
of evidence that a significant number of clients rely on such a
hack, we don't want to try to continue to support such behavior.

This behavioral change affects testRedirectWithInvalidUrl() and was
introduced by:
github.com/square/okhttp/commit/c358656c8799d30fd422448153e99a5dd37e298a
which no converts the URL to an Address, then back to a URL that's
delivered to the proxy selector.

- When clients set a Proxy-Authorization header on a request to a
target server (e.g. google.com), previous versions of OkHttp would
have copied that header to the request to the proxy that
established a tunnel. It's unreasonable to support clients that may
rely on this hack because this leaks the Proxy-Authorization header
to the target server. Instead, the Proxy-Authorization header is no
generated on the library level in response to a HTTP 407 Proxy
authentication required status, which requires an additional round
trip.

Similarly, the request to the proxy to set up the tunnel used to
have the User-Agent copied from the initial tunneled request.
Instead, this request's User-Agent is now generated at the library
level through Version.userAgent()

- OkHttp 2.7 has new logic for CertificatePinning that we do not
want to expose through Android's API surface; Android already
has a different implementation of certificate pinning. This CL
adds a sanity check that some Platform logic that OkHttp 2.7.5
uses only for certificate pinning is not invoked in the common
case of Http{s}URLConnections.

More details on these and other changes that didn't affect tests, at:
https://docs.google.com/document/d/19PF3Exd_q32gAGCiRFWRf0Pq_xrIWs-cRViHkFTxJg8/edit

Change-Id: I29277aea0beb8921b3038fefb922b669e01bf106
c3ccff57d6029c0105eb7b100708d0b4883c6160 15-Jun-2016 Tobias Thierer <tobiast@google.com> Fix URLConnectionTest.testConnectTimeouts() by dropping use of Mockito

This test used a Mockito spy to wrap a Socket instance.

It has been failing on AOSP for (at least) weeks due to what
appears like a bug in AOSP's version of Mockito; this bug can lead
to crashes in <clinit>, or the expectations set up on the spy not
working correctly. There is probably some way we could call the
Mockito API to cause the static initializers to run in a different
order and work around the bug, but that would require more
investigation and would likely still be fragile. It doesn't seem
like a good trade-off as long as this only affects isolated cases.

Therefore this CL replaces the spy with an explicit DelegatingSocket
wrapper instead. This avoids the need to investigate a potentially
fragile workaround for the Mockito behavior and increases clarity by
removing the runtime magic.

Bug: 29095428
Change-Id: I46d57f18d9ea157e8a34ce3aead55e0f97de458a
cc4ece7f7ff42e955ac454aed51fc1a8e38abe4c 15-Jun-2016 Tobias Thierer <tobiast@google.com> URLConnectionTest: explicitly close() all the TestSSLContexts

This fixes the test failing from the un-close()d TestSSLContexts
when run on vogar. It doesn't disconnect Http{,s}URLConnections
which the test constructs; these can cause the test to fail
similarly.

The un-close()d contexts caused the test to fail in this manner:

- TestSSLContext.serverSocket.getImpl() instanceof SocksSocketImpl
which extends AbstractPlainSocketImpl.
- That base class in turn uses CloseGuard to enforce (best effort)
that close() is being called.

I originally observed this in vogar on a local branch with an
updated version of OkHttp (2.7.5). I have reproduced it on
AOSP master head but have not reproduced it under cts-tradefed.
Therefore I conclude that there is an additional bug that caused
this test to pass in cts-tradefed when it should have failed; I
have filed bug 29533469 for that.

Change-Id: Ifffeb576b25e07375917dcfc0fdec3c6a9da1be9
5ccc6fa33dd097cb501869d041bef20e45c8d47d 22-Jun-2016 Tobias Thierer <tobiast@google.com> Disable leak detection in URLConnectionTest by extending TestCase.

URLConnectionTest previously extended
AbstractResourceLeakageDetectorTestCase which supplied the
leak detection logic, but that logic was unreliable.

This created more boilerplate and maintenance work in unrelated
tests (which are not focused on leak detection) exceeding the
value it provides:

- The leak detection doesn't work at all under CTS (29533469)
and is very flaky on vogar.
- Currently URLConnectionTest constructs 19 instances of
TestSSLContext and 127 instances of Http(s)URLConnection,
most of which aren't closed/disconnected. Closing all of
these would add excessive boilerplate and pollute the
purpose of these tests.

Tested:
- Test now passes under vogar

Bug: 29533469
Change-Id: I5ef6a51e651b52d975a4cd0dfe4548b83a328c72
41a4ba666dcb6eb5ad498fe133c8022afdf0c935 20-Jun-2016 Tobias Thierer <tobiast@google.com> Revert "URLConnection: Add regression test for b/26769689."

WhatsApp have address the issue so we no longer need this
workaround.

This reverts commit c7b148fd04d1f7de9ced0d56a97014467f86a59b.

Bug: 27353040
Change-Id: Ie4aa1187cc602eb9d2123d58deca9034ee6f2021
9f6ca97141aa1094a447f78a196988a2d52c438f 25-May-2016 Neil Fuller <nfuller@google.com> Relax tests around HTTP header validation

An associated change in OkHttp is relaxing the validation to
make it closer to the behavior in M. This may be temporary and
could be removed in a future release of Android.

Bug: 28867041
Bug: https://code.google.com/p/android/issues/detail?id=210205
(cherry picked from commit e62b4c5890b48404714004e3d8a167479222b87b)

Change-Id: I8e2e58a583979611d78f9de6e24bd3c5a7dc2879
e62b4c5890b48404714004e3d8a167479222b87b 25-May-2016 Neil Fuller <nfuller@google.com> Relax tests around HTTP header validation

An associated change in OkHttp is relaxing the validation to
make it closer to the behavior in M. This may be temporary and
could be removed in a future release of Android.

Bug: 28867041
Bug: https://code.google.com/p/android/issues/detail?id=210205
Change-Id: If45f89578553e38ad455850f7f6bbecd4d51262e
7abb54e68e213538f8df3357a8abce4a6e49b086 05-Apr-2016 Sergio Giro <sgiro@google.com> TestKeyStore: add the ability to set certificate serial numbers

Change URLConnectionTest#testHttpsWithCustomTrustManager
to check for specifically set serial numbers.

As of 5a85130cc3ee3df65c3b263773e3649277b37317, the serial numbers
were being generated randomly, and the test was looking for the
value "1", so the test was broken.

(cherry picked from commit a23e1a7d40a0a85f8eed3a94d6b5714f98180a4e)

Bug: 27987415
Change-Id: I91d2726f362a6aab75edbb6b0d133c00ab774e73
a23e1a7d40a0a85f8eed3a94d6b5714f98180a4e 05-Apr-2016 Sergio Giro <sgiro@google.com> TestKeyStore: add the ability to set certificate serial numbers

Change URLConnectionTest#testHttpsWithCustomTrustManager
to check for specifically set serial numbers.

As of 5a85130cc3ee3df65c3b263773e3649277b37317, the serial numbers
were being generated randomly, and the test was looking for the
value "1", so the test was broken.

Bug: 27987415
Change-Id: I1b6a8dbcb496808266f66ede9503027ab8693861
72d80eec6c1516cf5d9c2b7746b8e32f43eb5107 16-Mar-2016 Neil Fuller <nfuller@google.com> Fix for a runtime exception that could occur with bad redirects

If the redirect address contained an invalid % escape sequence
the request would fail with a runtime exception when the URI
object was created to be passed to ProxySelector. Now the
bad escape sequence is itself escaped. e.g. %0& -> %250&. The
actual request made is unchanged (i.e. it will still contain
%0&).

This is related to changes in external/okhttp.

Bug: 27590872
(cherry picked from commit 7ac2143d73aa65c1d8bdb448ad11ee90a5503a85)

Change-Id: Ic2a5173edb817822c185694d7b64e9e3a2a56b91
7ac2143d73aa65c1d8bdb448ad11ee90a5503a85 16-Mar-2016 Neil Fuller <nfuller@google.com> Fix for a runtime exception that could occur with bad redirects

If the redirect address contained an invalid % escape sequence
the request would fail with a runtime exception when the URI
object was created to be passed to ProxySelector. Now the
bad escape sequence is itself escaped. e.g. %0& -> %250&. The
actual request made is unchanged (i.e. it will still contain
%0&).

This is related to changes in external/okhttp.

Bug: 27590872
Change-Id: I17e00aed33ff77c2f527e78f311c47c7a1c6bdb6
2325d15f20e54996573fe6656320db317fd28103 11-Mar-2016 Sergio Giro <sgiro@google.com> URLConnectionTest: add workaround for \r

Bug: 26422335
Bug: 26889631
Bug: 27606665

(cherry picked from commit 0f1529a265de32624ea0a675bd54b7861859c496)

Change-Id: If90a1f828abf251ad6a8a37c91d91cf17e6d3844
0f1529a265de32624ea0a675bd54b7861859c496 11-Mar-2016 Sergio Giro <sgiro@google.com> URLConnectionTest: add workaround for \r

Bug: 26422335
Bug: 26889631
Bug: 27606665
Change-Id: I88f5c0d456b871eccb36b49eb22e09065258ec02
c7b148fd04d1f7de9ced0d56a97014467f86a59b 15-Feb-2016 Narayan Kamath <narayan@google.com> URLConnection: Add regression test for b/26769689.

IPv6 Literal addresses must appear with surrounding square-brackets.

bug: 26769689
Change-Id: I2bf4c7b73adb8bc2a18a185771fa96742e8579d5
80d240bbef2cab434191cd4e60f45d117dcf8c92 26-Jan-2016 Narayan Kamath <narayan@google.com> URLConnectionTest: Change character mapping expectations.

Track commit 65f07bec4f480898b1c41472234b833497482829
in external/okhttp.

bug: 26455836
bug: 26843611
Change-Id: I71da6d9ebd07aecda7b8ca00e3a850c3ca2e2eca
9a649c0fa7636ffa21786a9c78e43effd3b0f457 12-Jan-2016 Neil Fuller <nfuller@google.com> Tests for request header validation

Includes tests for the workaround added for bug so it is not
lost prematurely.

Bug: 26422335
Change-Id: Ic4bf7511bfa2e323ee05522b5da0a9141364f2e3
8821bc671060ee45e95fb6da6694645c15d7c577 30-Nov-2015 Neil Fuller <nfuller@google.com> Add tests for "follow redirects" behavior

Bug: https://code.google.com/p/android/issues/detail?id=194495
Bug: 25928343
Change-Id: Ic0ff2f94f7de0caa0e5c76be7443b0742cb96977
f6e698d17090d55159e19dd15a74df953f8ade63 01-Sep-2015 Neil Fuller <nfuller@google.com> Changes associated with upstream OkHttp pull

Contains changes related to how bad characters,
particularly in hostnames, are handled. These
are all related to OkHttp's changes to use HttpUrl
internally. URL and URI were previously used and
were less fussy.

The following tests changed:

URLConnectionTest.testHostWithNul():

Hosts with nul (\0) characters in them
throw UnknownHostException instead of
IllegalArgumentException. This is consistent
with the behavior with other bad host names
(like those with spaces which have historically
been treated as UnknownHostException).
A checked exception generally seems better than
an unchecked one.

URLConnectionTest.testUrlWithSpaceInHostViaHttpProxy():

Hosts with spaces in them returned by proxies will
now throw an UnknownHostException, not nothing.
This reverts the behavior to as it was in older
versions of Android (see commit
ac03ce489cbe22905ee525e005d67df0a74ff8de).

URLConnectionTest.testUrlCharacterMapping():

Hosts are now canonicalized to lower-case.
Hosts can now be rejected if the characters are
invalid and outside of supported IDN input codes.

Some characters in paths and queries are no longer
supported, will not be encoded or may be encoded
differently. e.g. '@' is no longer encoded in paths,
'[' is no longer supported.

Bug: 23553256
Bug: 22943975
Change-Id: Icfbcd520fd4e861dc6a0261aba982ee44d9f80cc
a77f9f561d6bf7c2fb789b8065f7017351f1cacd 14-Sep-2015 Neil Fuller <nfuller@google.com> Add additional tests around HttpURLConnection character handling

The upcoming OkHttp upgrade modifies the behavior. It will be
easier to debate / document what is changing by adding tests that
cover the existing behavior.

Bug: 23553256
Change-Id: Ia7e55bfd2685a6914269cfcb7deb95c78fc20db0
26f2557b26ea23326178f029e07a8adbfc27d0bf 08-Sep-2015 Neil Fuller <nfuller@google.com> Fix / unsuppress some URLConnectTests tests

URLConnectionTest.testConnectTimeouts():

The code was creating a URL like:

http://:::<port number>/

because the stuck server returns "::" as the host
address for the wildcard binding done. This URL
is invalid (as it is missing [] around the IPv6
address string).

The test was supposed to check multiple IPs are tried
and the overall timeout is the sum of all the sockets
tried.

Switching StuckServer over to binding to localhost
did not work.

Since the format of the URL does not appear to be the
purpose of this test it is reasonable to change it
before the OkHttp update.

Instead, the test now replaces the the SocketFactory
with one that returns sockets that immediately time
out, avoid the need to nerf the server-side entirely.
The test does not test multiple IPs because (AFAIK) the
tests cannot depend on being able to resolve real
server names. This part of the change involved creating
a hidden method in SocketFactory.

This change adds a new dependency on Mockito so that a
partial mock for Socket can be created.

URLConnectionTest.testServerShutdownInput():

Unsuppress. It should work now.

Bug: 5534202
Bug: 23888521
Change-Id: Iaa57987c59cd6ec1c117f9c90f6ff8ea42d58210
381dc32dba0a02497a29f267f11d074d4fe39bcd 05-Aug-2015 Neil Fuller <nfuller@google.com> Revert "Revert "Changes associated with an OkHttp bad proxy response fix""

This reverts commit 11c3934f61c6c873fd9caae16947285bc0068965.

commit 11c3934f61c6c873fd9caae16947285bc0068965 was incorrectly
merged from lollipop-cts-dev into lollipop-mr1-cts-dev.

Change-Id: I66fa65f08397fb34d6af1cb73d2c0fa7f57ef1b6
11c3934f61c6c873fd9caae16947285bc0068965 17-Jul-2015 Neil Fuller <nfuller@google.com> Revert "Changes associated with an OkHttp bad proxy response fix"

This reverts commit 467a6809cd31cbfa94c326415ff3c441d9b1e8be.

commit 467a6809cd31cbfa94c326415ff3c441d9b1e8be is present in
lollipop-cts-dev but not lollipop-release. This causes the
tests to fail when run against a lollipop-release build.

DO NOT MERGE ANYWHERE

Bug: 22546532
Change-Id: I4582824e94679213f27352e18e7d9bb985954909
e8e4c88dbbc82ca581a899a152a4ff7a13217232 26-Jan-2015 Neil Fuller <nfuller@google.com> Regression tests for Etag handling

Confirm that Etag headers are implemented correctly.

Bug: https://code.google.com/p/android/issues/detail?id=108949
Change-Id: Ida716d089ab1367ae955bb110a450c63ce3a1fa9
d0ebcbd92bd1910c043a5b9cfc0c64f547f17ba6 23-Jan-2015 Neil Fuller <nfuller@google.com> Fix incorrect ordering of assertEquals

Change-Id: I69ddea2941400881ef64309d2470953d25136c1a
764ea3d867b544de457aac2d02327d7b796d4a5c 02-Dec-2014 Neil Fuller <nfuller@google.com> Changes needed to support OkHttp upgrade

Change-Id: Ifd6ed8ab22e7fd5d8cb8c9eb28976291d125c0e4
467a6809cd31cbfa94c326415ff3c441d9b1e8be 05-Nov-2014 Neil Fuller <nfuller@google.com> Changes associated with an OkHttp bad proxy response fix

See the associated external/okhttp that changes the behavior
when encountering a body response from a CONNECT request.

Bug: 6754912
Bug: 18575971

(cherry picked from commit 305af3892e7b62c80ce5888a2514141ea3008ae2)

Change-Id: Idaf1fb5ef7cd3395e1fe26280799321715509e94
4284daf6172310292947bd62540e3007164fdde9 27-Nov-2014 Narayan Kamath <narayan@google.com> Add a simple test for "last-modified" headers.

Tests that getLastModified() == getHeaderFieldDate("Last-Modified").
This was lost in commit d8ce757d85ba665fa61d35e25e03c4de16c0f4c6.

Change-Id: I0dd1e7091b690d70161f33b8dfe3d0cee7ee4c9b
d8ce757d85ba665fa61d35e25e03c4de16c0f4c6 22-Nov-2014 Aaron Whyte <awhyte@google.com> Fix URLConnectionTest for devices without full internet access.

This removes two bad tests that are covered elsewhere, using
mocks.

test_getContentEncoding() was hitting http://www.amazon.com, to see
if a URLConnection getter was working. That getter is now tested in
libcore/luni/src/test/java/libcore/java/net/URLConnectionTest.java,
in testClientConfiguredGzipContentEncoding().

test_getLastModified() was hitting
http://www.php.net/manual/en/function.explode.php, to see if
getHeaderFieldDate was working for Last-Modified. That getter is
better tested in test_getHeaderFieldDateLjava_lang_StringJ(), in the
same file.

Bug:18480776

(cherry picked from commit 939e6a1aceff448445928ad5d815479e84e84383)

Change-Id: Ia01fd59809683317271017364179e1843c149e65
939e6a1aceff448445928ad5d815479e84e84383 22-Nov-2014 Aaron Whyte <awhyte@google.com> Fix URLConnectionTest for devices without full internet access.

This removes two bad tests that are covered elsewhere, using
mocks.

test_getContentEncoding() was hitting http://www.amazon.com, to see
if a URLConnection getter was working. That getter is now tested in
libcore/luni/src/test/java/libcore/java/net/URLConnectionTest.java,
in testClientConfiguredGzipContentEncoding().

test_getLastModified() was hitting
http://www.php.net/manual/en/function.explode.php, to see if
getHeaderFieldDate was working for Last-Modified. That getter is
better tested in test_getHeaderFieldDateLjava_lang_StringJ(), in the
same file.

Bug:18480776
Change-Id: I21ffc5c9c72eb4379478c11687d197dab176a851
5df4f660e3a115d450633c6c1e3a5220d3a9708d 12-Nov-2014 Neil Fuller <nfuller@google.com> Test changes for the HttpURLConnection fallback strategy

The fallback strategy has changed to perform a multi-level
fallback, rather than trying
"default enabled protocols" and "SSLv3, if enabled".
Fallback now includes attempts leading with TLSv1.2, TLSv1.1,
TLSv1 and SSLv3 if they are enabled.

Bug: 13228108
Change-Id: I6361a4103461bffd50bf7849fe92cb7e384a1930
ce0ccd0299a8c23666a630afa4e440963e457615 12-Nov-2014 Neil Fuller <nfuller@google.com> Fixes associated with OkHttp fallback changes

OkHttp now selects from the available, enabled protocols rather
than forcing SSLv3 to be on. Without this change, if SSLv3 is not
part of the protocols enabled by default on the device this test
would fail.

Bug: 13228108
Change-Id: I5b89a73af9cf729dbf892f958fa318daa4109ff4
1d99fe5087ee6a512bb2d38ce5b0f6e3bbc2ea79 12-Nov-2014 Neil Fuller <nfuller@google.com> Improve tests for TLS fallback.

This is a small improvement over the changes that were submitted to
Android when TLS_FALLBACK_SCSV was introduced.

Previously the test would cripple the server to use a low quality
protocol so the TLS_FALLBACK_SCSV check would pass for all connection
attempts.

This change modifies that approach. Instead it introduces a test
client socket factory that ignores any attempt to set the
TLS_FALLBACK_SCSV cipher. This means that the server will
not attempt to enforce the fallback check.

The ideal solution would be to disable TLS_FALLBACK_SCSV checks in
the MockWebServer for the tests that are supposed to simulate servers
that do not perform TLS_FALLBACK_SCSV checks. However, we do not
currently have a mechanism to do this.

This change also adjusts tests that test fallback to explicitly
enable SSLv3 for server-side socket factories. The Android default
was changed to disable SSLv3 (though it is still supported). An
up-coming change should remove the need for this.

Change-Id: I5bd6c2659ebbb8eff729f75b5208ca414d70e385
305af3892e7b62c80ce5888a2514141ea3008ae2 05-Nov-2014 Neil Fuller <nfuller@google.com> Changes associated with an OkHttp bad proxy response fix

See the associated external/okhttp that changes the behavior
when encountering a body response from a CONNECT request.

Bug: 6754912
Change-Id: I20553dda374cd4903dc83cceb8d203662319571e
25f20231a8e43b92d7128aa57e52a1d4d8e90fea 24-Oct-2014 Neil Fuller <nfuller@google.com> Update tests for HttpURLConnection.disconnect() changes

These changes are associated with external/mockwebserver
and external/okhttp commits.

URLConnectionTest#testDisconnectedConnection
- Affected by the bug fix.

URLConnectionTest#testSslFallback
- Affected by changes to MockWebServer. Handshake failures
are no longer queued/recorded.

HttpsURLConnectionTest
- API changes related to MockWebServer.

Bug: 18083851
(cherry pick from commit 246e740c85527012891ac3b07cb658dd2fcabc87)

Change-Id: Ia7fe3961b1bc28ef2efa69bbf59a16bc54d07063
246e740c85527012891ac3b07cb658dd2fcabc87 24-Oct-2014 Neil Fuller <nfuller@google.com> Update tests for HttpURLConnection.disconnect() changes

These changes are associated with external/mockwebserver
and external/okhttp commits.

URLConnectionTest#testDisconnectedConnection
- Affected by the bug fix.

URLConnectionTest#testSslFallback
- Affected by changes to MockWebServer. Handshake failures
are no longer queued/recorded.

HttpsURLConnectionTest
- API changes related to MockWebServer.

Bug: 18083851
Change-Id: Iec211a1e1e713623ccc8f8ca1de79833abe2f961
7618d0b86f53ada960898d531e53e1980914539f 03-Oct-2014 Neil Fuller <nfuller@google.com> Changes to support TLS fallback SCSV

Fixes for tests.

(cherry picked from commit 957ec8b09833e1c2f2c21380e53c13c9962e6b3e)

Change-Id: I848b6c84524aabffb1dc71c00aae8f3e9b741ef0
6c9609af5f63a759bd50b5f6586f6f52502b4f93 07-Oct-2014 Neil Fuller <nfuller@google.com> Add support for TLS_FALLBACK_SCSV

Backport of commits:

external/conscrypt: 8d7e23e117da591a8d48e6bcda9ed6f58ff1a375
libcore: e6a6e935e98f426c7000b2bf4086f87101f4441c
libcore: 957ec8b09833e1c2f2c21380e53c13c9962e6b3e

Plus additional changes to:
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
luni/src/test/java/libcore/java/net/URLConnectionTest.java
luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
support/src/test/java/libcore/java/security/StandardNames.java

to account for KitKat differences.

Bug: 17750026
Change-Id: Ic6e9474275bc3ffec3b5c2d6df1f8d6ffe77bff8
865c83f8383f03d545217c35d9140a4627a74406 07-Oct-2014 Neil Fuller <nfuller@google.com> Add support for TLS_FALLBACK_SCSV

Backport of commits:

external/conscrypt: 8d7e23e117da591a8d48e6bcda9ed6f58ff1a375
libcore: e6a6e935e98f426c7000b2bf4086f87101f4441c
libcore: 957ec8b09833e1c2f2c21380e53c13c9962e6b3e

Plus additional changes to:
luni/src/main/java/libcore/net/http/HttpConnection.java
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLServerSocketImpl.java
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java
luni/src/test/java/libcore/java/net/URLConnectionTest.java
luni/src/test/java/org/apache/harmony/xnet/provider/jsse/CipherSuiteTest.java
support/src/test/java/libcore/java/security/StandardNames.java

to account for JellyBean differences.

Bug: 17750026
Change-Id: I7b60b1260fa0b275631ce9987168c7b5fc7ca138
957ec8b09833e1c2f2c21380e53c13c9962e6b3e 03-Oct-2014 Neil Fuller <nfuller@google.com> Changes to support TLS fallback SCSV

Fixes for tests.

Change-Id: Ie8e01e8fa654afd6b6c9f30ec46552d46326e467
fa023837b8be8e9eda6008398648b4c9b1aa1e3e 28-May-2014 Neil Fuller <nfuller@google.com> Fix for flakiness in URLConnectionTest.testServerShutdownOutput

Flakiness reported by Junjie.Hu <junjie.hu@mediatek.com>
This fix relies on changes to MockWebServer to provide
deterministic ordering of responses.

Change-Id: I4f296fa2f8d227876f52c69e22001f4e0d7b4ffd
a6f350c645dbb66d68cc2b03afb8f2eeaa88fbba 28-Feb-2014 Paul Duffin <paulduffin@google.com> Improve detection of CloseGuard protected resource leakage

* Add CloseGuardMonitor to intercept and collate CloseGuard reports and if
necessary throw an exception listing the resource leaks.
* Add ResourceLeakageDetector to abstract away the CloseGuardMonitor which will
not work on RI.
* Add AbstractResourceLeakageDetectorTestCase as a base class for tests
that need to detect resource leaks, in future this could be handled by
modifications to Cts and Vogar test runners.
* Remove CloseGuardTester and its sole usage in ProcessBuilderTest.
* Remove CloseGuardGuard from within URLConnectionTest
* Change ZipFileTest, ProcessBuilderTest, URLConnectionTest to use new
mechanism, fix issues that are identified and do some cleanup/remove
duplicated code.

Bug: https://code.google.com/p/android/issues/detail?id=66383
Change-Id: Id026dbb6bc66091a15f07329e6371cd0d1f32cf5
ac03ce489cbe22905ee525e005d67df0a74ff8de 06-Mar-2014 Neil Fuller <nfuller@google.com> Relax testUrlWithSpaceInHostViaHttpProxy test

This is for the new OkHttp version. The older
version detected the URL is invalid on Android. The newer
version does not. The correct behavior is undefined and
this test was added to prove that NullPointerException is
not thrown, which it will still test for.

Change-Id: Ibbaaf006982eba9de2d3751c6ee302dd28f7786f
9749b98a92fbf2bfe095b7ec884789f62ab293d8 03-Mar-2014 Neil Fuller <nfuller@google.com> Fix URLConnectionTest#testSetChunkedStreamingMode

Commit 60f79119fd7e37c459a96888594f90d86bab5535 broke it
- until OkHttp is upgraded the chunkLength is obeyed.
The argument needs to be >= 8 for the test to pass.

Change-Id: I22acaa4a56fdbd22abc075a2300cf53e303ec791
60f79119fd7e37c459a96888594f90d86bab5535 27-Feb-2014 Neil Fuller <nfuller@google.com> Tests and docs updates for OkHttp update.

OkHttp has made various changes. This fixes the known
breakages before the update is applied.

1) Chunk length is no longer honored exactly. The
API docs have been updated to reflect this.

2) testConnectViaHttpsWithSSLFallback simulated an SSL
handshake failure by closing the socket. This is no longer
sufficient to trigger the fallback behavior after OkHttp change
46a0852. testSslFallback tests an actual handshake failure and
provides coverage. testConnectViaHttpsWithSSLFallback
has therefore been removed.

3) testRetryableRequestBodyAfterBrokenConnection is similar to
testConnectViaHttpsWithSSLFallback. Previously it passed because
of the SSL fallback behavior. That fallback no longer happens.
It is possible this was actually supposed to be checking the
internal RetryableOutputStream. Now OkHttp does not retry
connections after the connection is made it is not possible
to test the request body is "replayed" to the server.

4) testNonRetryableRequestBodyAfterBrokenConnection: Related to
3 above. It was testing that fixed length request bodies are not
retryable. This test continues to pass with OkHttp but only
because it fails to retry generally, not because of the request
body and therefore the test is misleading.

Change-Id: If430bce75ad5b2fd5ace38d0f65d9c4af56b88df
9de94e4aaa6de951d1c7ca08d137d57b36d24fa3 19-Dec-2013 Alex Klyubin <klyubin@google.com> Fix test breakages due to TLSv1.2 enabled and FS preferred.

Bug: 11220570
Change-Id: Ic918e806ae1d8ea9b98c690cfabd9c3245886525
ec33de3303760e5ba31bd6d0e6b46d5681c123dc 04-Nov-2013 Narayan Kamath <narayan@google.com> Add a test for lower case auth scheme handling.

bug: 11473660

(Cherry picked from d87ee0f7b587bf19b7bf4c047aa6e5ab0c5045de)

Change-Id: I42fed52e5fdfe0a0ec99dfc8f77330b37a82f772
d87ee0f7b587bf19b7bf4c047aa6e5ab0c5045de 04-Nov-2013 Narayan Kamath <narayan@google.com> Add a test for lower case auth scheme handling.

bug: 11473660
Change-Id: I21cbff82508921b34b45ce2d62bfc959f6ca4b01
157b95d87eba99a4804aca480ced9c8b99637dc7 21-Aug-2013 Narayan Kamath <narayan@google.com> Update authentication tests.

Test for multiple schemes and multiple auth headers, but
insist that one of schemes is "Basic".

Fixes CTS tests
URLConnectionTest#testAuthenticateWithCommaSeparatedAuthenticationMethods
URLConnectionTest#testAuthenticateWithMultipleAuthenticationHeaders

(cherry picked from d1b438d58c2177c9cebcc3b72df13ac9b7c46e91)

bug: 10211309

Change-Id: Icdc30a5c52cc2c8e3b65abe402732658d4308a88
0136437c9973615e02f4a22b622399d6a7063932 21-Aug-2013 Narayan Kamath <narayan@google.com> Test that timeouts are respected on recycled connections.

This is a renamed version of testGetKeepAlive, which wasn't
testing very much in its old form.

(cherry picked from 35e58c073df4a45345e89fe8f4d0f77bf7df878)

bug: 10211309

Change-Id: I08c46f577741817b7de714d362f3426d17984042
8a1e42f2cfcb3cab8cfba7a572d68c534598d627 21-Aug-2013 Narayan Kamath <narayan@google.com> Fix tests dealing with retryable bodies.

Test them in a slightly more robust manner.
- Rely on the fallback from Modern TLS for the retry, instead
of a fallback due to a closed socket.
- Use mode DISCONNECT_AFTER_READING_RESPONSE to make sure the
response is consumed before being discarded.

(cherry picked from 2f1d4ee69ef9dc2eb0d9da37ba4ef1c6089d595e)

bug: 10211309

Change-Id: I8227148e1fc04b7557a41ee6485ffe98efb77ace
d1b438d58c2177c9cebcc3b72df13ac9b7c46e91 21-Aug-2013 Narayan Kamath <narayan@google.com> Update authentication tests.

Test for multiple schemes and multiple auth headers, but
insist that one of schemes is "Basic".

Fixes CTS tests
URLConnectionTest#testAuthenticateWithCommaSeparatedAuthenticationMethods
URLConnectionTest#testAuthenticateWithMultipleAuthenticationHeaders

Change-Id: Icdc30a5c52cc2c8e3b65abe402732658d4308a88
35e58c073df4a45345e89fe8f4d0f77bf7df8787 21-Aug-2013 Narayan Kamath <narayan@google.com> Test that timeouts are respected on recycled connections.

This is a renamed version of testGetKeepAlive, which wasn't
testing very much in its old form.

Change-Id: I08c46f577741817b7de714d362f3426d17984042
2f1d4ee69ef9dc2eb0d9da37ba4ef1c6089d595e 21-Aug-2013 Narayan Kamath <narayan@google.com> Fix tests dealing with retryable bodies.

Test them in a slightly more robust manner.
- Rely on the fallback from Modern TLS for the retry, instead
of a fallback due to a closed socket.
- Use mode DISCONNECT_AFTER_READING_RESPONSE to make sure the
response is consumed before being discarded.

Change-Id: I8227148e1fc04b7557a41ee6485ffe98efb77ace
cc440f43ee5cee8b52d6ad86c6926d1189aad37b 20-Aug-2013 Narayan Kamath <narayan@google.com> Track changes to MockWebServer

Track changes in ag/63871 which add bookkeeping requests
to the request queue.

(cherry picked from b27031a36bbb3c64ad0672553122dcebb17c89)

bug: 10211309

Change-Id: I8093bda336950846dafaaba2acaace8ee52713d6
3778c428ec5bc08881d8cc8057d79027648b327c 20-Aug-2013 Narayan Kamath <narayan@google.com> Update test exercising broken proxy behaviour.

The test must account for the fact that the connection
will be retried with TLS_MODE_COMPATIBLE if the first
attempt throws an exception.

It's also worth noting that MockWebServer does not
deal with abrupt client disconnections in a particularly
graceful manner (but that does not affect the test,
and I'll address it in a follow up).

(cherry picked from bfdb88fab84756703e01e9b43808a406bdd)

bug: 10211309

Change-Id: I5bf8a8e890df4146ecd0606e50c5a616434fd883
b27031a36bbb3c64ad0672553122dcebb17c89f3 20-Aug-2013 Narayan Kamath <narayan@google.com> Track changes to MockWebServer

Track changes in ag/63871 which add bookkeeping requests
to the request queue.

Change-Id: I8093bda336950846dafaaba2acaace8ee52713d6
bfdb88fab84756703e01e9b43808a406bdd48755 20-Aug-2013 Narayan Kamath <narayan@google.com> Update test exercising broken proxy behaviour.

The test must account for the fact that the connection
will be retried with TLS_MODE_COMPATIBLE if the first
attempt throws an exception.

It's also worth noting that MockWebServer does not
deal with abrupt client disconnections in a particularly
graceful manner (but that does not affect the test,
and I'll address it in a follow up).

Change-Id: I5bf8a8e890df4146ecd0606e50c5a616434fd883
3d849f3d37a0b7c4c8b7b0fa5a285289ed99a309 15-Aug-2013 Narayan Kamath <narayan@google.com> Update URLConnection#testLenientUrlToUriNul.

Our earlier behaviour was somewhat broken. We'd accept
hosts with \u0000 in them, and then produce a request with
a bad Host header. We now fail on such requests, so add a
unit test to exercise that new behaviour.

The ideal behaviour might be to be lenient and escape characters
that we don't like. (This would involve using the URI from
URL#toUriLenient to populate the Host header. I attempted that
but it has the side effect of introducing a new set of
incompatibilities).

(cherry picked from aafc934e9e3b5afce7c54162654720fad80)

bug: 10211309

Change-Id: I38a0d39124dc5ca766a6e963e72b0250440e82ee
aafc934e9e3b5afce7c54162654720fad80a733e 15-Aug-2013 Narayan Kamath <narayan@google.com> Update URLConnection#testLenientUrlToUriNul.

Our earlier behaviour was somewhat broken. We'd accept
hosts with \u0000 in them, and then produce a request with
a bad Host header. We now fail on such requests, so add a
unit test to exercise that new behaviour.

The ideal behaviour might be to be lenient and escape characters
that we don't like. (This would involve using the URI from
URL#toUriLenient to populate the Host header. I attempted that
but it has the side effect of introducing a new set of
incompatibilities).

Change-Id: I38a0d39124dc5ca766a6e963e72b0250440e82ee
0df27a0c1f64c589a1df3eb2d94c75aea90cdf4a 14-Aug-2013 Narayan Kamath <narayan@google.com> Fix URLConnectionTest#testConnectTimeouts.

Use StuckServer correctly. When StuckServer isn't
in blocking mode, its local socket address isn't 127.0.0.1.

Attempting to connect to localhost will then throw a
SocketException (ECONNREFUSED) instead of a
SocketTimeoutException.

(cherry picked from commit bf1a9e10eefd28bb3a989df20b4a57c745fb3670)

Bug: 10211309
Change-Id: I8aaab598d043b893e73fab9055082fa420cfb9cd
a37fb255a1993e835eea8c934205b1e568a1271c 14-Aug-2013 Narayan Kamath <narayan@google.com> Fix URLConnectionTest#testConnectTimeouts.

Use StuckServer correctly. When StuckServer isn't
in blocking mode, its local socket address isn't 127.0.0.1.

Attempting to connect to localhost will then throw a
SocketException (ECONNREFUSED) instead of a
SocketTimeoutException.

(cherry picked from commit bf1a9e10eefd28bb3a989df20b4a57c745fb3670)

Bug: 10211309
Change-Id: I8aaab598d043b893e73fab9055082fa420cfb9cd
bf1a9e10eefd28bb3a989df20b4a57c745fb3670 14-Aug-2013 Narayan Kamath <narayan@google.com> Fix URLConnectionTest#testConnectTimeouts.

Use StuckServer correctly. When StuckServer isn't
in blocking mode, its local socket address isn't 127.0.0.1.

Attempting to connect to localhost will then throw a
SocketException (ECONNREFUSED) instead of a
SocketTimeoutException.

Change-Id: I8ea1af80996894a5951e53f9c31e828bbbca3628
8c213bcc2aadb8249d683312505f1068ae74f1a8 12-Jun-2013 Narayan Kamath <narayan@google.com> Fix URLConnectionTest after latest okhttp update.

I've observed 14 failing tests both before and after
the update.

Change-Id: I40dfd9efe35ed03d89b38b030d3c7b6558b247e2
d4781a20611fd0424aede028c139bfdbaea5677b 06-May-2013 Brian Carlstrom <bdc@google.com> Make it clearer that a new MockWebServer is created for each test run

Change-Id: Ib3ce11f42d19688fe00b7d057eece25567fccea2
2503556d17b28c7b4e6e514540a77df1627857d0 30-Mar-2013 jwilson <jwilson@squareup.com> Switch to OkHttp as URL's preferred HTTP implementation.

Change-Id: Id724b75dd78b68ed00f5db4989c4070896996ec0
0e1afa1091f74a6228c01d8c7a8eebf001efdc57 13-Oct-2012 Elliott Hughes <enh@google.com> Fix ConcurrentCloseTest flakiness.

We can't rely on consuming all the listen(2) backlog. For the tests we've
seen fail because they sometimes connect rather than time out, switch to
an unroutable address.

(cherry-pick of babccbf9e429c4c78aca24c205825ceaaf7d3f37.)

Bug: 6971145
Change-Id: Ibfa412ff1ad7da7e63842d0162cc67a706e2b27e
babccbf9e429c4c78aca24c205825ceaaf7d3f37 13-Oct-2012 Elliott Hughes <enh@google.com> Fix ConcurrentCloseTest flakiness.

We can't rely on consuming all the listen(2) backlog. For the tests we've
seen fail because they sometimes connect rather than time out, switch to
an unroutable address.

Bug: 6971145
Change-Id: I259d31b1a15123bcd78c36849d5ed863d392ac20
b11e44a402eb0f9c5da1f7482fc1eabdd9adff47 20-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug in tunnel construction and 'Connection: close' headers.

Based on https://github.com/square/okhttp/pull/30
(git fetch git://github.com/square/okhttp.git && git cherry-pick -x b8c51dc5bdc89d5487cbc110d6fe40389de16480)

Bug: http://code.google.com/p/android/issues/detail?id=37221
Bug: 7291446

(cherry picked from commit 4bedacd569fed2db56c518ed239412b3fe32245e)

Change-Id: I68c55e9259db91dbccca30824c00726094570304
4bedacd569fed2db56c518ed239412b3fe32245e 20-Sep-2012 Jesse Wilson <jwilson@squareup.com> Fix a bug in tunnel construction and 'Connection: close' headers.

Based on https://github.com/square/okhttp/pull/30
(git fetch git://github.com/square/okhttp.git && git cherry-pick -x b8c51dc5bdc89d5487cbc110d6fe40389de16480)

Bug: http://code.google.com/p/android/issues/detail?id=37221
Change-Id: I5bed33d9ab16002aa38c2f729fa14a2022485469
6d41a7cc3cb4cc684c8bece69ddc55954812ad6e 24-Sep-2012 Narayan Kamath <narayan@google.com> Strip content length in requests with "transparent" gzip handling.

We need to strip both the Content-Length and the Content-Encoding
for such requests. In such requests, it will be the length of the
compressed response. We hide the fact that compression is taking place
from clients, so we shouldn't give them the content length either.

(cherry picked from commit f9d60aed414ae21811a6488f603333517f257b22)

Change-Id: Ic2776ecf020c34b1c55e2fb7e2f0728e553187a0
f9d60aed414ae21811a6488f603333517f257b22 24-Sep-2012 Narayan Kamath <narayan@google.com> Strip content length in requests with "transparent" gzip handling.

We need to strip both the Content-Length and the Content-Encoding
for such requests. In such requests, it will be the length of the
compressed response. We hide the fact that compression is taking place
from clients, so we shouldn't give them the content length either.

Change-Id: I80713ab33143945c5e2656f478d83cc9e60226a8
3edd28a92fc86a1260347d0995e65a815d73bbbe 16-Apr-2012 Mattias Petersson <mattias.petersson@sonymobile.com> Fix problem with Runtime.runFinalization()

This is a fix for a problem with runFinalization(). The
problem was that all FinalizerReferences to objects that had
not yet been garbage collected were lost when calling this
function. When a FinalizerReference was lost, it is was not
possible to call the finalize() method when the object
was garbage collected.

The result was that finalizers was sometimes never
called, which typically lead to memory leaks.

Also stop synchronizing on the class itself; use a private
lock instead.

Bug: 6907299
Bug: 5462944 # Synchronization on FinalizerReference.class
Change-Id: Ief515edbb5a1823c06d7371415d131165baef7f2
8155888a2c4e7cc28596deec28433e1984cfaf11 25-Jul-2012 Brian Carlstrom <bdc@google.com> Fix HttpURLConnection CloseGuard warning due to lack of close on GZIPInputStream

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
4ec2d0dea800397fb32227e0631246f4d2a73191 29-Jun-2012 Brian Carlstrom <bdc@google.com> HttpEngine should not attempt to cache proxy CONNECT responses

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
deb26711801f9bfafcd5cad20963b3c3913404fd 04-Apr-2012 Elliott Hughes <enh@google.com> Add a test for an already-fixed publicly-reported bug.

Bug: http://code.google.com/p/android/issues/detail?id=28095
Change-Id: I26ff2834becce6f51e668ec71b4e5050b15f06cd
0731920fdf845358cc13ce78292f9e80e143f915 28-Mar-2012 Brian Carlstrom <bdc@google.com> Disable TLSv1.1 and TLSv1.2 by default

Bug: 6234791

Change-Id: I5d829211c9e1d5672fc96e42ef603c53d789e695
3d74b4bec8543e6e3f89eafe3afe0925f3a69f01 28-Mar-2012 Brian Carlstrom <bdc@google.com> Disable TLSv1.1 and TLSv1.2 by default

Bug: 6234791

Change-Id: I5d829211c9e1d5672fc96e42ef603c53d789e695
3e6dd45baa0d7f9b4fa06f4ade76e088b59cc7bf 16-Mar-2012 Brian Carlstrom <bdc@google.com> Tracking openssl-1.0.1

Bug: 6168278

Change-Id: I240d2cbc91f616fd486efc5203e2221c9896d90f
df29c7dc69965462cd19de8910b04c8cb463e57f 15-Feb-2012 Jesse Wilson <jessewilson@google.com> Don't attempt to parse an HTTP response body on HEAD requests.

Previously if the response had a Content-Length or Transfer-Encoding
header we assumed it had a body. This was untrue of HEAD requests.
This is not a regression.

Bug: http://code.google.com/p/android/issues/detail?id=24672
Change-Id: I264db2014e681a6f8e93cd40b0f1640c95103d21
a468471e8ccc2f642d5b2ae3c75873a74267ece2 26-Jan-2012 Jesse Wilson <jessewilson@google.com> Don't throw needlessly when returning the CacheResponse.

We were throwing under the premise that we'd always have
response headers before we had a cached body. But when the
user calls connect() we'll have queried the cache but we
won't necessarily have response headers from the server yet.
That's because connect() doesn't require a response to be ready.

Bug: http://b/5920659
Cherry-picked from: I9d69b44b5be3d0e29f14d8b83781f6e65c67582a

Change-Id: Ia403b42ddc9783fd1456164f4b7350da3ce80566
fa5e8dfe3c7ed144b0fbe69091628dedd6a3b961 21-Dec-2011 Jesse Wilson <jessewilson@google.com> Don't reuse an SSL socket if the socket factory has changed.

Bug: http://b/3042192
Change-Id: Iaa9deb69058afcca4ab79ca6ba745c55d1e9321a
abe4e615f473b387b1c00a738062a7c428f05a33 20-Dec-2011 Jesse Wilson <jessewilson@google.com> Unit test SSL fallback.

Bug: http://b/4462288
Change-Id: I9a29c70b24f235df15aa9a763ae5217e10e42f83
5757cb35ad2e58d7accb7f5d3db6f2d5e72f097d 16-Dec-2011 Jesse Wilson <jessewilson@google.com> Support multiple challenges for HTTP authentication.

This fixes the problem reported in the bug, but we still need
to give attention to the digest scheme. Currently we can't do
Basic auth if the HTTP response contains both a Digest challenge
and a Basic challenge!

Bug: http://code.google.com/p/android/issues/detail?id=19081
Change-Id: Ifffb307678c2afa0db1d50c1ef5fc49ec7769306
b2b02ac6cd42a69463fd172531aa1f9b9bb887a8 15-Dec-2011 Jesse Wilson <jessewilson@google.com> Change the way we cope with stale pooled connections.

Previously we'd attempt to detect if a connection was stale by
probing it. This was expensive (it relied on catching a 1-millisecond
read timing out with a SocketTimeoutException), and racy. If the
recycled connection was stale, the application would have to catch
the failure and retry.

The new approach is to try the stale connection directly and to recover
if that connection fails. This is simpler and avoids the isStale
heuristics.

This fixes some flakiness in URLConnectionTest tests like
testServerShutdownOutput and testServerClosesOutput.

Bug: http://b/2974888
Change-Id: I1f1711c0a6855f99e6ff9c348790740117c7ffb9
2d9fa917aae6a6da38e9d1eda05841ffdf8855bb 15-Dec-2011 Jesse Wilson <jessewilson@google.com> Document the effect on timeouts of having both IPv4 and IPv6 addresses

Bug: http://b/3441111

Change-Id: Ib4c2e3e0d8d86eb5eb77cf92a0814c7444fd153f
0613de89655e481fa610bfd4f1bcaeeae3272205 14-Dec-2011 Jesse Wilson <jessewilson@google.com> Document that disconnect() doesn't release sockets.

We could make disconnect() work, but it's a lot of complexity for
little gain. The core problem is that by the time the user calls
disconnect(), the connection has already been pooled. On the RI,
disconnect() will close a socket connection if it hasn't yet been
removed from the pool. Our pooling always-on or always-off behavior
is simpler and more predictable.

Bug: http://b/4148042
Change-Id: I61ef2ccb898f3ffaa08cedc70ee9e728fc1889b9
d0d626655f1d452070d3116678037e8759f807f4 10-Nov-2011 Jesse Wilson <jessewilson@google.com> Don't NullPointerException when a URL contains a space.

We end up creating a URI of http://and%20roid which has no host
name part because and%20roid is not a valid host name. It's unclear
where the best place to fail is. This is consistent with the RI
which doesn't fail until it attempts to connect.

Bug: http://code.google.com/p/android/issues/detail?id=16895
Change-Id: Ifa4dc3c651f4627e27622ed5cedfa820f9a35358
25a753691a80186cd4d7086b12c0e52225d95897 30-Sep-2011 Jesse Wilson <jessewilson@google.com> Fix chunked input stream's available() method to never return -1.

Change-Id: I6ea268e469675ef890010282dbe35ed5838cca73
http://code.google.com/p/android/issues/detail?id=20442
09336c914b4fc813e493acc82469b9ad89fd8694 07-Jun-2011 Jesse Wilson <jessewilson@google.com> Use external/mockwebserver in libcore

Change-Id: I4dac34f88b23484643bce31e5f25ac6eb1fea426
5292410e4ebf7fb5149eefd2f52fcb94c46690a6 24-May-2011 Jesse Wilson <jessewilson@google.com> Rewrite parsing for java.net.URL.

This fixes many broken cases on handling relative URLs.

We normalize all URLs by default. This will result
in more URL equality than before. Previously the URLs
http://android.com/a/../ and http://android.com/ were not
equal; now they are equal.

Change-Id: I8cf7be2e42eeb1386520be2698d8f14e0a55decb
http://b/4361656
ec6163ceac64902ccde3259e8a426f0f9ad6a88c 20-May-2011 Jesse Wilson <jessewilson@google.com> Add test cases inspired by Jetty-dependent Harmony tests.

Change-Id: Id8288e0524b64255c5d9808d3f5582708211d96b
1e518e80aeb8c27d49d51e5c69173d3e08fb9ec7 09-May-2011 Jesse Wilson <jessewilson@google.com> Deduplicate a unit test merged in from upstream.

Change-Id: Ia5f4ad1753fa6bb2ce4dd5fdf4c978e1ff0ffa80
http://b/4188137
68b8820c82a524388a32501fa9b423d77b4b73b6 09-May-2011 Jesse Wilson <jessewilson@google.com> Deduplicate a test that was duplicated by an automerge.

Change-Id: Id8ef04b21c1132db224c69437428bbe4f5890a6a
http://b/4188137
5e8b5a55eda914b67c62b4e77152922d5c77eb68 29-Mar-2011 Jesse Wilson <jessewilson@google.com> Don't read from the delegate stream after we close it.

Honeycomb MR2 patch cherry-picked from bc4c79c6a2059003f695f7ad204de36700e8d701

Change-Id: Ib379595a1e6b2ed3b16d4d82c744b00e4b576c51
http://b/4188137
c996149b500fc4825156106554457fe2394ae087 06-May-2011 Jesse Wilson <jessewilson@google.com> Fix proxy+HTTPS to handle authentication requests from the proxy.

Previously I'd introduced a bug by assuming that CONNECT
responses would always be successful.

Change-Id: Iaf0caf67f52154f6951a20284c75db0090843b99
http://b/4188137
d742d7fc7f0593eb8c6e4ac9dd4c0f6a80374e46 05-May-2011 Jesse Wilson <jessewilson@google.com> Use GET after a POST is redirected.

Also dropping support for response code 305 Use Proxy, which
is seldom used, and whose behavior is quite different from
Chrome and Firefox. This is an intentional delta from the RI.

Also testing disconnect().

Change-Id: I80433f4776a2cfc5e228179421a787a44a4ded69
http://b/3180373
953df613522e12a418cb7cb73248594d6c9f53d4 03-May-2011 Jesse Wilson <jessewilson@google.com> Refactor HttpURLConnection implementation.

Break HttpURLConnectionImpl into two parts: the part that
implements the Java API (that follows redirects etc.) and
the part that speaks HTTP. The HTTP part is called HttpEngine,
and it can only be used for a single HTTP request. This makes
it easier to set request properties that only apply to a
single socket request.

Tests for 'Vary', 'Content-Location' and warnings.

For simplicity of implementation I've chosen not to support
'Vary' at this time.

The 'Content-Location' header doesn't require any work from
the cache.

Warnings are ugly but allow the caller to identify when the
cache results may be problematic.

Also breaking HttpResponseCache's dependency on HttpURLConnectionImpl
so it can be tested on the RI.

Change-Id: Idbabb51251f479c2cdea4e0fceb029bfd07182be
http://b/3180373
0c59055dd24e1659f85d9ff7e2148883f663bd62 27-Apr-2011 Jesse Wilson <jessewilson@google.com> Support conditional gets in HttpURLConnection.

This is the first step towards adding an HTTP response cache.
There's still much to do; details are listed on the bug.

Change-Id: Ie693fe424d1d90e90576fc959595e4d96a31f767
http://b/3180373
5f03a4682a71e56535059258a4d41150b99177d7 05-Apr-2011 Jesse Wilson <jessewilson@google.com> Fix a test that was merged from both GB and HC.

Change-Id: I8cf7dec2dcec177669a04951635c95c78d8c7aaf
http://b/4188137
bc4c79c6a2059003f695f7ad204de36700e8d701 31-Mar-2011 Jesse Wilson <jessewilson@google.com> Don't read from the delegate stream after we close it.

Change-Id: Ib724b170f7ec10ea0025c0e2e7978119fd070eb6
http://b/4188137
0c2fd828abec671333b8b88281825fd27a783723 30-Mar-2011 Jesse Wilson <jessewilson@google.com> Fix MockWebServer to use the same hostname as TestKeyStore.

Change-Id: I31c9f6e9add87a17737eac4f09949540e5da8cb5
f241d462634527692b7d99335cdc8c11883ac966 29-Mar-2011 Jesse Wilson <jessewilson@google.com> Don't read from the delegate stream after we close it.

Change-Id: I9a018ca88373d5f317335e35fc6ca43c5473490e
http://b/4188137
32559028b14b9b321b10eede050afd554a376569 09-Feb-2011 Jesse Wilson <jessewilson@google.com> Use the same code to encode and fix poorly encoded URLs.

Don't permit digits outside of ASCII.

Change-Id: I47b756c32e67b7415e35ae9eb55b735d1c22a36d
http://b/3436051
38db242d16a5a31fd86c519b817ae94c5fc89417 27-Jan-2011 Elliott Hughes <enh@google.com> Consistently use "expected" for expected exceptions in our tests.

Change-Id: I796624fb53dbba420d43858741c9a97b4fb8d017
afd9b157f467b7c4f2f0b5592dca72f18d844602 20-Jan-2011 Jesse Wilson <jessewilson@google.com> Handle the CacheResponse returning a null body.

Change-Id: I45c4d6b7cac5cabd8c42f5e17d110fb5b3ecc9cc
http://b/3373699
d1b5e5da828434388e486a388710d21e4306dae0 20-Jan-2011 Jesse Wilson <jessewilson@google.com> Fix URL character bugs by adding yet another encoder.

We don't have an encoder that ignores already escaped
characters.

Change-Id: I9ff080ad1745136b7d7313d78af2b0ca1785b200
http://b/3360947
b7f4d6c3968c372767b2510f38a3d506067aced6 13-Jan-2011 Jesse Wilson <jessewilson@google.com> Move tests from android.core.URLTest to URLConnectionTest.

This includes some changes to MockWebServer to make it stop
accepting connections as soon as its response queue is empty.

Change-Id: I5a6bcdf1c03d0c36b11552ae086d0dece0440f64
http://b/1158780
fa9f91a486b81b19db13eab59e704179381de22f 12-Jan-2011 Jesse Wilson <jessewilson@google.com> Fix typo in testResponseCacheCallbackApis().

Embarassing. Test passes with the typo fixed!

Change-Id: Ic348f68c0e720163ca77b125415b01e840c7412d
f14bee4dbf9f724a177a85a7b73f7b0bc6df1ec0 06-Jan-2011 Jesse Wilson <jessewilson@google.com> Return HTTP headers even if there is no HTTP response body.

Also add a test to demonstrate that we've bug 7787.
http://code.google.com/p/android/issues/detail?id=7787

Change-Id: I4e320835516c05ec9e305661b5bbb1e59b278183
e942f46f10bb9384a1b186b3d7b74f9704c57090 17-Dec-2010 Jesse Wilson <jessewilson@google.com> Test that HttpURLConnection responds gracefully when the server closes a socket.

Change-Id: I5110d58d91e7c6f8f7553ad400f0bd841bcf07b6
http://b/2612240
2915378e253f08e47fe5a9bfd026cd1ca7c6c351 16-Dec-2010 Brian Carlstrom <bdc@google.com> HttpsURLConnection retry should not invoke X509TrustManager and HostnameVerifier more than once

Summary:

In 2.3, HttpsURLConnection was change to retry TLS connections as SSL
connections w/o compression to deal with servers that are TLS
intolerant. However, if the handshake proceeded to the point of
invoking the X509TrustManager, we should not retry. Similarly, if we
should not invoke the HostnameVerifier repeatedly, and need to wait
until the SSL handshake has completed.

Tested with (includes two new tests for this issue):
libcore/luni/src/test/java/libcore/javax/net/ssl/
libcore/luni/src/test/java/libcore/java/net/URLConnectionTest.java
libcore/luni/src/test/java/org/apache/harmony/luni/tests/internal/net/www/protocol/https/HttpsURLConnectionTest.java

Details:

HttpConnection.setupSecureSocket has been broken into two
pieces. setupSecureSocket now just does the SSL
handshaking. verifySecureSocketHostname now does the
verification. The old HttpConnection code was careful never to
assign its sslSocket field until verification was complete. A new
unverifiedSocket field is added to store the sslSocket before
verification is completed by verifySecureSocketHostname.

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java

HttpsEngine.makeConnection now skips TLS intolerant retry if the
reason for the makeSslConnection failure was a
CertificateException, since that implies that we failed during
certification validation after initial handshaking. We also
prevent retrying hostname verification by moving it out of
makeSslConnection and only doing it on new SSL connections,
tracking the changes to HttpConnection.setupSecureSocket mentioned
above. We also now skip the redundant call to setUpTransportIO in
makeSslConnection on reused SSLSockets.

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java

Instead of throwing away the underlying CertificateExceptions, set
them as the cause of the SSLExceptions. This is what the RI does
in the case of X509TrustManager failures and is now used by
HttpsEngine.makeConnection.

luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java

Added new testConnectViaHttpsToUntrustedServer which makes sure
that connections are not retried on certificate verification
failure.

luni/src/test/java/libcore/java/net/URLConnectionTest.java

Added new test_SSLSocket_untrustedServer that verifies that an
SSLHandshakeException is thown containing a CertificateException
is thrown on certificate verification problems.

luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java

Added second test CA and a new TestKeyStore.getClientCA2 test key
store that does not trust the primary test key stores. This is
useful for negative testing and is used in the above two new
tests.

support/src/test/java/libcore/java/security/TestKeyStore.java

Issue: http://code.google.com/p/android/issues/detail?id=13178
Bug: 3292412

Change-Id: I37136bb65f04d2bceaf2f32f542d6432c8b76ad4
c6dae581716b9362a5c7f166c80a7f2b46ed1124 06-Nov-2010 Jesse Wilson <jessewilson@google.com> Throw the expected exception after the response failed.

Change-Id: I4c2ed726d41d6b55e27a503467a412fa05242383
http://b/3172197
35eef71e8ce721c4199c525890ecc1a263054596 02-Dec-2010 Jesse Wilson <jessewilson@google.com> Fix two bugs with HTTPS + file uploads.

Firstly, we weren't echoing calls to setFixedLengthStreamingMode
and setChunkedStreamingMode from the HTTPS adapter down to the
real HTTP client.

Secondly, we were calling setTransportIO twice, and the second
call destroyed the buffer of our request body stream. That buffer
has only existed since change Id22a8449118a4b8dd13e71915700ac78803d2d9f,
(November 2, 2010) so the impact of that problem is limited.

Change-Id: Icb0eb2e0ca4e201a629bd74c3b98e852f6cc0fd3
http://code.google.com/p/android/issues/detail?id=12860
253851cdb2904082c205949da273c455d197c083 01-Dec-2010 Jesse Wilson <jessewilson@google.com> Do not merge: Fix a bug where we weren't pooling connections due to mismatched URLs.

Already committed to master as change 78504.

Change-Id: Ib883e92bb03b142f34449ef1314c57878dcc00f0

http://b/3169861
dbc42ad94ce37b3178e14b50496914c267d6cea6 16-Nov-2010 Brian Carlstrom <bdc@google.com> HttpsURLConnection fixes to pass URLConnectionTest and HttpsURLConnectionTest

Add public getSecureSocket so that HttpsURLConnection can reset its sslSocket field on reused connections.

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpConnection.java

discardIntermediateResponse now maintain old values for
intermediateReponse, which is necessary when retrying the CONNECT
method with proxy authorization.

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnectionImpl.java

Clear sslSocket before retrying makeSslConnection to ensure we reconnect.
makeSslConnection now resets sslSocket on resumed connection.
makeSslConnection now exits early on existing connection.

luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/https/HttpsURLConnectionImpl.java

git cherry-pick -e 4df5be29bdffc09e7368c03423a0bef85fa26ac5
Bug: 3184701
Change-Id: Ida3c027f79e5e29968263ac761d4f4f79d063a27
5bcbe1c84468a25fec1e5b4e1dd636f917c73422 16-Nov-2010 Brian Carlstrom <bdc@google.com> HttpsURLConnectionTest rewrite and URLConnectionTest updates

Rewrote HttpsURLConnectionTest to work with current SSLSocket
implementation which more strictly follows RI behavior.

Also made upates to URLConnectionTest related to HttpsURLConnection
- changed assertContent call connect() explictly to illustrate problem
with https proxy case also seen by HttpsURLConnectionTest
- Rewrote testConnectTimeouts to work reliably. Before if often
worked on WiFi but not on mobile networks where a "HTTP/1.1 501 Bad
Gateway" would be seen causing a FileNotFoundException.
- Changed testConnectViaHttpProxyToHttpsUsingHttpProxySystemProperty
to match expectation that https does not use the http.proxyHost
values. Added new testConnectViaHttpProxyToHttpsUsingProxyArgWithNoProxy
which should have the same behavior as the fixed
testConnectViaHttpProxyToHttpsUsingHttpProxySystemProperty

git cherry-pick -e f02c695ed03e708623d9365dec26d533356ef2d0

Bug: 3184701
Change-Id: Id25f619d2437db607deaf35aeb1d5e817514b92f
5fc5dde4c719c1dfdac46b67d5d2e4884d07721e 16-Nov-2010 Elliott Hughes <enh@google.com> Improve ConcurrentCloseTest.

No more flaky use of 10.* addresses.

Bug: 3044772
Change-Id: I5ca8dc431b50950efdc818efe73eb9aba76ea67f
f02c695ed03e708623d9365dec26d533356ef2d0 16-Nov-2010 Brian Carlstrom <bdc@google.com> HttpsURLConnectionTest rewrite and URLConnectionTest updates

Rewrote HttpsURLConnectionTest to work with current SSLSocket
implementation which more strictly follows RI behavior.

Also made upates to URLConnectionTest related to HttpsURLConnection
- changed assertContent call connect() explictly to illustrate problem
with https proxy case also seen by HttpsURLConnectionTest
- Rewrote testConnectTimeouts to work reliably. Before if often
worked on WiFi but not on mobile networks where a "HTTP/1.1 501 Bad
Gateway" would be seen causing a FileNotFoundException.
- Changed testConnectViaHttpProxyToHttpsUsingHttpProxySystemProperty
to match expectation that https does not use the http.proxyHost
values. Added new testConnectViaHttpProxyToHttpsUsingProxyArgWithNoProxy
which should have the same behavior as the fixed
testConnectViaHttpProxyToHttpsUsingHttpProxySystemProperty

Change-Id: I397f55905524e2bbb587533f258ef0418ca8af80
06e15e6c528fcb773bedb43e34b0577312570927 05-Nov-2010 Jesse Wilson <jessewilson@google.com> Fix a bug where we weren't pooling connections due to mismatched URLs.

Change-Id: I13bebc94189192c3f8d959e521989591d2fca3e2
c1a675c80c69decadb736b245f0366f93a94a462 29-Oct-2010 Jesse Wilson <jessewilson@google.com> Remove the tree map in the HTTP headers.

This map is intended make looking up headers faster, but for real-world
sized datasets we spend more energy maintaining the map than we save from
using it.

I benchmarked the Android Market's HTTP connections' header use and it's
significantly faster to skip the map:

run us linear runtime
map+list 413.1 ==============================
list only 65.8 ====

Change-Id: I5b8fef6f999eb1bfe53eea2781f63cdd1002a273
8ac847a52e72f0cefbb20a6850ae04468d433a9e 28-Oct-2010 Jesse Wilson <jessewilson@google.com> Fix broken interactions between HTTP response caches and redirects.

This fixes several specific problems:
- HTTP header map didn't contain the status line (under the null key)
- response code, message and version weren't set by caches
- caches didn't work with redirects

This change also makes some significant cleanup to the Headers class.
We might be able to simplify this further by dropping the map, should
that prove efficient enough.

Change-Id: Ib79ec17bef5978b3234f68102114eee7d4b7cda2
http://b/3139211
http://b/3139211
37dcf5581f177229ca6c8e7d0d640361640bfb00 27-Oct-2010 Jesse Wilson <jessewilson@google.com> Fix ResponseCache to support caching of HTTPS responses.

Previously it would fail with an internal error because of
inconsistencies because HttpURLConnectionImpl claimed to be
'connected' when it had a cache hit, and HttpsURLConnection
acted upon this by talking to its sockets.

Change-Id: I51f4215ceb9c5fd851223a501488306fa6d382b1
http://b/3043966
984fcff696380abd6ea14e80030f9fd2d09dbad0 14-Oct-2010 Jesse Wilson <jessewilson@google.com> Tests for HTTP bugs using HTTPS through a proxy.

Change-Id: I01b470204d4da46016794ab7040d5751e7116958
http://b/3097277
http://b/3097518
f29ad8a60254345d1943d1b3836482395a7c916f 30-Sep-2010 Jesse Wilson <jessewilson@google.com> Don't explode if flush() is called when an HTTP upload stream is closed.

Streams like BufferedOutputStream always call flush() even if it is
a no-op. These flushes must be permitted for compatibility with apps
that don't call close() until after the response has been retrieved.

Change-Id: Ic5c86ab6050c6c4d166c44ae5b4fc7a1688e7e45
http://b/3038470
1f8243e3d2b5a3f8e0398c304d1dea0395cbc368 28-Sep-2010 Jesse Wilson <jessewilson@google.com> Remove java.net tests that are redundant with Harmony.

Change-Id: I01d6b3633a6de8a075982975d4cbf6c08e757490
00feece22909b7dc79fc96d666d157390b93858e 24-Sep-2010 Jesse Wilson <jessewilson@google.com> Strip usage of the term 'localhost' from URLConnectionTest.

Change-Id: I8ea7923c3ea72728c7df64c13bdd6f94b91be121
http://b/3032912
ef66494dce45a0b7ec22ec3fb20c60096517a4e3 22-Sep-2010 Jesse Wilson <jessewilson@google.com> Fix problem where single-byte reads were unsigned.

Change-Id: Ib0bc273698b71d13a90a03a8c60498ad7de5ad9d
http://b/3023872
d4bddd7d1fb7b1b7f0836648228235c6e4b56a18 16-Sep-2010 Jesse Wilson <jessewilson@google.com> Fix two HTTP issues that came up when writing HttpURLConnection docs.

We're now more careful about which headers are sent to HTTP proxies.
And getContentEncoding() is better documented.

Change-Id: I04241f99c2f32c25ba005fbd6ff9ef7236c3c9d3
8116f7e97e00d223e7fbe5c950c9a5e3277de124 17-Sep-2010 Jesse Wilson <jessewilson@google.com> Don't leave the Content-Encoding header around after transparent gzip.

Otherwise clients may be tempted to double-decompress.
http://b/issue?id=3009828

Change-Id: I4832da1c2aff9bad8d452ffc4a0f98ee27d44f49
65d890eb22aeba9b009ee642ffd4fff48a6f98ae 08-Sep-2010 Jesse Wilson <jessewilson@google.com> Cope with HTTP responses where the response code and headers disagree.

See http://b/issue?id=2981779

Change-Id: I0e4ed8f0cc606aa419704ba2eb5cd9938b5ff320
b7155fd57239e986bbaba254a91aeb9600d60305 03-Sep-2010 Jesse Wilson <jessewilson@google.com> Fixing a broken pipe with HttpsURLConnection connection reuse.

We had a bug where we were peeking a byte from the raw socket
stream rather than the encrypted stream when we were attempting
to reuse an HTTPS connection. The raw stream field shouldn't
have been initialized, but setupTransportIO() did it while the
connection was being established.

This fixes setupTransportIO() to not initialize the fields
and isStale() to use the SSL fields if they exist.

See http://code.google.com/p/android/issues/detail?id=8625

Change-Id: Idd5b6f20e098adf436997829940707548896bedb
50ae32218918eae80298bd1ab8e4f588bbbabdb2 01-Sep-2010 Jesse Wilson <jessewilson@google.com> Configure HttpURLConnection to prefer gzipped content by default.

This is not what the RI does. But the bandwidth savings is substantial,
and we can offer it almost for free.

See http://code.google.com/p/android/issues/detail?id=9390

Change-Id: I43c3fae8938f33809f2526d2d0e1cc5e08ae1202
f418bf447fd007cd2ec2d45b4b0399a11904e9b4 30-Aug-2010 Jesse Wilson <jessewilson@google.com> Support "Connection: close" from both request and response.

This is a rewrite of fix for the same problem in AOSP master:
https://review.source.android.com/16757

This expands on that fix by supporting "Connection: close" on
redirects by adding test coverage.

Change-Id: Ia0daa9d83cf9f557b4e9a99b2c51345c98c6db14
125f068f0a6cd739beac97821c9421cf8317cc87 20-Aug-2010 Jesse Wilson <jessewilson@google.com> Fix a bug when user sets "Content-Encoding: chunked" manually.

We used to try to build a -1-sized ByteArrayOutputStream, which
failed miserably with an exception.

Change-Id: Ia6fa72c639a14c03f03b6f73083ce37ffab8b4e5
4557728efb66c455a52b7669a8eefef7a9e54854 11-Aug-2010 Jesse Wilson <jessewilson@google.com> Moving tests to be under the libcore.* package.

This is indended to make it easier to run on VMs that restrict the packages
from which application classes can be loaded. For example, on the RI you need
to use the bootclasspath to load these tests.

Change-Id: I52193f35c5fcca18b5a3e1d280505b1e29b388af