diff options
author | xunjieli <xunjieli@chromium.org> | 2014-11-07 19:36:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-08 03:36:37 +0000 |
commit | 29c444e4d2d917142bb595e8af644ef374274c55 (patch) | |
tree | bd1582bda11e505e15a75bd02375aeb65ac48ee9 | |
parent | 271f94c31cd6b94f27d481008afd43f652bbca7d (diff) | |
download | chromium_src-29c444e4d2d917142bb595e8af644ef374274c55.zip chromium_src-29c444e4d2d917142bb595e8af644ef374274c55.tar.gz chromium_src-29c444e4d2d917142bb595e8af644ef374274c55.tar.bz2 |
[Cronet] Added a method to get status text in the async APIs
BUG=429310
Review URL: https://codereview.chromium.org/707233005
Cr-Commit-Position: refs/heads/master@{#303372}
4 files changed, 38 insertions, 7 deletions
diff --git a/components/cronet/android/cronet_url_request.cc b/components/cronet/android/cronet_url_request.cc index ed63c5b..768e8e9 100644 --- a/components/cronet/android/cronet_url_request.cc +++ b/components/cronet/android/cronet_url_request.cc @@ -266,4 +266,16 @@ static jlong GetTotalReceivedBytes(JNIEnv* env, return request_adapter->GetTotalReceivedBytes(); } +static jstring GetHttpStatusText(JNIEnv* env, + jobject jurl_request, + jlong jurl_request_adapter) { + DCHECK(jurl_request_adapter); + CronetURLRequestAdapter* request_adapter = + reinterpret_cast<CronetURLRequestAdapter*>(jurl_request_adapter); + DCHECK(request_adapter->IsOnNetworkThread()); + const net::HttpResponseHeaders* headers = + request_adapter->GetResponseHeaders(); + return ConvertUTF8ToJavaString(env, headers->GetStatusText()).Release(); +} + } // namespace cronet diff --git a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java index bd928ab..85bda3f 100644 --- a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java +++ b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequest.java @@ -119,14 +119,17 @@ final class CronetUrlRequest implements UrlRequest { static final class NativeResponseInfo implements ResponseInfo { private final String[] mResponseInfoUrlChain; private final int mHttpStatusCode; + private final String mHttpStatusText; private final HeadersMap mAllHeaders = new HeadersMap(); private final boolean mWasCached; private final String mNegotiatedProtocol; NativeResponseInfo(String[] urlChain, int httpStatusCode, - boolean wasCached, String negotiatedProtocol) { + String httpStatusText, boolean wasCached, + String negotiatedProtocol) { mResponseInfoUrlChain = urlChain; mHttpStatusCode = httpStatusCode; + mHttpStatusText = httpStatusText; mWasCached = wasCached; mNegotiatedProtocol = negotiatedProtocol; } @@ -147,6 +150,11 @@ final class CronetUrlRequest implements UrlRequest { } @Override + public String getHttpStatusText() { + return mHttpStatusText; + } + + @Override public Map<String, List<String>> getAllHeaders() { return mAllHeaders; } @@ -336,6 +344,7 @@ final class CronetUrlRequest implements UrlRequest { NativeResponseInfo responseInfo = new NativeResponseInfo( mUrlChain.toArray(new String[mUrlChain.size()]), httpStatusCode, + nativeGetHttpStatusText(urlRequestAdapter), nativeGetWasCached(urlRequestAdapter), nativeGetNegotiatedProtocol(urlRequestAdapter)); nativePopulateResponseHeaders(urlRequestAdapter, @@ -593,6 +602,8 @@ final class CronetUrlRequest implements UrlRequest { private native String nativeGetNegotiatedProtocol(long urlRequestAdapter); + private native String nativeGetHttpStatusText(long urlRequestAdapter); + private native boolean nativeGetWasCached(long urlRequestAdapter); private native long nativeGetTotalReceivedBytes(long urlRequestAdapter); diff --git a/components/cronet/android/java/src/org/chromium/net/ResponseInfo.java b/components/cronet/android/java/src/org/chromium/net/ResponseInfo.java index 3d5e53e..42168db 100644 --- a/components/cronet/android/java/src/org/chromium/net/ResponseInfo.java +++ b/components/cronet/android/java/src/org/chromium/net/ResponseInfo.java @@ -31,6 +31,12 @@ public interface ResponseInfo { int getHttpStatusCode(); /** + * @return the HTTP status text of the status line. For example, if the + * request has a "HTTP/1.1 200 OK" response, this method returns "OK". + */ + String getHttpStatusText(); + + /** * @return an unmodifiable map of the response-header fields and values. * The null key is mapped to the HTTP status line for compatibility with * HttpUrlConnection. diff --git a/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/CronetUrlRequestTest.java b/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/CronetUrlRequestTest.java index 320ee9a..b3a1822 100644 --- a/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/CronetUrlRequestTest.java +++ b/components/cronet/android/test/javatests/src/org/chromium/cronet_test_apk/CronetUrlRequestTest.java @@ -67,11 +67,13 @@ public class CronetUrlRequestTest extends CronetTestBase { } private void checkResponseInfo(ResponseInfo responseInfo, - String expectedUrl, int expectedStatusHttpCode) { + String expectedUrl, int expectedHttpStatusCode, + String expectedHttpStatusText) { assertEquals(expectedUrl, responseInfo.getUrl()); assertEquals(expectedUrl, responseInfo.getUrlChain()[ responseInfo.getUrlChain().length - 1]); - assertEquals(expectedStatusHttpCode, responseInfo.getHttpStatusCode()); + assertEquals(expectedHttpStatusCode, responseInfo.getHttpStatusCode()); + assertEquals(expectedHttpStatusText, responseInfo.getHttpStatusText()); assertFalse(responseInfo.wasCached()); } @@ -95,7 +97,7 @@ public class CronetUrlRequestTest extends CronetTestBase { assertFalse(listener.mOnRedirectCalled); assertEquals(listener.mResponseStep, ResponseStep.ON_SUCCEEDED); checkResponseInfo(listener.mResponseInfo, - UploadTestServer.getEchoMethodURL(), 200); + UploadTestServer.getEchoMethodURL(), 200, "OK"); } @SmallTest @@ -286,7 +288,7 @@ public class CronetUrlRequestTest extends CronetTestBase { assertEquals(MOCK_CRONET_TEST_SUCCESS_URL, mResponseInfo.getUrlChain()[1]); checkResponseInfo(listener.mRedirectResponseInfoList.get(0), - MOCK_CRONET_TEST_REDIRECT_URL, 302); + MOCK_CRONET_TEST_REDIRECT_URL, 302, "Found"); checkResponseInfoHeader(listener.mRedirectResponseInfoList.get(0), "redirect-header", "header-value"); assertTrue(listener.mHttpResponseDataLength != 0); @@ -311,7 +313,7 @@ public class CronetUrlRequestTest extends CronetTestBase { assertEquals(MOCK_CRONET_TEST_MULTI_REDIRECT_URL, firstRedirectResponseInfo.getUrlChain()[0]); checkResponseInfo(firstRedirectResponseInfo, - MOCK_CRONET_TEST_MULTI_REDIRECT_URL, 302); + MOCK_CRONET_TEST_MULTI_REDIRECT_URL, 302, "Found"); checkResponseInfoHeader(firstRedirectResponseInfo, "redirect-header0", "header-value"); @@ -324,7 +326,7 @@ public class CronetUrlRequestTest extends CronetTestBase { assertEquals(MOCK_CRONET_TEST_REDIRECT_URL, secondRedirectResponseInfo.getUrlChain()[1]); checkResponseInfo(secondRedirectResponseInfo, - MOCK_CRONET_TEST_REDIRECT_URL, 302); + MOCK_CRONET_TEST_REDIRECT_URL, 302, "Found"); checkResponseInfoHeader(secondRedirectResponseInfo, "redirect-header", "header-value"); |