diff --git a/panda/src/downloader/httpChannel.cxx b/panda/src/downloader/httpChannel.cxx index d1d75e1f25..5fb2117616 100644 --- a/panda/src/downloader/httpChannel.cxx +++ b/panda/src/downloader/httpChannel.cxx @@ -1456,7 +1456,7 @@ begin_request(HTTPEnum::Method method, const URLSpec &url, // requested a direct connection somewhere. ostringstream request; request - << "CONNECT " << _url.get_server() << ":" << _url.get_port() + << "CONNECT " << _url.get_server_and_port() << " " << _client->get_http_version_string() << "\r\n"; if (_client->get_http_version() >= HTTPEnum::HV_11) { request @@ -2177,12 +2177,9 @@ make_proxy_request_text() { _proxy_request_text = _proxy_header; if (_proxy_auth != (HTTPAuthorization *)NULL && !_proxy_username.empty()) { - ostringstream strm; - strm << _url.get_server() << ":" << _url.get_port(); - _proxy_request_text += "Proxy-Authorization: "; _proxy_request_text += - _proxy_auth->generate(HTTPEnum::M_connect, strm.str(), + _proxy_auth->generate(HTTPEnum::M_connect, _url.get_server_and_port(), _proxy_username, _body); _proxy_request_text += "\r\n"; } diff --git a/panda/src/downloader/urlSpec.cxx b/panda/src/downloader/urlSpec.cxx index 4e47aee74d..ac5c43482d 100644 --- a/panda/src/downloader/urlSpec.cxx +++ b/panda/src/downloader/urlSpec.cxx @@ -98,6 +98,24 @@ get_port() const { } } +//////////////////////////////////////////////////////////////////// +// Function: URLSpec::get_server_and_port +// Access: Published +// Description: Returns a string consisting of the server name, +// followed by a colon, followed by the port number. If +// the port number is not explicitly given in the URL, +// this string will include the implicit port number. +//////////////////////////////////////////////////////////////////// +string URLSpec:: +get_server_and_port() const { + if (has_port()) { + return _url.substr(_server_start, _port_end - _server_start); + } + ostringstream strm; + strm << get_server() << ":" << get_port(); + return strm.str(); +} + //////////////////////////////////////////////////////////////////// // Function: URLSpec::get_path // Access: Published @@ -297,6 +315,28 @@ set_port(int port) { set_port(str.str()); } +//////////////////////////////////////////////////////////////////// +// Function: URLSpec::set_server_and_port +// Access: Published +// Description: Replaces the server and port parts of the URL +// specification simultaneously. The input string +// should be of the form "server:port", or just +// "server" to make the port number implicit. +//////////////////////////////////////////////////////////////////// +void URLSpec:: +set_server_and_port(const string &server_and_port) { + if (server_and_port.empty() && !has_authority()) { + return; + } + string authority; + + if (has_username()) { + authority = get_username() + "@"; + } + authority += server_and_port; + set_authority(authority); +} + //////////////////////////////////////////////////////////////////// // Function: URLSpec::set_path // Access: Published @@ -684,6 +724,8 @@ unquote_plus(const string &source) { //////////////////////////////////////////////////////////////////// void URLSpec:: parse_authority() { + _flags &= ~(F_has_username | F_has_server | F_has_port); + if (!has_authority()) { return; } diff --git a/panda/src/downloader/urlSpec.h b/panda/src/downloader/urlSpec.h index 66ea971baa..6fe34bdaa3 100644 --- a/panda/src/downloader/urlSpec.h +++ b/panda/src/downloader/urlSpec.h @@ -56,6 +56,7 @@ PUBLISHED: INLINE string get_server() const; INLINE string get_port_str() const; int get_port() const; + string get_server_and_port() const; string get_path() const; INLINE string get_query() const; @@ -67,6 +68,7 @@ PUBLISHED: void set_server(const string &server); void set_port(const string &port); void set_port(int port); + void set_server_and_port(const string &server_and_port); void set_path(const string &path); void set_query(const string &query);