xref: /aosp_15_r20/external/libbrillo/brillo/http/http_request.h (revision 1a96fba65179ea7d3f56207137718607415c5953)
1*1a96fba6SXin Li // Copyright 2014 The Chromium OS Authors. All rights reserved.
2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be
3*1a96fba6SXin Li // found in the LICENSE file.
4*1a96fba6SXin Li 
5*1a96fba6SXin Li #ifndef LIBBRILLO_BRILLO_HTTP_HTTP_REQUEST_H_
6*1a96fba6SXin Li #define LIBBRILLO_BRILLO_HTTP_HTTP_REQUEST_H_
7*1a96fba6SXin Li 
8*1a96fba6SXin Li #include <limits>
9*1a96fba6SXin Li #include <map>
10*1a96fba6SXin Li #include <memory>
11*1a96fba6SXin Li #include <string>
12*1a96fba6SXin Li #include <utility>
13*1a96fba6SXin Li #include <vector>
14*1a96fba6SXin Li 
15*1a96fba6SXin Li #include <base/macros.h>
16*1a96fba6SXin Li #include <brillo/brillo_export.h>
17*1a96fba6SXin Li #include <brillo/errors/error.h>
18*1a96fba6SXin Li #include <brillo/http/http_connection.h>
19*1a96fba6SXin Li #include <brillo/http/http_transport.h>
20*1a96fba6SXin Li 
21*1a96fba6SXin Li namespace brillo {
22*1a96fba6SXin Li namespace http {
23*1a96fba6SXin Li 
24*1a96fba6SXin Li // HTTP request verbs
25*1a96fba6SXin Li namespace request_type {
26*1a96fba6SXin Li BRILLO_EXPORT extern const char kOptions[];
27*1a96fba6SXin Li BRILLO_EXPORT extern const char kGet[];
28*1a96fba6SXin Li BRILLO_EXPORT extern const char kHead[];
29*1a96fba6SXin Li BRILLO_EXPORT extern const char kPost[];
30*1a96fba6SXin Li BRILLO_EXPORT extern const char kPut[];
31*1a96fba6SXin Li BRILLO_EXPORT extern const char kPatch[];  // Non-standard HTTP/1.1 verb
32*1a96fba6SXin Li BRILLO_EXPORT extern const char kDelete[];
33*1a96fba6SXin Li BRILLO_EXPORT extern const char kTrace[];
34*1a96fba6SXin Li BRILLO_EXPORT extern const char kConnect[];
35*1a96fba6SXin Li BRILLO_EXPORT extern const char kCopy[];   // Non-standard HTTP/1.1 verb
36*1a96fba6SXin Li BRILLO_EXPORT extern const char kMove[];   // Non-standard HTTP/1.1 verb
37*1a96fba6SXin Li }  // namespace request_type
38*1a96fba6SXin Li 
39*1a96fba6SXin Li // HTTP request header names
40*1a96fba6SXin Li namespace request_header {
41*1a96fba6SXin Li BRILLO_EXPORT extern const char kAccept[];
42*1a96fba6SXin Li BRILLO_EXPORT extern const char kAcceptCharset[];
43*1a96fba6SXin Li BRILLO_EXPORT extern const char kAcceptEncoding[];
44*1a96fba6SXin Li BRILLO_EXPORT extern const char kAcceptLanguage[];
45*1a96fba6SXin Li BRILLO_EXPORT extern const char kAllow[];
46*1a96fba6SXin Li BRILLO_EXPORT extern const char kAuthorization[];
47*1a96fba6SXin Li BRILLO_EXPORT extern const char kCacheControl[];
48*1a96fba6SXin Li BRILLO_EXPORT extern const char kConnection[];
49*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentEncoding[];
50*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLanguage[];
51*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLength[];
52*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLocation[];
53*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentMd5[];
54*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentRange[];
55*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentType[];
56*1a96fba6SXin Li BRILLO_EXPORT extern const char kCookie[];
57*1a96fba6SXin Li BRILLO_EXPORT extern const char kDate[];
58*1a96fba6SXin Li BRILLO_EXPORT extern const char kExpect[];
59*1a96fba6SXin Li BRILLO_EXPORT extern const char kExpires[];
60*1a96fba6SXin Li BRILLO_EXPORT extern const char kFrom[];
61*1a96fba6SXin Li BRILLO_EXPORT extern const char kHost[];
62*1a96fba6SXin Li BRILLO_EXPORT extern const char kIfMatch[];
63*1a96fba6SXin Li BRILLO_EXPORT extern const char kIfModifiedSince[];
64*1a96fba6SXin Li BRILLO_EXPORT extern const char kIfNoneMatch[];
65*1a96fba6SXin Li BRILLO_EXPORT extern const char kIfRange[];
66*1a96fba6SXin Li BRILLO_EXPORT extern const char kIfUnmodifiedSince[];
67*1a96fba6SXin Li BRILLO_EXPORT extern const char kLastModified[];
68*1a96fba6SXin Li BRILLO_EXPORT extern const char kMaxForwards[];
69*1a96fba6SXin Li BRILLO_EXPORT extern const char kPragma[];
70*1a96fba6SXin Li BRILLO_EXPORT extern const char kProxyAuthorization[];
71*1a96fba6SXin Li BRILLO_EXPORT extern const char kRange[];
72*1a96fba6SXin Li BRILLO_EXPORT extern const char kReferer[];
73*1a96fba6SXin Li BRILLO_EXPORT extern const char kTE[];
74*1a96fba6SXin Li BRILLO_EXPORT extern const char kTrailer[];
75*1a96fba6SXin Li BRILLO_EXPORT extern const char kTransferEncoding[];
76*1a96fba6SXin Li BRILLO_EXPORT extern const char kUpgrade[];
77*1a96fba6SXin Li BRILLO_EXPORT extern const char kUserAgent[];
78*1a96fba6SXin Li BRILLO_EXPORT extern const char kVia[];
79*1a96fba6SXin Li BRILLO_EXPORT extern const char kWarning[];
80*1a96fba6SXin Li }  // namespace request_header
81*1a96fba6SXin Li 
82*1a96fba6SXin Li // HTTP response header names
83*1a96fba6SXin Li namespace response_header {
84*1a96fba6SXin Li BRILLO_EXPORT extern const char kAcceptRanges[];
85*1a96fba6SXin Li BRILLO_EXPORT extern const char kAge[];
86*1a96fba6SXin Li BRILLO_EXPORT extern const char kAllow[];
87*1a96fba6SXin Li BRILLO_EXPORT extern const char kCacheControl[];
88*1a96fba6SXin Li BRILLO_EXPORT extern const char kConnection[];
89*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentEncoding[];
90*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLanguage[];
91*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLength[];
92*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentLocation[];
93*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentMd5[];
94*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentRange[];
95*1a96fba6SXin Li BRILLO_EXPORT extern const char kContentType[];
96*1a96fba6SXin Li BRILLO_EXPORT extern const char kDate[];
97*1a96fba6SXin Li BRILLO_EXPORT extern const char kETag[];
98*1a96fba6SXin Li BRILLO_EXPORT extern const char kExpires[];
99*1a96fba6SXin Li BRILLO_EXPORT extern const char kLastModified[];
100*1a96fba6SXin Li BRILLO_EXPORT extern const char kLocation[];
101*1a96fba6SXin Li BRILLO_EXPORT extern const char kPragma[];
102*1a96fba6SXin Li BRILLO_EXPORT extern const char kProxyAuthenticate[];
103*1a96fba6SXin Li BRILLO_EXPORT extern const char kRetryAfter[];
104*1a96fba6SXin Li BRILLO_EXPORT extern const char kServer[];
105*1a96fba6SXin Li BRILLO_EXPORT extern const char kSetCookie[];
106*1a96fba6SXin Li BRILLO_EXPORT extern const char kTrailer[];
107*1a96fba6SXin Li BRILLO_EXPORT extern const char kTransferEncoding[];
108*1a96fba6SXin Li BRILLO_EXPORT extern const char kUpgrade[];
109*1a96fba6SXin Li BRILLO_EXPORT extern const char kVary[];
110*1a96fba6SXin Li BRILLO_EXPORT extern const char kVia[];
111*1a96fba6SXin Li BRILLO_EXPORT extern const char kWarning[];
112*1a96fba6SXin Li BRILLO_EXPORT extern const char kWwwAuthenticate[];
113*1a96fba6SXin Li }  // namespace response_header
114*1a96fba6SXin Li 
115*1a96fba6SXin Li // HTTP request status (error) codes
116*1a96fba6SXin Li namespace status_code {
117*1a96fba6SXin Li // OK to continue with request
118*1a96fba6SXin Li static const int Continue = 100;
119*1a96fba6SXin Li // Server has switched protocols in upgrade header
120*1a96fba6SXin Li static const int SwitchProtocols = 101;
121*1a96fba6SXin Li 
122*1a96fba6SXin Li // Request completed
123*1a96fba6SXin Li static const int Ok = 200;
124*1a96fba6SXin Li // Object created, reason = new URI
125*1a96fba6SXin Li static const int Created = 201;
126*1a96fba6SXin Li // Async completion (TBS)
127*1a96fba6SXin Li static const int Accepted = 202;
128*1a96fba6SXin Li // Partial completion
129*1a96fba6SXin Li static const int Partial = 203;
130*1a96fba6SXin Li // No info to return
131*1a96fba6SXin Li static const int NoContent = 204;
132*1a96fba6SXin Li // Request completed, but clear form
133*1a96fba6SXin Li static const int ResetContent = 205;
134*1a96fba6SXin Li // Partial GET fulfilled
135*1a96fba6SXin Li static const int PartialContent = 206;
136*1a96fba6SXin Li 
137*1a96fba6SXin Li // Server couldn't decide what to return
138*1a96fba6SXin Li static const int Ambiguous = 300;
139*1a96fba6SXin Li // Object permanently moved
140*1a96fba6SXin Li static const int Moved = 301;
141*1a96fba6SXin Li // Object temporarily moved
142*1a96fba6SXin Li static const int Redirect = 302;
143*1a96fba6SXin Li // Redirection w/ new access method
144*1a96fba6SXin Li static const int RedirectMethod = 303;
145*1a96fba6SXin Li // If-Modified-Since was not modified
146*1a96fba6SXin Li static const int NotModified = 304;
147*1a96fba6SXin Li // Redirection to proxy, location header specifies proxy to use
148*1a96fba6SXin Li static const int UseProxy = 305;
149*1a96fba6SXin Li // HTTP/1.1: keep same verb
150*1a96fba6SXin Li static const int RedirectKeepVerb = 307;
151*1a96fba6SXin Li 
152*1a96fba6SXin Li // Invalid syntax
153*1a96fba6SXin Li static const int BadRequest = 400;
154*1a96fba6SXin Li // Access denied
155*1a96fba6SXin Li static const int Denied = 401;
156*1a96fba6SXin Li // Payment required
157*1a96fba6SXin Li static const int PaymentRequired = 402;
158*1a96fba6SXin Li // Request forbidden
159*1a96fba6SXin Li static const int Forbidden = 403;
160*1a96fba6SXin Li // Object not found
161*1a96fba6SXin Li static const int NotFound = 404;
162*1a96fba6SXin Li // Method is not allowed
163*1a96fba6SXin Li static const int BadMethod = 405;
164*1a96fba6SXin Li // No response acceptable to client found
165*1a96fba6SXin Li static const int NoneAcceptable = 406;
166*1a96fba6SXin Li // Proxy authentication required
167*1a96fba6SXin Li static const int ProxyAuthRequired = 407;
168*1a96fba6SXin Li // Server timed out waiting for request
169*1a96fba6SXin Li static const int RequestTimeout = 408;
170*1a96fba6SXin Li // User should resubmit with more info
171*1a96fba6SXin Li static const int Conflict = 409;
172*1a96fba6SXin Li // The resource is no longer available
173*1a96fba6SXin Li static const int Gone = 410;
174*1a96fba6SXin Li // The server refused to accept request w/o a length
175*1a96fba6SXin Li static const int LengthRequired = 411;
176*1a96fba6SXin Li // Precondition given in request failed
177*1a96fba6SXin Li static const int PrecondionFailed = 412;
178*1a96fba6SXin Li // Request entity was too large
179*1a96fba6SXin Li static const int RequestTooLarge = 413;
180*1a96fba6SXin Li // Request URI too long
181*1a96fba6SXin Li static const int UriTooLong = 414;
182*1a96fba6SXin Li // Unsupported media type
183*1a96fba6SXin Li static const int UnsupportedMedia = 415;
184*1a96fba6SXin Li // Retry after doing the appropriate action.
185*1a96fba6SXin Li static const int RetryWith = 449;
186*1a96fba6SXin Li 
187*1a96fba6SXin Li // Internal server error
188*1a96fba6SXin Li static const int InternalServerError = 500;
189*1a96fba6SXin Li // Request not supported
190*1a96fba6SXin Li static const int NotSupported = 501;
191*1a96fba6SXin Li // Error response received from gateway
192*1a96fba6SXin Li static const int BadGateway = 502;
193*1a96fba6SXin Li // Temporarily overloaded
194*1a96fba6SXin Li static const int ServiceUnavailable = 503;
195*1a96fba6SXin Li // Timed out waiting for gateway
196*1a96fba6SXin Li static const int GatewayTimeout = 504;
197*1a96fba6SXin Li // HTTP version not supported
198*1a96fba6SXin Li static const int VersionNotSupported = 505;
199*1a96fba6SXin Li }  // namespace status_code
200*1a96fba6SXin Li 
201*1a96fba6SXin Li class Response;  // Just a forward declaration.
202*1a96fba6SXin Li class FormData;
203*1a96fba6SXin Li 
204*1a96fba6SXin Li ///////////////////////////////////////////////////////////////////////////////
205*1a96fba6SXin Li // Request class is the main object used to set up and initiate an HTTP
206*1a96fba6SXin Li // communication session. It is used to specify the HTTP request method,
207*1a96fba6SXin Li // request URL and many optional parameters (such as HTTP headers, user agent,
208*1a96fba6SXin Li // referer URL and so on.
209*1a96fba6SXin Li //
210*1a96fba6SXin Li // Once everything is setup, GetResponse() method is used to send the request
211*1a96fba6SXin Li // and obtain the server response. The returned Response object can be
212*1a96fba6SXin Li // used to inspect the response code, HTTP headers and/or response body.
213*1a96fba6SXin Li ///////////////////////////////////////////////////////////////////////////////
214*1a96fba6SXin Li class BRILLO_EXPORT Request final {
215*1a96fba6SXin Li  public:
216*1a96fba6SXin Li   // The main constructor. |url| specifies the remote host address/path
217*1a96fba6SXin Li   // to send the request to. |method| is the HTTP request verb and
218*1a96fba6SXin Li   // |transport| is the HTTP transport implementation for server communications.
219*1a96fba6SXin Li   Request(const std::string& url,
220*1a96fba6SXin Li           const std::string& method,
221*1a96fba6SXin Li           std::shared_ptr<Transport> transport);
222*1a96fba6SXin Li   ~Request();
223*1a96fba6SXin Li 
224*1a96fba6SXin Li   // Gets/Sets "Accept:" header value. The default value is "*/*" if not set.
225*1a96fba6SXin Li   void SetAccept(const std::string& accept_mime_types);
226*1a96fba6SXin Li   const std::string& GetAccept() const;
227*1a96fba6SXin Li 
228*1a96fba6SXin Li   // Gets/Sets "Content-Type:" header value
229*1a96fba6SXin Li   void SetContentType(const std::string& content_type);
230*1a96fba6SXin Li   const std::string& GetContentType() const;
231*1a96fba6SXin Li 
232*1a96fba6SXin Li   // Adds additional HTTP request header
233*1a96fba6SXin Li   void AddHeader(const std::string& header, const std::string& value);
234*1a96fba6SXin Li   void AddHeaders(const HeaderList& headers);
235*1a96fba6SXin Li 
236*1a96fba6SXin Li   // Removes HTTP request header
237*1a96fba6SXin Li   void RemoveHeader(const std::string& header);
238*1a96fba6SXin Li 
239*1a96fba6SXin Li   // Adds a request body. This is not to be used with GET method
240*1a96fba6SXin Li   bool AddRequestBody(const void* data, size_t size, brillo::ErrorPtr* error);
241*1a96fba6SXin Li   bool AddRequestBody(StreamPtr stream, brillo::ErrorPtr* error);
242*1a96fba6SXin Li 
243*1a96fba6SXin Li   // Adds a request body. This is not to be used with GET method.
244*1a96fba6SXin Li   // This method also sets the correct content-type of the request, including
245*1a96fba6SXin Li   // the multipart data boundary.
246*1a96fba6SXin Li   bool AddRequestBodyAsFormData(std::unique_ptr<FormData> form_data,
247*1a96fba6SXin Li                                 brillo::ErrorPtr* error);
248*1a96fba6SXin Li 
249*1a96fba6SXin Li   // Adds a stream for the response. Otherwise a MemoryStream will be used.
250*1a96fba6SXin Li   bool AddResponseStream(StreamPtr stream, brillo::ErrorPtr* error);
251*1a96fba6SXin Li 
252*1a96fba6SXin Li   // Makes a request for a subrange of data. Specifies a partial range with
253*1a96fba6SXin Li   // either from beginning of the data to the specified offset (if |bytes| is
254*1a96fba6SXin Li   // negative) or from the specified offset to the end of data (if |bytes| is
255*1a96fba6SXin Li   // positive).
256*1a96fba6SXin Li   // All individual ranges will be sent as part of "Range:" HTTP request header.
257*1a96fba6SXin Li   void AddRange(int64_t bytes);
258*1a96fba6SXin Li 
259*1a96fba6SXin Li   // Makes a request for a subrange of data. Specifies a full range with
260*1a96fba6SXin Li   // start and end bytes from the beginning of the requested data.
261*1a96fba6SXin Li   // All individual ranges will be sent as part of "Range:" HTTP request header.
262*1a96fba6SXin Li   void AddRange(uint64_t from_byte, uint64_t to_byte);
263*1a96fba6SXin Li 
264*1a96fba6SXin Li   // Returns the request URL
265*1a96fba6SXin Li   const std::string& GetRequestURL() const;
266*1a96fba6SXin Li 
267*1a96fba6SXin Li   // Returns the request verb.
268*1a96fba6SXin Li   const std::string& GetRequestMethod() const;
269*1a96fba6SXin Li 
270*1a96fba6SXin Li   // Gets/Sets a request referer URL (sent as "Referer:" request header).
271*1a96fba6SXin Li   void SetReferer(const std::string& referer);
272*1a96fba6SXin Li   const std::string& GetReferer() const;
273*1a96fba6SXin Li 
274*1a96fba6SXin Li   // Gets/Sets a user agent string (sent as "User-Agent:" request header).
275*1a96fba6SXin Li   void SetUserAgent(const std::string& user_agent);
276*1a96fba6SXin Li   const std::string& GetUserAgent() const;
277*1a96fba6SXin Li 
278*1a96fba6SXin Li   // Sends the request to the server and blocks until the response is received,
279*1a96fba6SXin Li   // which is returned as the response object.
280*1a96fba6SXin Li   // In case the server couldn't be reached for whatever reason, returns
281*1a96fba6SXin Li   // empty unique_ptr (null). In such a case, the additional error information
282*1a96fba6SXin Li   // can be returned through the optional supplied |error| parameter.
283*1a96fba6SXin Li   std::unique_ptr<Response> GetResponseAndBlock(brillo::ErrorPtr* error);
284*1a96fba6SXin Li 
285*1a96fba6SXin Li   // Sends out the request and invokes the |success_callback| when the response
286*1a96fba6SXin Li   // is received. In case of an error, the |error_callback| is invoked.
287*1a96fba6SXin Li   // Returns the ID of the asynchronous request created.
288*1a96fba6SXin Li   RequestID GetResponse(const SuccessCallback& success_callback,
289*1a96fba6SXin Li                         const ErrorCallback& error_callback);
290*1a96fba6SXin Li 
291*1a96fba6SXin Li  private:
292*1a96fba6SXin Li   friend class HttpRequestTest;
293*1a96fba6SXin Li 
294*1a96fba6SXin Li   // Helper function to create an http::Connection and send off request headers.
295*1a96fba6SXin Li   BRILLO_PRIVATE bool SendRequestIfNeeded(brillo::ErrorPtr* error);
296*1a96fba6SXin Li 
297*1a96fba6SXin Li   // Implementation that provides particular HTTP transport.
298*1a96fba6SXin Li   std::shared_ptr<Transport> transport_;
299*1a96fba6SXin Li 
300*1a96fba6SXin Li   // An established connection for adding request body. This connection
301*1a96fba6SXin Li   // is maintained by the request object after the headers have been
302*1a96fba6SXin Li   // sent and before the response is requested.
303*1a96fba6SXin Li   std::shared_ptr<Connection> connection_;
304*1a96fba6SXin Li 
305*1a96fba6SXin Li   // Full request URL, such as "http://www.host.com/path/to/object"
306*1a96fba6SXin Li   const std::string request_url_;
307*1a96fba6SXin Li   // HTTP request verb, such as "GET", "POST", "PUT", ...
308*1a96fba6SXin Li   const std::string method_;
309*1a96fba6SXin Li 
310*1a96fba6SXin Li   // Referrer URL, if any. Sent to the server via "Referer: " header.
311*1a96fba6SXin Li   std::string referer_;
312*1a96fba6SXin Li   // User agent string, if any. Sent to the server via "User-Agent: " header.
313*1a96fba6SXin Li   std::string user_agent_;
314*1a96fba6SXin Li   // Content type of the request body data.
315*1a96fba6SXin Li   // Sent to the server via "Content-Type: " header.
316*1a96fba6SXin Li   std::string content_type_;
317*1a96fba6SXin Li   // List of acceptable response data types.
318*1a96fba6SXin Li   // Sent to the server via "Accept: " header.
319*1a96fba6SXin Li   std::string accept_ = "*/*";
320*1a96fba6SXin Li 
321*1a96fba6SXin Li   // List of optional request headers provided by the caller.
322*1a96fba6SXin Li   std::multimap<std::string, std::string> headers_;
323*1a96fba6SXin Li   // List of optional data ranges to request partial content from the server.
324*1a96fba6SXin Li   // Sent to the server as "Range: " header.
325*1a96fba6SXin Li   std::vector<std::pair<uint64_t, uint64_t>> ranges_;
326*1a96fba6SXin Li 
327*1a96fba6SXin Li   // range_value_omitted is used in |ranges_| list to indicate omitted value.
328*1a96fba6SXin Li   // E.g. range (10,range_value_omitted) represents bytes from 10 to the end
329*1a96fba6SXin Li   // of the data stream.
330*1a96fba6SXin Li   const uint64_t range_value_omitted = std::numeric_limits<uint64_t>::max();
331*1a96fba6SXin Li 
332*1a96fba6SXin Li   DISALLOW_COPY_AND_ASSIGN(Request);
333*1a96fba6SXin Li };
334*1a96fba6SXin Li 
335*1a96fba6SXin Li ///////////////////////////////////////////////////////////////////////////////
336*1a96fba6SXin Li // Response class is returned from Request::GetResponse() and is a way
337*1a96fba6SXin Li // to get to response status, error codes, response HTTP headers and response
338*1a96fba6SXin Li // data (body) if available.
339*1a96fba6SXin Li ///////////////////////////////////////////////////////////////////////////////
340*1a96fba6SXin Li class BRILLO_EXPORT Response final {
341*1a96fba6SXin Li  public:
342*1a96fba6SXin Li   explicit Response(const std::shared_ptr<Connection>& connection);
343*1a96fba6SXin Li   ~Response();
344*1a96fba6SXin Li 
345*1a96fba6SXin Li   // Returns true if server returned a success code (status code below 400).
346*1a96fba6SXin Li   bool IsSuccessful() const;
347*1a96fba6SXin Li 
348*1a96fba6SXin Li   // Returns the HTTP status code (e.g. 200 for success)
349*1a96fba6SXin Li   int GetStatusCode() const;
350*1a96fba6SXin Li 
351*1a96fba6SXin Li   // Returns the status text (e.g. for error 403 it could be "NOT AUTHORIZED").
352*1a96fba6SXin Li   std::string GetStatusText() const;
353*1a96fba6SXin Li 
354*1a96fba6SXin Li   // Returns the content type of the response data.
355*1a96fba6SXin Li   std::string GetContentType() const;
356*1a96fba6SXin Li 
357*1a96fba6SXin Li   // Returns response data stream by transferring ownership of the data stream
358*1a96fba6SXin Li   // from Response class to the caller.
359*1a96fba6SXin Li   StreamPtr ExtractDataStream(ErrorPtr* error);
360*1a96fba6SXin Li 
361*1a96fba6SXin Li   // Extracts the data from the underlying response data stream as a byte array.
362*1a96fba6SXin Li   std::vector<uint8_t> ExtractData();
363*1a96fba6SXin Li 
364*1a96fba6SXin Li   // Extracts the data from the underlying response data stream as a string.
365*1a96fba6SXin Li   std::string ExtractDataAsString();
366*1a96fba6SXin Li 
367*1a96fba6SXin Li   // Returns a value of a given response HTTP header.
368*1a96fba6SXin Li   std::string GetHeader(const std::string& header_name) const;
369*1a96fba6SXin Li 
370*1a96fba6SXin Li  private:
371*1a96fba6SXin Li   friend class HttpRequestTest;
372*1a96fba6SXin Li 
373*1a96fba6SXin Li   std::shared_ptr<Connection> connection_;
374*1a96fba6SXin Li 
375*1a96fba6SXin Li   DISALLOW_COPY_AND_ASSIGN(Response);
376*1a96fba6SXin Li };
377*1a96fba6SXin Li 
378*1a96fba6SXin Li }  // namespace http
379*1a96fba6SXin Li }  // namespace brillo
380*1a96fba6SXin Li 
381*1a96fba6SXin Li #endif  // LIBBRILLO_BRILLO_HTTP_HTTP_REQUEST_H_
382