blob: 59483a8254664cb620f15862a858f15d9c65f7e4 [file] [log] [blame]
Aurimas Liutikasdc3f8852024-07-11 10:07:48 -07001// 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
5package android.net.http;
6
7import androidx.annotation.NonNull;
8import androidx.annotation.Nullable;
9
10import java.util.List;
11import 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 */
18public 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
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
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 */
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
53 public abstract String getHttpStatusText();
54
55 /**
56 * Returns the response headers.
57 */
58 @NonNull
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 */
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
79 public abstract String getNegotiatedProtocol();
80
81 /**
82 * Returns a minimum count of bytes received from the network to process this request. This
83 * count may ignore certain overheads (for example IP and TCP/UDP framing, SSL handshake and
84 * framing, proxy handling). This count is taken prior to decompression (for example GZIP) and
85 * includes headers and data from all redirects.
86 *
87 * This value may change (even for one {@link UrlResponseInfo} instance) as the request
88 * progresses until completion, when {@link UrlRequest.Callback#onSucceeded onSucceeded()},
89 * {@link UrlRequest.Callback#onFailed onFailed()}, or {@link UrlRequest.Callback#onCanceled
90 * onCanceled()} is called.
91 *
92 * @return a minimum count of bytes received from the network to process this request.
93 */
94 public abstract long getReceivedByteCount();
95}