Browse Source

add URLSpec::is_ssl

David Rose 22 years ago
parent
commit
34dfb94e83

+ 5 - 5
panda/src/downloader/httpChannel.cxx

@@ -1813,16 +1813,16 @@ begin_request(HTTPEnum::Method method, const DocumentSpec &url,
 
 
   // An https-style request means we'll need to establish an SSL
   // An https-style request means we'll need to establish an SSL
   // connection.
   // connection.
-  _want_ssl = (_request.get_url().get_scheme() == "https");
+  _want_ssl = _request.get_url().is_ssl();
 
 
   _proxy_tunnel = false;
   _proxy_tunnel = false;
   _proxy_serves_document = false;
   _proxy_serves_document = false;
 
 
   if (!_proxy.empty()) {
   if (!_proxy.empty()) {
-    // If we're opening an SSL connection, or we ask for a direct
-    // connection of some kind, or if we have a SOCKS-style proxy,
-    // that demands a tunnel through the proxy to speak directly to
-    // the http server.
+    // If we're opening an SSL connection, or the user has explicitly
+    // asked for a direct connection of some kind, or if we have a
+    // SOCKS-style proxy; each of these demands a tunnel through the
+    // proxy to speak directly to the http server.
     _proxy_tunnel =
     _proxy_tunnel =
       (_want_ssl || _method == HTTPEnum::M_connect || _proxy.get_scheme() == "socks");
       (_want_ssl || _method == HTTPEnum::M_connect || _proxy.get_scheme() == "socks");
 
 

+ 22 - 0
panda/src/downloader/urlSpec.I

@@ -227,6 +227,28 @@ get_query() const {
   return _url.substr(_query_start);
   return _url.substr(_query_start);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: URLSpec::is_ssl
+//       Access: Published
+//  Description: Returns true if the URL's scheme specifies an
+//               SSL-secured protocol such as https, or false
+//               otherwise.
+////////////////////////////////////////////////////////////////////
+INLINE bool URLSpec::
+is_ssl() const {
+  if (has_scheme() && _scheme_end > 0) {
+    // If we have a scheme specification, assume it is SSL-secured if
+    // it ends in "s", except for the special case of "socks".
+    if (_url.substr(0, _scheme_end) == "socks") {
+      return false;
+    }
+    return (_url[_scheme_end - 1] == 's');
+  }
+
+  // If we have no scheme specification, it's not SSL-secured.
+  return false;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: URLSpec::get_url
 //     Function: URLSpec::get_url
 //       Access: Published
 //       Access: Published

+ 1 - 0
panda/src/downloader/urlSpec.h

@@ -60,6 +60,7 @@ PUBLISHED:
   string get_server_and_port() const;
   string get_server_and_port() const;
   string get_path() const;
   string get_path() const;
   INLINE string get_query() const;
   INLINE string get_query() const;
+  INLINE bool is_ssl() const;
 
 
   INLINE const string &get_url() const;
   INLINE const string &get_url() const;