147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org/*
247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  Copyright 2006 The WebRTC Project Authors. All rights reserved.
347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *
447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  Use of this source code is governed by a BSD-style license
547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  that can be found in the LICENSE file in the root of the source
647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  tree. An additional intellectual property rights grant can be found
747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  in the file PATENTS.  All contributing project authors may
847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org *  be found in the AUTHORS file in the root of the source tree.
947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org */
1047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#ifndef _HTTPREQUEST_H_
1247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#define _HTTPREQUEST_H_
1347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
1447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/httpclient.h"
1547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/logging.h"
1647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/proxyinfo.h"
1747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/socketserver.h"
1847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/thread.h"
1947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#include "webrtc/base/sslsocketfactory.h"  // Deprecated include
2047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
2147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgnamespace rtc {
2247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
2347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org///////////////////////////////////////////////////////////////////////////////
2447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org// HttpRequest
2547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org///////////////////////////////////////////////////////////////////////////////
2647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
2747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgclass FirewallManager;
2847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgclass MemoryStream;
2947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
3047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgclass HttpRequest {
3147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgpublic:
3247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpRequest(const std::string &user_agent);
3347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
3447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void Send();
3547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
3647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_proxy(const ProxyInfo& proxy) {
3747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    proxy_ = proxy;
3847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
3947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_firewall(FirewallManager * firewall) {
4047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    firewall_ = firewall;
4147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
4247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
4347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // The DNS name of the host to connect to.
4447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  const std::string& host() { return host_; }
4547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_host(const std::string& host) { host_ = host; }
4647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
4747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // The port to connect to on the target host.
4847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int port() { return port_; }
4947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_port(int port) { port_ = port; }
5047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
5147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org   // Whether the request should use SSL.
5247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool secure() { return secure_; }
5347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_secure(bool secure) { secure_ = secure; }
5447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
5547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // Returns the redirect when redirection occurs
5647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  const std::string& response_redirect() { return response_redirect_; }
5747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
5847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // Time to wait on the download, in ms.  Default is 5000 (5s)
5947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int timeout() { return timeout_; }
6047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_timeout(int timeout) { timeout_ = timeout; }
6147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
6247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  // Fail redirects to allow analysis of redirect urls, etc.
6347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool fail_redirect() const { return fail_redirect_; }
6447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_fail_redirect(bool fail_redirect) { fail_redirect_ = fail_redirect; }
6547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
6647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpRequestData& request() { return client_.request(); }
6747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpResponseData& response() { return client_.response(); }
6847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpErrorType error() { return error_; }
6947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
7047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgprotected:
7147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void set_error(HttpErrorType error) { error_ = error; }
7247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
7347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgprivate:
7447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  ProxyInfo proxy_;
7547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  FirewallManager * firewall_;
7647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  std::string host_;
7747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int port_;
7847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool secure_;
7947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  int timeout_;
8047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool fail_redirect_;
8147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpClient client_;
8247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpErrorType error_;
8347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  std::string response_redirect_;
8447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org};
8547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
8647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org///////////////////////////////////////////////////////////////////////////////
8747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org// HttpMonitor
8847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org///////////////////////////////////////////////////////////////////////////////
8947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
9047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgclass HttpMonitor : public sigslot::has_slots<> {
9147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgpublic:
9247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpMonitor(SocketServer *ss);
9347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
9447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void reset() {
9547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    complete_ = false;
9647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org    error_ = HE_DEFAULT;
9747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  }
9847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
9947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool done() const { return complete_; }
10047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpErrorType error() const { return error_; }
10147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
10247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void Connect(HttpClient* http);
10347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  void OnHttpClientComplete(HttpClient * http, HttpErrorType error);
10447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
10547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.orgprivate:
10647be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  bool complete_;
10747be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  HttpErrorType error_;
10847be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org  SocketServer *ss_;
10947be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org};
11047be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
11147be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org///////////////////////////////////////////////////////////////////////////////
11247be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
11347be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org}  // namespace rtc_
11447be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org
11547be73b8629244d6bb63a28198f97f040ce53d21henrike@webrtc.org#endif  // _HTTPREQUEST_H_
116