Automatically pick port 443 for HTTPS

This commit is contained in:
Niels Sascha Reedijk 2012-05-12 10:37:07 +00:00 committed by Hamish Morrison
parent 4e607e1aae
commit f00edeb7e3
3 changed files with 15 additions and 8 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;