From 88ad8449818c9ea598ce56417803f23c0997ca02 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 25 Sep 2002 21:55:14 +0000 Subject: [PATCH] tweaks --- panda/src/downloader/httpClient.cxx | 30 ++++++++++++++++++++++----- panda/src/downloader/httpDocument.cxx | 9 ++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/panda/src/downloader/httpClient.cxx b/panda/src/downloader/httpClient.cxx index 9dafb97d9c..c37433b981 100644 --- a/panda/src/downloader/httpClient.cxx +++ b/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()); } diff --git a/panda/src/downloader/httpDocument.cxx b/panda/src/downloader/httpDocument.cxx index 7d9cf311bd..f7881effe6 100644 --- a/panda/src/downloader/httpDocument.cxx +++ b/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;