History log of /libcore/support/src/test/java/tests/http/MockWebServer.java
Revision Date Author Comments
b274574b7e2681f4411852af9857b4540bf75841 02-Aug-2013 Elliott Hughes <enh@google.com> If libcore wants ASCII casing, it needs to ask for it like everyone else.

http://elliotth.blogspot.com/2012/01/beware-convenience-methods.html

Bug: https://code.google.com/p/android/issues/detail?id=58359
Change-Id: I597b2ac940f17b5b2bc176e390dc4b63fe0a4e72
99b4489d0555c6e0e5df941cbfad4cf250c8f0b8 07-Jun-2013 Elliott Hughes <enh@google.com> Fix @deprecated javadoc orthography.

Change-Id: I6db6d91e21b8e1aca5b5338534196fd5bdef8a06
09336c914b4fc813e493acc82469b9ad89fd8694 07-Jun-2011 Jesse Wilson <jessewilson@google.com> Use external/mockwebserver in libcore

Change-Id: I4dac34f88b23484643bce31e5f25ac6eb1fea426
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
a0de05e00f3d51df7461cb2048c50bb30ef9112a 06-May-2011 Jesse Wilson <jessewilson@google.com> Don't lose the import for InetAddress.

Change-Id: I90fcf6c284f4a3bbe36ef0ed44f85ddf5a424ffb
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
adb64fbba2b781467e055706c3de0873dfc01166 30-Apr-2011 Jesse Wilson <jessewilson@google.com> Honor max-age and min-fresh request headers.

We now honor headers from both the server's response (which
we have cached) and the client's request.

Change-Id: Ib46e4fc0c5dd5b3e74cff8f45eea2dda51d20b94
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
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
f162edaa335461474b020027bb2e85eb3be2c179 14-Jan-2011 Jesse Wilson <jessewilson@google.com> Fix HTTP cookie to do case mapping with Locale.US.

While I'm here fix a MockWebServer bug I recently introduced
that broke cookie tests that needed to know port numbers before
responses were enqueued.

Change-Id: Idb2389ac5ed66656248c10aeb68209641acc0a68
http://b/3325637
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
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
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
00feece22909b7dc79fc96d666d157390b93858e 24-Sep-2010 Jesse Wilson <jessewilson@google.com> Strip usage of the term 'localhost' from URLConnectionTest.

Change-Id: I8ea7923c3ea72728c7df64c13bdd6f94b91be121
http://b/3032912
4559b1d37edcb5d7f1da086cf2e3290388d74f46 23-Jul-2010 Brian Carlstrom <bdc@google.com> Support for TLS Extensions enabled SSLSockets with fallback to vanila SSL

See also b/1569612

Summary:
- OpenSSlSocket support for SNI, session tickets, compression
- URLConnection mimics Chrome behavior of trying connection with these enabled,
falling back to SSL w/o encryption on failure

Details:

libcore

URLConnection https retry

Change HttpConnection.getSecureSocket to enable non-standard features on first
connection attempt. On second attempt, we back off to SSLv3 from
TLSv1, mimicking Chrome's behavior.

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

Change HttpsEngine.connect to implement SSL reconnect

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

OpenSSL SSLSocket implementation

OpenSSLSocketImpl and OpenSSLServerSocketImpl now have an array of
enabled compression methods interface and implementation to
parallel that of procotols and ciphersuites.

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

OpenSSLSessionImpl now has a cache of the native
compressionMethod. Also replaced "gives" javadoc working with
"returns".

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

OpenSSLSocketImpl session caching now needs to skip cached
sessions with mismatched compression requirements.

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

OpenSSLSocketImpl.startHandshake now uses NativeCrypto to support
our non-standard extensions.

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

NativeCrypto changes
- Added declaration of SSL options for tickets and compression.
- Added general "compression methods" interface
paralleling "cipher suites" and "protocols" interfaces.
- Added SSL_set_tlsext_host_name to set SNI (Server Name Indication) value
- Added SSL_get_servername to read SNI (Server Name Indication) value
- Added SSL_SESSION_compress_meth read negotiated compression method
- SSL_new makes sure to default compression to off for compatibility
luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java
luni/src/main/native/NativeCrypto.cpp

Testing

Added URLConnectionTest.testConnectViaHttpsWithSSLFallback to make
sure we properly retry an https connection if the server
terminates unexpectedly. Fixed up
URLConnectionTest.testHttpsWithCustomTrustManager with new
expected certificate chain. Fixed a few mistaken
TestSSLContext.serverContext uses to clientContext

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

Added test_SSL_set_tlsext_host_name, test_SSL_get_servername,
test_SSL_SESSION_compress_meth. Added a number of missing fail()
calls in expected exception cases which caught one test with
mistaken expectations. Removed some unnecessary scopes. Fixed some
badly scoped catch blocks.

luni/src/test/java/org/apache/harmony/xnet/provider/jsse/NativeCryptoTest.java

Changed MockWebServer to support a new MockResponse propery of
disconnectAtStart, which immediately terminates the connection

support/src/test/java/tests/http/MockResponse.java
support/src/test/java/tests/http/MockWebServer.java

external/openssl

Restore -ZLIB to OpenSSL build. Note that NativeCrypto.SSL_new
disables compression by for default SSLSocket for compatibility.
android-config.mk
Force clean build with new CFLAGS
CleanSpec.mk

Change-Id: Iba6268f9096f2be43f0d30de151dd3fd0aea4a81
096aac7b8a607d3da237900f52cab1c5066bf992 01-Jul-2010 Jesse Wilson <jessewilson@google.com> Buffering the decoding of chunked encoding and HTTP headers.

Also cleanup of HttpConfiguration (renamed HttpConnection.Address),
including removing some dead code.

Also adding performance-run support to MockWebServer to permit
benchmarking.

I benchmarked different buffer sizes, and a buffer as small as 16 bytes
halved the runtime on some HTTP requests. Ultimately I chose a 128 byte
buffer, since that's the point of diminishing returns.

The following report shows benchmark results for 5 different buffer
sizes. Notice how our previous unbuffered behaviour was particularly
inefficient.

bodySize transferEncoding responseHeaders bufferSize ms logarithmic runtime
0 FIXED_LENGTH MINIMAL 0 5.44 =
0 FIXED_LENGTH MINIMAL 16 5.17 =
0 FIXED_LENGTH MINIMAL 128 5.06 =
0 FIXED_LENGTH MINIMAL 512 5.19 =
0 FIXED_LENGTH MINIMAL 1024 5.27 =
0 FIXED_LENGTH TYPICAL 0 14.61 ===========
0 FIXED_LENGTH TYPICAL 16 7.35 ====
0 FIXED_LENGTH TYPICAL 128 6.48 ===
0 FIXED_LENGTH TYPICAL 512 6.97 ====
0 FIXED_LENGTH TYPICAL 1024 6.92 ====
0 CHUNKED MINIMAL 0 5.72 ==
0 CHUNKED MINIMAL 16 5.26 =
0 CHUNKED MINIMAL 128 5.27 =
0 CHUNKED MINIMAL 512 5.16 =
0 CHUNKED MINIMAL 1024 5.31 =
0 CHUNKED TYPICAL 0 14.81 ===========
0 CHUNKED TYPICAL 16 7.30 ====
0 CHUNKED TYPICAL 128 6.62 ===
0 CHUNKED TYPICAL 512 6.51 ===
0 CHUNKED TYPICAL 1024 6.50 ===
1024 FIXED_LENGTH MINIMAL 0 5.47 =
1024 FIXED_LENGTH MINIMAL 16 5.40 =
1024 FIXED_LENGTH MINIMAL 128 5.43 =
1024 FIXED_LENGTH MINIMAL 512 5.40 =
1024 FIXED_LENGTH MINIMAL 1024 5.37 =
1024 FIXED_LENGTH TYPICAL 0 14.83 ===========
1024 FIXED_LENGTH TYPICAL 16 7.42 ====
1024 FIXED_LENGTH TYPICAL 128 6.50 ===
1024 FIXED_LENGTH TYPICAL 512 6.50 ===
1024 FIXED_LENGTH TYPICAL 1024 6.51 ===
1024 CHUNKED MINIMAL 0 6.12 ==
1024 CHUNKED MINIMAL 16 5.51 =
1024 CHUNKED MINIMAL 128 5.55 =
1024 CHUNKED MINIMAL 512 5.60 ==
1024 CHUNKED MINIMAL 1024 5.50 =
1024 CHUNKED TYPICAL 0 15.00 ===========
1024 CHUNKED TYPICAL 16 7.56 =====
1024 CHUNKED TYPICAL 128 6.86 ====
1024 CHUNKED TYPICAL 512 6.73 ===
1024 CHUNKED TYPICAL 1024 6.60 ===
1048576 FIXED_LENGTH MINIMAL 0 25.27 =================
1048576 FIXED_LENGTH MINIMAL 16 25.36 =================
1048576 FIXED_LENGTH MINIMAL 128 25.86 =================
1048576 FIXED_LENGTH MINIMAL 512 25.25 =================
1048576 FIXED_LENGTH MINIMAL 1024 32.51 ===================
1048576 FIXED_LENGTH TYPICAL 0 36.65 =====================
1048576 FIXED_LENGTH TYPICAL 16 27.43 ==================
1048576 FIXED_LENGTH TYPICAL 128 26.88 =================
1048576 FIXED_LENGTH TYPICAL 512 26.94 =================
1048576 FIXED_LENGTH TYPICAL 1024 33.13 ====================
1048576 CHUNKED MINIMAL 0 77.02 ============================
1048576 CHUNKED MINIMAL 16 51.32 ========================
1048576 CHUNKED MINIMAL 128 50.98 ========================
1048576 CHUNKED MINIMAL 512 51.82 ========================
1048576 CHUNKED MINIMAL 1024 50.40 ========================
1048576 CHUNKED TYPICAL 0 88.99 ==============================
1048576 CHUNKED TYPICAL 16 53.94 ========================
1048576 CHUNKED TYPICAL 128 53.03 ========================
1048576 CHUNKED TYPICAL 512 52.14 ========================
1048576 CHUNKED TYPICAL 1024 50.90 ========================

Benchmark source code is here:
http://code.google.com/p/dalvik/source/browse/trunk/benchmarks/regression/URLConnectionBenchmark.java

Change-Id: Ie3e754ab8497e6200f8b6e7f9c63c40a7d4784e2
51e468abf2628ce964d3657042f3ac8f2c947504 26-Jun-2010 Jesse Wilson <jessewilson@google.com> Fixing response cache and connection reuse for HTTP client.

The code splits our HTTP input streams into four (!) inner
classes. The base class takes care of ensuring split() and
single byte reads get cached and call disconnect() as necessary.
Our code closes the cache when the stream is exhausted; this
is different from the RI which closes it when in.close() is
called.

When a fixed length input stream of length 0 is received,
we cache it immediately. This has behavior consequences for
CONNECT, which needs the otherwise-recyclable connection to
stick around.

This adds explicit shutdown capabilities to MockWebServer.
This is necessary now that we don't guarantee all enqueued
responses will be requested.

We still need test coverage for malformed chunk sizes.

Change-Id: Iaf866af4fc1d76faea559df267a4bde6fdfa1d83
c8977f474b30c5f3807398859a6b16687af6fc7b 15-Jun-2010 Jesse Wilson <jessewilson@google.com> Fixing various problems with HTTPS proxies thru HTTP.

- reading extra bytes from the server depending on available()
- not sending the port with the proxy request
- returning a read-til-the-end stream instead of a read-0-bytes-stream
on CONNECT requests
- fixing MockWebServer to omit the unnecessary \r\n after
the response body
- tests no longer mask the issue by unambiguously reading characters.
Trailing newlines aren't discarded!
- New tests when content-length and content disagree. The RI fails
the test when the transfer-encoding is not chunked.

Change-Id: I888569844d323bc770cd5bb95ac71c740dd5e720
60476787f0e0f052366d8031c74e507ffd3d16a3 12-Jun-2010 Jesse Wilson <jessewilson@google.com> Adding testcases for HttpsURLConnection and through a proxy.

One failure is here: http://b/issue?id=2761326

Change-Id: If1918a2e59bd4335e38ce3ec4214dfccd24ee798
706d53593cd8841d378dbe298a8d1940db1e71df 09-Jun-2010 Jesse Wilson <jessewilson@google.com> Adding HTTPS and proxy support to our mock webserver.

Also exposing core-tests-support for use by tests in frameworks/base.
I'm not particularly happy about this, but it seems to be the best
way to share test support code between the two build targets.

Change-Id: I5e8dcac90fc5d9be791e46c2606498978212108e
211d3bbada505912bb16e9d1a6c1a9f1f5c16cff 18-May-2010 Jesse Wilson <jessewilson@google.com> Testing that URLConnection uses CookieManager for send and receive.

These all fail on Dalvik because we haven't wired these together.
On the RI, everything passes except for the two tests that check
parsing for multiple cookies in a single HTTP header.

Change-Id: Idb10c5b51b7ae5ca400dc564f2926f0d5792093d
fd4350050d7a0d333f9d346560b167040c3f44df 10-May-2010 Jesse Wilson <jessewilson@google.com> Adding checks to make sure the HTTP method is consistent with its body.

From the post-review comments here:
https://android-git.corp.google.com/g/51054

Change-Id: I67be25a6648a2df02a888a0ae8559c05614de20c
b1b5baac449d2725002338735f4db34bec8fd001 08-May-2010 Jesse Wilson <jessewilson@google.com> New MockWebServer for HTTP testing.

Unlike the Support_TestWebServer, this server is dumb but scriptable.
It's intended to make it easier to test uncommon HTTP behavior, such
as an intermediate HTTP proxy.

Change-Id: Iac07e0b4788eeaa172d5c55d8ed9e034d98aa8e6