• 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 org.chromium.net;
6 
7 import java.util.List;
8 import java.util.Map;
9 
10 /**
11  * Basic information about a response. Included in {@link UrlRequest.Callback} callbacks. Each
12  * {@link UrlRequest.Callback#onRedirectReceived onRedirectReceived()} callback gets a different
13  * copy of {@code UrlResponseInfo} describing a particular redirect response.
14  */
15 public abstract class UrlResponseInfo {
16     /** Unmodifiable container of response headers or trailers. {@hide crbug/1394772}. */
17     public abstract static class HeaderBlock {
18         /**
19          * Returns an unmodifiable list of the response header field and value pairs. The headers
20          * are in the same order they are received over the wire.
21          *
22          * @return an unmodifiable list of response header field and value pairs
23          */
getAsList()24         public abstract List<Map.Entry<String, String>> getAsList();
25 
26         /**
27          * Returns an unmodifiable map from response-header field names to lists of values. Each
28          * list of values for a single header field is in the same order they were received over the
29          * wire.
30          *
31          * @return an unmodifiable map from response-header field names to lists of values
32          */
getAsMap()33         public abstract Map<String, List<String>> getAsMap();
34     }
35 
36     /**
37      * Returns the URL the response is for. This is the URL after following redirects, so it may not
38      * be the originally requested URL.
39      *
40      * @return the URL the response is for.
41      */
getUrl()42     public abstract String getUrl();
43 
44     /**
45      * Returns the URL chain. The first entry is the originally requested URL; the following entries
46      * are redirects followed.
47      *
48      * @return the URL chain.
49      */
getUrlChain()50     public abstract List<String> getUrlChain();
51 
52     /**
53      * Returns the HTTP status code. When a resource is retrieved from the cache, whether it was
54      * revalidated or not, the original status code is returned.
55      *
56      * @return the HTTP status code.
57      */
getHttpStatusCode()58     public abstract int getHttpStatusCode();
59 
60     /**
61      * Returns the HTTP status text of the status line. For example, if the request received a
62      * "HTTP/1.1 200 OK" response, this method returns "OK".
63      *
64      * @return the HTTP status text of the status line.
65      */
getHttpStatusText()66     public abstract String getHttpStatusText();
67 
68     /**
69      * Returns an unmodifiable list of response header field and value pairs. The headers are in the
70      * same order they are received over the wire.
71      *
72      * @return an unmodifiable list of response header field and value pairs.
73      */
getAllHeadersAsList()74     public abstract List<Map.Entry<String, String>> getAllHeadersAsList();
75 
76     /**
77      * Returns an unmodifiable map of the response-header fields and values. Each list of values for
78      * a single header field is in the same order they were received over the wire.
79      *
80      * @return an unmodifiable map of the response-header fields and values.
81      */
getAllHeaders()82     public abstract Map<String, List<String>> getAllHeaders();
83 
84     /**
85      * Returns {@code true} if the response came from the cache, including requests that were
86      * revalidated over the network before being retrieved from the cache.
87      *
88      * @return {@code true} if the response came from the cache, {@code false} otherwise.
89      */
wasCached()90     public abstract boolean wasCached();
91 
92     /**
93      * Returns the protocol (for example 'quic/1+spdy/3') negotiated with the server. Returns an
94      * empty string if no protocol was negotiated, the protocol is not known, or when using plain
95      * HTTP or HTTPS.
96      *
97      * @return the protocol negotiated with the server.
98      */
99     // TODO(mef): Figure out what this returns in the cached case, both with
100     // and without a revalidation request.
getNegotiatedProtocol()101     public abstract String getNegotiatedProtocol();
102 
103     /**
104      * Returns the proxy server that was used for the request.
105      *
106      * @return the proxy server that was used for the request.
107      */
getProxyServer()108     public abstract String getProxyServer();
109 
110     /**
111      * Returns a minimum count of bytes received from the network to process this request. This
112      * count may ignore certain overheads (for example IP and TCP/UDP framing, SSL handshake and
113      * framing, proxy handling). This count is taken prior to decompression (for example GZIP) and
114      * includes headers and data from all redirects.
115      *
116      * This value may change (even for one {@link UrlResponseInfo} instance) as the request
117      * progresses until completion, when {@link UrlRequest.Callback#onSucceeded onSucceeded()},
118      * {@link UrlRequest.Callback#onFailed onFailed()}, or {@link UrlRequest.Callback#onCanceled
119      * onCanceled()} is called.
120      *
121      * @return a minimum count of bytes received from the network to process this request.
122      */
getReceivedByteCount()123     public abstract long getReceivedByteCount();
124 }
125