From f00edeb7e364656cbe11784edd33a6af43d32038 Mon Sep 17 00:00:00 2001 From: Niels Sascha Reedijk Date: Sat, 12 May 2012 10:37:07 +0000 Subject: [PATCH] Automatically pick port 443 for HTTPS --- headers/os/net/UrlProtocolHttp.h | 2 ++ src/kits/network/libnetapi/UrlProtocolHttp.cpp | 17 +++++++++++------ src/kits/network/libnetapi/UrlRequest.cpp | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/headers/os/net/UrlProtocolHttp.h b/headers/os/net/UrlProtocolHttp.h index c7024330c8..1902827f80 100644 --- a/headers/os/net/UrlProtocolHttp.h +++ b/headers/os/net/UrlProtocolHttp.h @@ -23,6 +23,7 @@ class BAbstractSocket; class BUrlProtocolHttp : public BUrlProtocol { public: BUrlProtocolHttp(BUrl& url, bool ssl = false, + const char *protocolName = "HTTP", BUrlProtocolListener* listener = NULL, BUrlContext* context = NULL, BUrlResult* result = NULL); @@ -62,6 +63,7 @@ private: private: BAbstractSocket* fSocket; BNetworkAddress fRemoteAddr; + bool fSSL; int8 fRequestMethod; int8 fHttpVersion; diff --git a/src/kits/network/libnetapi/UrlProtocolHttp.cpp b/src/kits/network/libnetapi/UrlProtocolHttp.cpp index fdf764608d..40936492be 100644 --- a/src/kits/network/libnetapi/UrlProtocolHttp.cpp +++ b/src/kits/network/libnetapi/UrlProtocolHttp.cpp @@ -32,10 +32,11 @@ static const char* kHttpProtocolThreadStrStatus[ BUrlProtocolHttp::BUrlProtocolHttp(BUrl& url, bool ssl, - BUrlProtocolListener* listener, BUrlContext* context, - BUrlResult* result) + const char *protocolName, BUrlProtocolListener* listener, + BUrlContext* context, BUrlResult* result) : - BUrlProtocol(url, listener, context, result, "BUrlProtocol.HTTP", "HTTP"), + BUrlProtocol(url, listener, context, result, "BUrlProtocol.HTTP", protocolName), + fSSL(ssl), fRequestMethod(B_HTTP_GET), fHttpVersion(B_HTTP_11) { @@ -337,9 +338,13 @@ BUrlProtocolHttp::_ResolveHostName() if (fUrl.HasPort()) fRemoteAddr = BNetworkAddress(fUrl.Host(), fUrl.Port()); - else - fRemoteAddr = BNetworkAddress(fUrl.Host(), 80); - + else { + if (fSSL) + fRemoteAddr = BNetworkAddress(fUrl.Host(), 443); + else + fRemoteAddr = BNetworkAddress(fUrl.Host(), 80); + } + if (fRemoteAddr.InitCheck() != B_OK) return false; diff --git a/src/kits/network/libnetapi/UrlRequest.cpp b/src/kits/network/libnetapi/UrlRequest.cpp index e04ce1303a..975cb4804f 100644 --- a/src/kits/network/libnetapi/UrlRequest.cpp +++ b/src/kits/network/libnetapi/UrlRequest.cpp @@ -136,13 +136,13 @@ BUrlRequest::Identify() fUrlProtocol = NULL; if (fUrl.Protocol() == "http") { - fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, false, + fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, false, "HTTP", fListener, fContext, &fResult); fReady = true; return B_OK; } else if (fUrl.Protocol() == "https") { - fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, true, + fUrlProtocol = new(std::nothrow) BUrlProtocolHttp(fUrl, true, "HTTPS", fListener, fContext, &fResult); fReady = true;