blob: 2e13c328fcee5b5d4b23a9e1569aba4ed3e15ef8 [file] [log] [blame]
henrike@webrtc.org0e118e72013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2006, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#ifndef _HTTPREQUEST_H_
29#define _HTTPREQUEST_H_
30
31#include "talk/base/httpclient.h"
32#include "talk/base/logging.h"
33#include "talk/base/proxyinfo.h"
34#include "talk/base/socketserver.h"
35#include "talk/base/thread.h"
36#include "talk/base/sslsocketfactory.h" // Deprecated include
37
38namespace talk_base {
39
40///////////////////////////////////////////////////////////////////////////////
41// HttpRequest
42///////////////////////////////////////////////////////////////////////////////
43
44class FirewallManager;
45class MemoryStream;
46
47class HttpRequest {
48public:
49 HttpRequest(const std::string &user_agent);
50
51 void Send();
52
53 void set_proxy(const ProxyInfo& proxy) {
54 proxy_ = proxy;
55 }
56 void set_firewall(FirewallManager * firewall) {
57 firewall_ = firewall;
58 }
59
60 // The DNS name of the host to connect to.
61 const std::string& host() { return host_; }
62 void set_host(const std::string& host) { host_ = host; }
63
64 // The port to connect to on the target host.
65 int port() { return port_; }
66 void set_port(int port) { port_ = port; }
67
68 // Whether the request should use SSL.
69 bool secure() { return secure_; }
70 void set_secure(bool secure) { secure_ = secure; }
71
72 // Returns the redirect when redirection occurs
73 const std::string& response_redirect() { return response_redirect_; }
74
75 // Time to wait on the download, in ms. Default is 5000 (5s)
76 int timeout() { return timeout_; }
77 void set_timeout(int timeout) { timeout_ = timeout; }
78
79 // Fail redirects to allow analysis of redirect urls, etc.
80 bool fail_redirect() const { return fail_redirect_; }
81 void set_fail_redirect(bool fail_redirect) { fail_redirect_ = fail_redirect; }
82
83 HttpRequestData& request() { return client_.request(); }
84 HttpResponseData& response() { return client_.response(); }
85 HttpErrorType error() { return error_; }
86
87protected:
88 void set_error(HttpErrorType error) { error_ = error; }
89
90private:
91 ProxyInfo proxy_;
92 FirewallManager * firewall_;
93 std::string host_;
94 int port_;
95 bool secure_;
96 int timeout_;
97 bool fail_redirect_;
98 HttpClient client_;
99 HttpErrorType error_;
100 std::string response_redirect_;
101};
102
103///////////////////////////////////////////////////////////////////////////////
104// HttpMonitor
105///////////////////////////////////////////////////////////////////////////////
106
107class HttpMonitor : public sigslot::has_slots<> {
108public:
109 HttpMonitor(SocketServer *ss);
110
111 void reset() {
112 complete_ = false;
113 error_ = HE_DEFAULT;
114 }
115
116 bool done() const { return complete_; }
117 HttpErrorType error() const { return error_; }
118
119 void Connect(HttpClient* http);
120 void OnHttpClientComplete(HttpClient * http, HttpErrorType error);
121
122private:
123 bool complete_;
124 HttpErrorType error_;
125 SocketServer *ss_;
126};
127
128///////////////////////////////////////////////////////////////////////////////
129
130} // namespace talk_base_
131
132#endif // _HTTPREQUEST_H_