From c861dfdb7e58022b877c94a6f4ff3144854a240b Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 26 Jan 2015 09:38:15 +0100 Subject: [PATCH] HttpRequest: fix HTTP to HTTPS redirects When redirected from http to https, we did not switch to SSL and port 443 and kept using unencrypted http on port 80. --- src/kits/network/libnetapi/HttpRequest.cpp | 23 ++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 3f2f64d7b0..1da64c2ecc 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -79,10 +79,7 @@ BHttpRequest::BHttpRequest(const BUrl& url, bool ssl, const char* protocolName, fOptFollowLocation(true) { _ResetOptions(); - if (fSSL) - fSocket = new(std::nothrow) CheckedSecureSocket(this); - else - fSocket = new(std::nothrow) BSocket(); + fSocket = NULL; } @@ -105,10 +102,7 @@ BHttpRequest::BHttpRequest(const BHttpRequest& other) { _ResetOptions(); // FIXME some options may be copied from other instead. - if (fSSL) - fSocket = new(std::nothrow) CheckedSecureSocket(this); - else - fSocket = new(std::nothrow) BSocket(); + fSocket = NULL; } @@ -406,6 +400,12 @@ BHttpRequest::_ProtocolLoop() if (--maxRedirs > 0) { newRequest = true; + // Redirections may need a switch from http to https. + if (fUrl.Protocol() == "https") + fSSL = true; + else if (fUrl.Protocol() == "http") + fSSL = false; + _EmitDebug(B_URL_PROTOCOL_DEBUG_TEXT, "Following: %s\n", fUrl.UrlString().String()); @@ -472,6 +472,13 @@ BHttpRequest::_ProtocolLoop() status_t BHttpRequest::_MakeRequest() { + delete fSocket; + + if (fSSL) + fSocket = new(std::nothrow) CheckedSecureSocket(this); + else + fSocket = new(std::nothrow) BSocket(); + if (fSocket == NULL) return B_NO_MEMORY;