David Rose 23 years ago
parent
commit
88ad844981
2 changed files with 34 additions and 5 deletions
  1. 25 5
      panda/src/downloader/httpClient.cxx
  2. 9 0
      panda/src/downloader/httpDocument.cxx

+ 25 - 5
panda/src/downloader/httpClient.cxx

@@ -199,7 +199,10 @@ get_https_proxy(const URLSpec &url, const string &body) {
       << "CONNECT " << url.get_authority() << " HTTP/1.1\r\n"
       << "\r\n";
     string request_str = request.str();
-    
+
+    if (downloader_cat.is_debug()) {
+      downloader_cat.debug() << "send:\n" << request_str << "\n";
+    }
     BIO_puts(bio, request_str.c_str());
   }
 
@@ -213,10 +216,14 @@ get_https_proxy(const URLSpec &url, const string &body) {
         << ": " << doc->get_status_code() << " "
         << doc->get_status_string() << "\n";
       
-      // If the proxy won't open a raw connection for us, see if it will
-      // handle the https communication directly.
-      BIO_free_all(bio);
-      return get_http_proxy(url, body);
+      // If the proxy refused to open a raw connection for us, see if
+      // it will handle the https communication directly.  For other
+      // error codes, just return error.
+      if ((doc->get_status_code() / 100) == 4) {
+        BIO_free_all(bio);
+        return get_http_proxy(url, body);
+      }
+      return NULL;
     }
   }
 
@@ -231,6 +238,16 @@ get_https_proxy(const URLSpec &url, const string &body) {
   nassertr(ssl != (SSL *)NULL, NULL);
   SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
 
+  if (BIO_do_handshake(sbio) <= 0) {
+    downloader_cat.info()
+      << "Could not establish SSL handshake with " 
+      << url.get_server() << ":" << url.get_port() << "\n";
+#ifndef NDEBUG
+    ERR_print_errors_fp(stderr);
+#endif
+    return NULL;
+  }
+
   send_get_request(sbio, url.get_path(), url.get_server(), body);
   return sbio;
 }
@@ -265,5 +282,8 @@ send_get_request(BIO *bio,
   }
 
   string request_str = request.str();
+  if (downloader_cat.is_debug()) {
+    downloader_cat.debug() << "send:\n" << request_str << "\n";
+  }
   BIO_puts(bio, request_str.c_str());
 }

+ 9 - 0
panda/src/downloader/httpDocument.cxx

@@ -165,6 +165,9 @@ read_headers() {
   if (!line.empty() && line[line.length() - 1] == '\r') {
     line = line.substr(0, line.length() - 1);
   }
+  if (downloader_cat.is_debug()) {
+    downloader_cat.debug() << "recv: " << line << "\n";
+  }
   if (!(*_source) || line.length() < 5 || line.substr(0, 5) != "HTTP/") {
     // Not an HTTP response.
     _status_code = 0;
@@ -203,6 +206,9 @@ read_headers() {
   if (!line.empty() && line[line.length() - 1] == '\r') {
     line = line.substr(0, line.length() - 1);
   }
+  if (downloader_cat.is_debug()) {
+    downloader_cat.debug() << "recv: " << line << "\n";
+  }
   while (!_source->eof() && !_source->fail() && !line.empty()) {
     if (isspace(line[0])) {
       // If the line begins with a space, that continues the previous
@@ -236,6 +242,9 @@ read_headers() {
     if (!line.empty() && line[line.length() - 1] == '\r') {
       line = line.substr(0, line.length() - 1);
     }
+    if (downloader_cat.is_debug()) {
+      downloader_cat.debug() << "recv: " << line << "\n";
+    }
   }
   if (!field_name.empty()) {
     _headers[field_name] = field_value;