• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 package android.net.http;
6 
7 import androidx.annotation.NonNull;
8 import androidx.annotation.Nullable;
9 
10 import java.util.List;
11 import java.util.Map;
12 
13 /**
14  * Basic information about a response. Included in {@link UrlRequest.Callback} callbacks. Each
15  * {@link UrlRequest.Callback#onRedirectReceived onRedirectReceived()} callback gets a different
16  * copy of {@code UrlResponseInfo} describing a particular redirect response.
17  */
18 public abstract class UrlResponseInfo {
19 
20     /**
21      * Returns the URL the response is for. This is the URL after following redirects, so it may not
22      * be the originally requested URL.
23      *
24      * @return the URL the response is for.
25      */
26     @NonNull
getUrl()27     public abstract String getUrl();
28 
29     /**
30      * Returns the URL chain. The first entry is the originally requested URL; the following entries
31      * are redirects followed.
32      *
33      * @return the URL chain.
34      */
35     @NonNull
getUrlChain()36     public abstract List<String> getUrlChain();
37 
38     /**
39      * Returns the HTTP status code. When a resource is retrieved from the cache, whether it was
40      * revalidated or not, the original status code is returned.
41      *
42      * @return the HTTP status code.
43      */
getHttpStatusCode()44     public abstract int getHttpStatusCode();
45 
46     /**
47      * Returns the HTTP status text of the status line. For example, if the request received a
48      * "HTTP/1.1 200 OK" response, this method returns "OK".
49      *
50      * @return the HTTP status text of the status line.
51      */
52     @NonNull
getHttpStatusText()53     public abstract String getHttpStatusText();
54 
55     /**
56      * Returns the response headers.
57      */
58     @NonNull
getHeaders()59     public abstract HeaderBlock getHeaders();
60 
61     /**
62      * Returns {@code true} if the response came from the cache, including requests that were
63      * revalidated over the network before being retrieved from the cache.
64      *
65      * @return {@code true} if the response came from the cache, {@code false} otherwise.
66      */
wasCached()67     public abstract boolean wasCached();
68 
69     /**
70      * Returns the protocol (for example 'quic/1+spdy/3') negotiated with the server. Returns an
71      * empty string if no protocol was negotiated, the protocol is not known, or when using plain
72      * HTTP or HTTPS.
73      *
74      * @return the protocol negotiated with the server.
75      */
76     // TODO(mef): Figure out what this returns in the cached case, both with
77     // and without a revalidation request.
78     @NonNull
getNegotiatedProtocol()79     public abstract String getNegotiatedProtocol();
80 
81     /**
82      * Returns the proxy server that was used for the request.
83      *
84      * @return the proxy server that was used for the request.
85      *
86      * @hide
87      */
88     @Nullable
getProxyServer()89     public String getProxyServer(){
90         return null;
91     };
92 
93     /**
94      * Returns a minimum count of bytes received from the network to process this request. This
95      * count may ignore certain overheads (for example IP and TCP/UDP framing, SSL handshake and
96      * framing, proxy handling). This count is taken prior to decompression (for example GZIP) and
97      * includes headers and data from all redirects.
98      *
99      * This value may change (even for one {@link UrlResponseInfo} instance) as the request
100      * progresses until completion, when {@link UrlRequest.Callback#onSucceeded onSucceeded()},
101      * {@link UrlRequest.Callback#onFailed onFailed()}, or {@link UrlRequest.Callback#onCanceled
102      * onCanceled()} is called.
103      *
104      * @return a minimum count of bytes received from the network to process this request.
105      */
getReceivedByteCount()106     public abstract long getReceivedByteCount();
107 }
108