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
21namespace rtc {
22
23///////////////////////////////////////////////////////////////////////////////
24// HttpRequest
25///////////////////////////////////////////////////////////////////////////////
26
27class FirewallManager;
28class MemoryStream;
29
30class HttpRequest {
31public:
32  HttpRequest(const std::string &user_agent);
33
34  void Send();
35
36  void set_proxy(const ProxyInfo& proxy) {
37    proxy_ = proxy;
38  }
39  void set_firewall(FirewallManager * firewall) {
40    firewall_ = firewall;
41  }
42
43  // The DNS name of the host to connect to.
44  const std::string& host() { return host_; }
45  void set_host(const std::string& host) { host_ = host; }
46
47  // The port to connect to on the target host.
48  int port() { return port_; }
49  void set_port(int port) { port_ = port; }
50
51   // Whether the request should use SSL.
52  bool secure() { return secure_; }
53  void set_secure(bool secure) { secure_ = secure; }
54
55  // Returns the redirect when redirection occurs
56  const std::string& response_redirect() { return response_redirect_; }
57
58  // Time to wait on the download, in ms.  Default is 5000 (5s)
59  int timeout() { return timeout_; }
60  void set_timeout(int timeout) { timeout_ = timeout; }
61
62  // Fail redirects to allow analysis of redirect urls, etc.
63  bool fail_redirect() const { return fail_redirect_; }
64  void set_fail_redirect(bool fail_redirect) { fail_redirect_ = fail_redirect; }
65
66  HttpRequestData& request() { return client_.request(); }
67  HttpResponseData& response() { return client_.response(); }
68  HttpErrorType error() { return error_; }
69
70protected:
71  void set_error(HttpErrorType error) { error_ = error; }
72
73private:
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
90class HttpMonitor : public sigslot::has_slots<> {
91public:
92  HttpMonitor(SocketServer *ss);
93
94  void reset() {
95    complete_ = false;
96    error_ = HE_DEFAULT;
97  }
98
99  bool done() const { return complete_; }
100  HttpErrorType error() const { return error_; }
101
102  void Connect(HttpClient* http);
103  void OnHttpClientComplete(HttpClient * http, HttpErrorType error);
104
105private:
106  bool complete_;
107  HttpErrorType error_;
108  SocketServer *ss_;
109};
110
111///////////////////////////////////////////////////////////////////////////////
112
113}  // namespace rtc_
114
115#endif  // _HTTPREQUEST_H_
116