You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.2 KiB

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