Ver Fonte

gstatic.com doesn't want a port number

David Rose há 16 anos atrás
pai
commit
b7134366df

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

@@ -3570,8 +3570,17 @@ make_header() {
     << _client->get_http_version_string() << "\r\n";
 
   if (_client->get_http_version() >= HTTPEnum::HV_11) {
+    
     stream 
-      << "Host: " << _request.get_url().get_server_and_port() << "\r\n";
+      << "Host: " << _request.get_url().get_server();
+    if (!_request.get_url().is_default_port()) {
+      // It appears that some servers (notably gstatic.com) might
+      // return a 404 if you include an explicit port number in with
+      // the Host: header, even if it is the default port.  So, don't
+      // include the port number unless we need to.
+      stream << ":" << _request.get_url().get_port();
+    }
+    stream << "\r\n";
     if (!get_persistent_connection()) {
       stream
         << "Connection: close\r\n";

+ 33 - 5
panda/src/downloader/urlSpec.cxx

@@ -85,16 +85,44 @@ get_port() const {
   if (has_port()) {
     return _port;
   }
-  string scheme = get_scheme();
-  if (scheme == "https") {
+  return get_default_port_for_scheme(get_scheme());
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: URLSpec::is_default_port
+//       Access: Published
+//  Description: Returns true if the port number encoded in this URL
+//               is the default port number for the scheme (or if
+//               there is no port number), or false if it is a
+//               nonstandard port.
+////////////////////////////////////////////////////////////////////
+bool URLSpec::
+is_default_port() const {
+  if (!has_port()) {
+    return true;
+  }
+  return (_port == get_default_port_for_scheme(get_scheme()));
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: URLSpec::get_default_port_for_scheme
+//       Access: Published, Static
+//  Description: Returns the default port number for the indicated
+//               scheme, or 0 if there is no known default.
+////////////////////////////////////////////////////////////////////
+int URLSpec::
+get_default_port_for_scheme(const string &scheme) {
+  if (scheme == "http" || scheme.empty()) {
+    return 80;
+
+  } else if (scheme == "https") {
     return 443;
 
   } else if (scheme == "socks") {
     return 1080;
-
-  } else { // == "http"
-    return 80;
   }
+
+  return 0;
 }
 
 ////////////////////////////////////////////////////////////////////

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

@@ -54,6 +54,8 @@ PUBLISHED:
   INLINE string get_port_str() const;
   int get_port() const;
   string get_server_and_port() const;
+  bool is_default_port() const;
+  static int get_default_port_for_scheme(const string &scheme);
   string get_path() const;
   INLINE string get_query() const;
   string get_path_and_query() const;