OLD | NEW |
| (Empty) |
1 // Copyright 2011 The Native Client 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 #ifndef URL_REQUEST_H_ | |
5 #define URL_REQUEST_H_ | |
6 | |
7 #include <map> | |
8 #include <ppapi/cpp/url_request_info.h> | |
9 | |
10 namespace pp { | |
11 class Instance; | |
12 } // namespace pp | |
13 | |
14 namespace url_io { | |
15 | |
16 /// | |
17 class URLRequest { | |
18 public: | |
19 enum Method { kMethodGet, kMethodPost }; | |
20 | |
21 explicit URLRequest(std::string url); | |
22 URLRequest(std::string url, Method method); | |
23 | |
24 /// Set the URL for the request. | |
25 /// @param url the url string. | |
26 void set_url(std::string url) { url_ = url; } | |
27 /// Query the current URL for this request. | |
28 /// @return the URL string. | |
29 std::string url() const {return url_; } | |
30 | |
31 /// Set the follow-redirect property. When set to true Chrome/NaCl | |
32 /// automatically follow redirect requests. When false, it is the users | |
33 /// responsibility to catch redirect headers and follow them. (@see | |
34 /// WebResourceLoader::FollowRedirect. | |
35 /// @param follow_redirect new boolean value for follow-redirect property. | |
36 void set_follow_redirect(bool follow_redirect) { | |
37 follow_redirect_ = follow_redirect; | |
38 } | |
39 /// Query the current value for follow-redirect property. | |
40 /// @return true/false property for property follow-redirect. | |
41 bool follow_redirect() const { return follow_redirect_; } | |
42 | |
43 /// Set the stream-to-file property. | |
44 /// @param stream_to_file new boolean value for stream-to-file property. | |
45 void set_stream_to_file(bool stream_to_file) { | |
46 stream_to_file_ = stream_to_file; | |
47 } | |
48 /// Query the current value for property stream-to-file. | |
49 /// @return true/false boolean value for property stream-to-file. | |
50 bool stream_to_file() const { return stream_to_file_; } | |
51 | |
52 /// Set the allow-cross-origin-requests property. | |
53 /// @param allow_cross_origin_requests new boolean value for allow-cross- | |
54 /// origin-requests property. | |
55 void set_allow_cross_origin_requests(bool allow_cross_origin_requests) { | |
56 allow_cross_origin_requests_ = allow_cross_origin_requests; | |
57 } | |
58 /// @return boolean value for property allow-cross-oriogin-requests. | |
59 bool allow_cross_origin_requests() const { | |
60 return allow_cross_origin_requests_; | |
61 } | |
62 | |
63 /// Set the allow-credentials property. | |
64 /// @param allow_credentials new boolean value for allow-credentials property. | |
65 void set_allow_credentials(bool allow_credentials) { | |
66 allow_credentials_ = allow_credentials; | |
67 } | |
68 /// @return boolean value for property allow-credentials. | |
69 bool allow_credentials() const { return allow_credentials_; } | |
70 | |
71 /// Set a request header. For instance, SetHeader("Accept", "text/*") causes | |
72 /// header "Accept: text/*" to be included in the http request. It is ok to | |
73 /// set a header value to an empty string. However, such headers are not | |
74 /// included in the http request. | |
75 /// @param key field name for the header, e.g. "Accept." | |
76 /// @param value field value for the header, e.g. "text/*." | |
77 void SetHeader(std::string key, std::string value); | |
78 /// Query the field value for a given header name. | |
79 /// @return field value for header with name key. Return an empty string if | |
80 /// there is no such header in the dictionary. | |
81 std::string GetHeaderValueForKey(std::string key); | |
82 /// Remove the header with field name key. | |
83 /// @param key name of field to remove. | |
84 void RemoveHeader(std::string key); | |
85 | |
86 /// Produce a URLRequestInfo instance suitable for use with pp::URLLoader. | |
87 /// @param instance the pp::Instance with which the request will be used. | |
88 /// @return a pp::URLRequestInfo instance. | |
89 pp::URLRequestInfo GetRequestInfo(pp::Instance* instance) const; | |
90 | |
91 // TODO(gwink): add support for (1) body data, (2) custom referrer, | |
92 // (3) download progress, (4) upload progress, (5) transfer encoding, | |
93 // (6) buffer thresholds, (7) cross-origin requests. | |
94 | |
95 private: | |
96 typedef std::map<std::string, std::string> HeaderDictionary; | |
97 | |
98 std::string url_; | |
99 Method method_; | |
100 HeaderDictionary headers_; | |
101 bool follow_redirect_; | |
102 bool stream_to_file_; | |
103 bool allow_cross_origin_requests_; | |
104 bool allow_credentials_; | |
105 }; | |
106 | |
107 } // namespace url_io | |
108 #endif // URL_REQUEST_H_ | |
OLD | NEW |