浏览代码

add set_allow_proxy

David Rose 22 年之前
父节点
当前提交
b6ad0bf0aa
共有 3 个文件被更改,包括 38 次插入1 次删除
  1. 30 0
      panda/src/downloader/httpChannel.I
  2. 4 1
      panda/src/downloader/httpChannel.cxx
  3. 4 0
      panda/src/downloader/httpChannel.h

+ 30 - 0
panda/src/downloader/httpChannel.I

@@ -211,6 +211,36 @@ get_persistent_connection() const {
   return _persistent_connection;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: HTTPChannel::set_allow_proxy
+//       Access: Published
+//  Description: If this is true (the normal case), the HTTPClient
+//               will be consulted for information about the proxy to
+//               be used for each connection via this HTTPChannel.  If
+//               this has been set to false by the user, then all
+//               connections will be made directly, regardless of the
+//               proxy settings indicated on the HTTPClient.
+////////////////////////////////////////////////////////////////////
+INLINE void HTTPChannel::
+set_allow_proxy(bool allow_proxy) {
+  _allow_proxy = allow_proxy;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: HTTPChannel::get_allow_proxy
+//       Access: Published
+//  Description: If this is true (the normal case), the HTTPClient
+//               will be consulted for information about the proxy to
+//               be used for each connection via this HTTPChannel.  If
+//               this has been set to false by the user, then all
+//               connections will be made directly, regardless of the
+//               proxy settings indicated on the HTTPClient.
+////////////////////////////////////////////////////////////////////
+INLINE bool HTTPChannel::
+get_allow_proxy() const {
+  return _allow_proxy;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: HTTPChannel::set_connect_timeout
 //       Access: Published

+ 4 - 1
panda/src/downloader/httpChannel.cxx

@@ -43,6 +43,7 @@ HTTPChannel(HTTPClient *client) :
 {
   _proxy_next_index = 0;
   _persistent_connection = false;
+  _allow_proxy = true;
   _connect_timeout = connect_timeout;
   _http_timeout = http_timeout;
   _blocking_connect = false;
@@ -1794,7 +1795,9 @@ begin_request(HTTPEnum::Method method, const DocumentSpec &url,
   // Get the set of proxies that are appropriate for this URL.
   _proxies.clear();
   _proxy_next_index = 0;
-  _client->get_proxies_for_url(url.get_url(), _proxies);
+  if (get_allow_proxy()) {
+    _client->get_proxies_for_url(url.get_url(), _proxies);
+  }
 
   // If we still have a live connection to a proxy that is on the
   // list, that proxy should be moved immediately to the front of the

+ 4 - 0
panda/src/downloader/httpChannel.h

@@ -91,6 +91,9 @@ PUBLISHED:
   INLINE void set_persistent_connection(bool persistent_connection);
   INLINE bool get_persistent_connection() const;
 
+  INLINE void set_allow_proxy(bool allow_proxy);
+  INLINE bool get_allow_proxy() const;
+
   INLINE void set_connect_timeout(double timeout_seconds);
   INLINE double get_connect_timeout() const;
   INLINE void set_blocking_connect(bool blocking_connect);
@@ -221,6 +224,7 @@ private:
   PT(BioPtr) _bio;
   PT(BioStreamPtr) _source;
   bool _persistent_connection;
+  bool _allow_proxy;
   double _connect_timeout;
   double _http_timeout;
   bool _blocking_connect;