3
* Copyright 2004--2010, Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
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.
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.
28
#ifndef TALK_BASE_ASYNCHTTPREQUEST_H_
29
#define TALK_BASE_ASYNCHTTPREQUEST_H_
32
#include "talk/base/event.h"
33
#include "talk/base/httpclient.h"
34
#include "talk/base/signalthread.h"
35
#include "talk/base/socketpool.h"
36
#include "talk/base/sslsocketfactory.h"
40
class FirewallManager;
42
///////////////////////////////////////////////////////////////////////////////
44
// Performs an HTTP request on a background thread. Notifies on the foreground
45
// thread once the request is done (successfully or unsuccessfully).
46
///////////////////////////////////////////////////////////////////////////////
48
class AsyncHttpRequest : public SignalThread {
50
explicit AsyncHttpRequest(const std::string &user_agent);
53
// If start_delay is less than or equal to zero, this starts immediately.
54
// Start_delay defaults to zero.
55
int start_delay() const { return start_delay_; }
56
void set_start_delay(int delay) { start_delay_ = delay; }
58
const ProxyInfo& proxy() const { return proxy_; }
59
void set_proxy(const ProxyInfo& proxy) {
62
void set_firewall(FirewallManager * firewall) {
66
// The DNS name of the host to connect to.
67
const std::string& host() { return host_; }
68
void set_host(const std::string& host) { host_ = host; }
70
// The port to connect to on the target host.
71
int port() { return port_; }
72
void set_port(int port) { port_ = port; }
74
// Whether the request should use SSL.
75
bool secure() { return secure_; }
76
void set_secure(bool secure) { secure_ = secure; }
78
// Time to wait on the download, in ms.
79
int timeout() { return timeout_; }
80
void set_timeout(int timeout) { timeout_ = timeout; }
82
// Fail redirects to allow analysis of redirect urls, etc.
83
bool fail_redirect() const { return fail_redirect_; }
84
void set_fail_redirect(bool redirect) { fail_redirect_ = redirect; }
86
// Returns the redirect when redirection occurs
87
const std::string& response_redirect() { return response_redirect_; }
89
HttpRequestData& request() { return client_.request(); }
90
HttpResponseData& response() { return client_.response(); }
91
HttpErrorType error() { return error_; }
94
void set_error(HttpErrorType error) { error_ = error; }
95
virtual void OnWorkStart();
96
virtual void OnWorkStop();
97
void OnComplete(HttpClient* client, HttpErrorType error);
98
virtual void OnMessage(Message* message);
99
virtual void DoWork();
102
void LaunchRequest();
106
FirewallManager* firewall_;
112
SslSocketFactory factory_;
113
ReuseSocketPool pool_;
115
HttpErrorType error_;
116
std::string response_redirect_;
119
} // namespace talk_base
121
#endif // TALK_BASE_ASYNCHTTPREQUEST_H_