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 #include "url_io/url_request.h" | |
5 #include <stdio.h> | |
6 | |
7 namespace url_io { | |
8 | |
9 URLRequest::URLRequest(std::string url) | |
10 : url_(url), | |
11 method_(kMethodGet), | |
12 follow_redirect_(true), | |
13 stream_to_file_(false), | |
14 allow_cross_origin_requests_(false), | |
15 allow_credentials_(false) { | |
16 } | |
17 | |
18 URLRequest::URLRequest(std::string url, Method method) | |
19 : url_(url), | |
20 method_(method), | |
21 follow_redirect_(true), | |
22 stream_to_file_(false), | |
23 allow_cross_origin_requests_(false), | |
24 allow_credentials_(false) { | |
25 } | |
26 | |
27 void URLRequest::SetHeader(std::string key, std::string value) { | |
28 if (!key.empty()) { | |
29 headers_[key] = value; | |
30 } | |
31 } | |
32 | |
33 std::string URLRequest::GetHeaderValueForKey(std::string key) { | |
34 return headers_[key]; | |
35 } | |
36 | |
37 void URLRequest::RemoveHeader(std::string key) { | |
38 HeaderDictionary::iterator i = headers_.find(key); | |
39 if (i != headers_.end()) { | |
40 headers_.erase(i); | |
41 } | |
42 } | |
43 | |
44 pp::URLRequestInfo URLRequest::GetRequestInfo(pp::Instance* instance) const { | |
45 pp::URLRequestInfo request(instance); | |
46 request.SetURL(url_); | |
47 request.SetMethod((method_ == kMethodGet) ? "GET" : "POST"); | |
48 request.SetFollowRedirects(follow_redirect_); | |
49 request.SetStreamToFile(stream_to_file_); | |
50 request.SetAllowCrossOriginRequests(allow_cross_origin_requests_); | |
51 request.SetAllowCredentials(allow_credentials_); | |
52 | |
53 HeaderDictionary::const_iterator i; | |
54 std::string header_str; | |
55 for (i = headers_.begin(); i != headers_.end(); ++i) { | |
56 header_str = header_str + (*i).first + ": " + (*i).second + "\n"; | |
57 } | |
58 request.SetHeaders(header_str); | |
59 | |
60 return request; | |
61 } | |
62 | |
63 } // namespace url_io | |
OLD | NEW |