| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2006 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 error_ = error; | 41 error_ = error; |
| 42 ss_->WakeUp(); | 42 ss_->WakeUp(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 /////////////////////////////////////////////////////////////////////////////// | 45 /////////////////////////////////////////////////////////////////////////////// |
| 46 // HttpRequest | 46 // HttpRequest |
| 47 /////////////////////////////////////////////////////////////////////////////// | 47 /////////////////////////////////////////////////////////////////////////////// |
| 48 | 48 |
| 49 const int kDefaultHTTPTimeout = 30 * 1000; // 30 sec | 49 const int kDefaultHTTPTimeout = 30 * 1000; // 30 sec |
| 50 | 50 |
| 51 HttpRequest::HttpRequest(const std::string &user_agent) | 51 HttpRequest::HttpRequest(const std::string& user_agent) |
| 52 : firewall_(0), port_(80), secure_(false), | 52 : firewall_(0), |
| 53 timeout_(kDefaultHTTPTimeout), fail_redirect_(false), | 53 port_(80), |
| 54 client_(user_agent.c_str(), NULL), error_(HE_NONE) { | 54 secure_(false), |
| 55 } | 55 timeout_(kDefaultHTTPTimeout), |
| 56 client_(user_agent.c_str(), NULL), |
| 57 error_(HE_NONE) {} |
| 56 | 58 |
| 57 HttpRequest::~HttpRequest() = default; | 59 HttpRequest::~HttpRequest() = default; |
| 58 | 60 |
| 59 void HttpRequest::Send() { | 61 void HttpRequest::Send() { |
| 60 // TODO: Rewrite this to use the thread's native socket server, and a more | 62 // TODO: Rewrite this to use the thread's native socket server, and a more |
| 61 // natural flow? | 63 // natural flow? |
| 62 | 64 |
| 63 PhysicalSocketServer physical; | 65 PhysicalSocketServer physical; |
| 64 SocketServer * ss = &physical; | 66 SocketServer * ss = &physical; |
| 65 if (firewall_) { | 67 if (firewall_) { |
| 66 ss = new FirewallSocketServer(ss, firewall_); | 68 ss = new FirewallSocketServer(ss, firewall_); |
| 67 } | 69 } |
| 68 | 70 |
| 69 SslSocketFactory factory(ss, client_.agent()); | 71 SslSocketFactory factory(ss, client_.agent()); |
| 70 factory.SetProxy(proxy_); | 72 factory.SetProxy(proxy_); |
| 71 if (secure_) | 73 if (secure_) |
| 72 factory.UseSSL(host_.c_str()); | 74 factory.UseSSL(host_.c_str()); |
| 73 | 75 |
| 74 //factory.SetLogging("HttpRequest"); | 76 //factory.SetLogging("HttpRequest"); |
| 75 | 77 |
| 76 ReuseSocketPool pool(&factory); | 78 ReuseSocketPool pool(&factory); |
| 77 client_.set_pool(&pool); | 79 client_.set_pool(&pool); |
| 78 | 80 |
| 79 bool transparent_proxy = (port_ == 80) && ((proxy_.type == PROXY_HTTPS) || | 81 bool transparent_proxy = (port_ == 80) && ((proxy_.type == PROXY_HTTPS) || |
| 80 (proxy_.type == PROXY_UNKNOWN)); | 82 (proxy_.type == PROXY_UNKNOWN)); |
| 81 | 83 |
| 82 if (transparent_proxy) { | 84 if (transparent_proxy) { |
| 83 client_.set_proxy(proxy_); | 85 client_.set_proxy(proxy_); |
| 84 } | 86 } |
| 85 client_.set_fail_redirect(fail_redirect_); | 87 client_.set_redirect_action(HttpClient::REDIRECT_ALWAYS); |
| 86 | 88 |
| 87 SocketAddress server(host_, port_); | 89 SocketAddress server(host_, port_); |
| 88 client_.set_server(server); | 90 client_.set_server(server); |
| 89 | 91 |
| 90 LOG(LS_INFO) << "HttpRequest start: " << host_ + client_.request().path; | 92 LOG(LS_INFO) << "HttpRequest start: " << host_ + client_.request().path; |
| 91 | 93 |
| 92 HttpMonitor monitor(ss); | 94 HttpMonitor monitor(ss); |
| 93 monitor.Connect(&client_); | 95 monitor.Connect(&client_); |
| 94 client_.start(); | 96 client_.start(); |
| 95 ss->Wait(timeout_, true); | 97 ss->Wait(timeout_, true); |
| 96 if (!monitor.done()) { | 98 if (!monitor.done()) { |
| 97 LOG(LS_INFO) << "HttpRequest request timed out"; | 99 LOG(LS_INFO) << "HttpRequest request timed out"; |
| 98 client_.reset(); | 100 client_.reset(); |
| 99 return; | 101 return; |
| 100 } | 102 } |
| 101 | 103 |
| 102 set_error(monitor.error()); | 104 set_error(monitor.error()); |
| 103 if (error_) { | 105 if (error_) { |
| 104 LOG(LS_INFO) << "HttpRequest request error: " << error_; | 106 LOG(LS_INFO) << "HttpRequest request error: " << error_; |
| 105 return; | 107 return; |
| 106 } | 108 } |
| 107 | 109 |
| 108 std::string value; | 110 std::string value; |
| 109 if (client_.response().hasHeader(HH_LOCATION, &value)) { | 111 if (client_.response().hasHeader(HH_LOCATION, &value)) { |
| 110 response_redirect_ = value.c_str(); | 112 response_redirect_ = value.c_str(); |
| 111 } | 113 } |
| 112 } | 114 } |
| OLD | NEW |