OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_TEST_WEBDRIVER_HTTP_RESPONSE_H_ | |
6 #define CHROME_TEST_WEBDRIVER_HTTP_RESPONSE_H_ | |
7 | |
8 #include <map> | |
9 #include <string> | |
10 | |
11 #include "base/basictypes.h" | |
12 | |
13 namespace webdriver { | |
14 | |
15 class HttpResponse { | |
16 public: | |
17 typedef std::map<std::string, std::string> HeaderMap; | |
18 | |
19 // The supported HTTP response codes. | |
20 static const int kOk; | |
21 static const int kNoContent; | |
22 static const int kSeeOther; | |
23 static const int kNotModified; | |
24 static const int kBadRequest; | |
25 static const int kForbidden; | |
26 static const int kNotFound; | |
27 static const int kMethodNotAllowed; | |
28 static const int kInternalServerError; | |
29 static const int kNotImplemented; | |
30 | |
31 // Creates an HTTP response with a 200 OK status. | |
32 HttpResponse(); | |
33 explicit HttpResponse(int status); | |
34 ~HttpResponse(); | |
35 | |
36 // Sets a header in this response. If a header with the same |name| already | |
37 // exists, the |value| will be appended to the existing values. Since header | |
38 // names are case insensitive, the header will be stored in lowercase format. | |
39 void AddHeader(const std::string& name, const std::string& value); | |
40 | |
41 // Retrieves the value of the specified header. If there is no such header, | |
42 // the output |value| will not be modified and false will be returned. | |
43 bool GetHeader(const std::string& name, std::string* value) const; | |
44 | |
45 // Removes the header with the given |name|. Returns whether there was a | |
46 // matching header to remove. | |
47 bool RemoveHeader(const std::string& name); | |
48 | |
49 // Removes all headers. | |
50 void ClearHeaders(); | |
51 | |
52 // Convenience function for setting the Content-Type header for this response. | |
53 void SetMimeType(const std::string& mime_type); | |
54 | |
55 // Returns the status phrase recommended by RFC 2616 section 6.1.1 for this | |
56 // response's status code. If the status code is not recognized, the default | |
57 // "Unknown" status phrase will be used. | |
58 std::string GetReasonPhrase() const; | |
59 | |
60 // Appends this response to |data|, abiding by HTTP 1.1. | |
61 // This will add an appropriate "Content-Length" header if not already set. | |
62 void GetData(std::string* data) const; | |
63 | |
64 int status() const; | |
65 void set_status(int status); | |
66 const std::string& body() const; | |
67 void set_body(const std::string& body); | |
68 | |
69 private: | |
70 void UpdateHeader(const std::string& name, const std::string& new_value); | |
71 | |
72 int status_; | |
73 HeaderMap headers_; | |
74 std::string body_; | |
75 }; | |
76 | |
77 } // webdriver | |
78 | |
79 #endif // CHROME_TEST_WEBDRIVER_HTTP_RESPONSE_H_ | |
OLD | NEW |