Chromium Code Reviews| Index: components/cronet/android/test/javatests/src/org/chromium/net/TestHttpUrlRequestListener.java |
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/TestHttpUrlRequestListener.java b/components/cronet/android/test/javatests/src/org/chromium/net/TestHttpUrlRequestListener.java |
| index 662dba46c55b3d0bc67bd5ca903cfb8a33f0386e..089c017e57b24aba13b9cb23d0fafcbb10d56ea3 100644 |
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/TestHttpUrlRequestListener.java |
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/TestHttpUrlRequestListener.java |
| @@ -39,27 +39,32 @@ public class TestHttpUrlRequestListener implements HttpUrlRequestListener { |
| + request.getContentLength()); |
| Log.i(TAG, "*** Headers Are *** " + request.getAllHeaders()); |
| mHttpStatusCode = request.getHttpStatusCode(); |
| - mNegotiatedProtocol = request.getNegotiatedProtocol(); |
| mHttpStatusText = request.getHttpStatusText(); |
| + mNegotiatedProtocol = request.getNegotiatedProtocol(); |
| + mResponseHeaders = request.getAllHeaders(); |
| mStarted.open(); |
| } |
| @Override |
| public void onRequestComplete(HttpUrlRequest request) { |
| mUrl = request.getUrl(); |
| - // mHttpStatusCode and mResponseHeaders are available in |
| - // onResponseStarted. However when redirects are disabled, |
| - // onResponseStarted is not invoked. |
| - Exception exception = request.getException(); |
| - if (exception != null && exception.getMessage().equals("Request failed " |
| - + "because there were too many redirects or redirects have " |
| - + "been disabled")) { |
| + mException = request.getException(); |
| + if (mException != null) { |
| + // When there is an exception, onResponseStarted is often not |
| + // invoked (eg. when request fails or redirects are disabled). |
|
mmenke
2015/03/02 19:22:50
nit: e.g.
xunjieli
2015/03/02 22:33:57
Done.
|
| + // Populate status code and text in this case. |
| mHttpStatusCode = request.getHttpStatusCode(); |
| - mResponseHeaders = request.getAllHeaders(); |
| + mHttpStatusText = request.getHttpStatusText(); |
| + if (mException.getMessage().equals("Request failed " |
| + + "because there were too many redirects or redirects have " |
| + + "been disabled")) { |
| + mResponseHeaders = request.getAllHeaders(); |
| + } |
| + } else { |
| + // Read the response body if there is not an exception. |
| + mResponseAsBytes = request.getResponseAsBytes(); |
| + mResponseAsString = new String(mResponseAsBytes); |
| } |
| - mResponseAsBytes = request.getResponseAsBytes(); |
| - mResponseAsString = new String(mResponseAsBytes); |
| - mException = request.getException(); |
| mComplete.open(); |
| Log.i(TAG, "****** Request Complete over " + mNegotiatedProtocol |
| + ", status code is " + mHttpStatusCode); |