Explorar o código

server_and_port

David Rose %!s(int64=23) %!d(string=hai) anos
pai
achega
36853fa4c3

+ 2 - 5
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";
   }

+ 42 - 0
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;
   }

+ 2 - 0
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);