• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2006 The WebRTC Project Authors. All rights reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef _HTTPREQUEST_H_
12 #define _HTTPREQUEST_H_
13 
14 #include "webrtc/base/httpclient.h"
15 #include "webrtc/base/logging.h"
16 #include "webrtc/base/proxyinfo.h"
17 #include "webrtc/base/socketserver.h"
18 #include "webrtc/base/thread.h"
19 #include "webrtc/base/sslsocketfactory.h"  // Deprecated include
20 
21 namespace rtc {
22 
23 ///////////////////////////////////////////////////////////////////////////////
24 // HttpRequest
25 ///////////////////////////////////////////////////////////////////////////////
26 
27 class FirewallManager;
28 class MemoryStream;
29 
30 class HttpRequest {
31 public:
32   HttpRequest(const std::string &user_agent);
33 
34   void Send();
35 
set_proxy(const ProxyInfo & proxy)36   void set_proxy(const ProxyInfo& proxy) {
37     proxy_ = proxy;
38   }
set_firewall(FirewallManager * firewall)39   void set_firewall(FirewallManager * firewall) {
40     firewall_ = firewall;
41   }
42 
43   // The DNS name of the host to connect to.
host()44   const std::string& host() { return host_; }
set_host(const std::string & host)45   void set_host(const std::string& host) { host_ = host; }
46 
47   // The port to connect to on the target host.
port()48   int port() { return port_; }
set_port(int port)49   void set_port(int port) { port_ = port; }
50 
51    // Whether the request should use SSL.
secure()52   bool secure() { return secure_; }
set_secure(bool secure)53   void set_secure(bool secure) { secure_ = secure; }
54 
55   // Returns the redirect when redirection occurs
response_redirect()56   const std::string& response_redirect() { return response_redirect_; }
57 
58   // Time to wait on the download, in ms.  Default is 5000 (5s)
timeout()59   int timeout() { return timeout_; }
set_timeout(int timeout)60   void set_timeout(int timeout) { timeout_ = timeout; }
61 
62   // Fail redirects to allow analysis of redirect urls, etc.
fail_redirect()63   bool fail_redirect() const { return fail_redirect_; }
set_fail_redirect(bool fail_redirect)64   void set_fail_redirect(bool fail_redirect) { fail_redirect_ = fail_redirect; }
65 
request()66   HttpRequestData& request() { return client_.request(); }
response()67   HttpResponseData& response() { return client_.response(); }
error()68   HttpErrorType error() { return error_; }
69 
70 protected:
set_error(HttpErrorType error)71   void set_error(HttpErrorType error) { error_ = error; }
72 
73 private:
74   ProxyInfo proxy_;
75   FirewallManager * firewall_;
76   std::string host_;
77   int port_;
78   bool secure_;
79   int timeout_;
80   bool fail_redirect_;
81   HttpClient client_;
82   HttpErrorType error_;
83   std::string response_redirect_;
84 };
85 
86 ///////////////////////////////////////////////////////////////////////////////
87 // HttpMonitor
88 ///////////////////////////////////////////////////////////////////////////////
89 
90 class HttpMonitor : public sigslot::has_slots<> {
91 public:
92   HttpMonitor(SocketServer *ss);
93 
reset()94   void reset() {
95     complete_ = false;
96     error_ = HE_DEFAULT;
97   }
98 
done()99   bool done() const { return complete_; }
error()100   HttpErrorType error() const { return error_; }
101 
102   void Connect(HttpClient* http);
103   void OnHttpClientComplete(HttpClient * http, HttpErrorType error);
104 
105 private:
106   bool complete_;
107   HttpErrorType error_;
108   SocketServer *ss_;
109 };
110 
111 ///////////////////////////////////////////////////////////////////////////////
112 
113 }  // namespace rtc_
114 
115 #endif  // _HTTPREQUEST_H_
116