]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
fixed the host/proxy name issue when re-using a connection and made IDN names
authorDaniel Stenberg <daniel@haxx.se>
Thu, 29 Apr 2004 13:41:48 +0000 (13:41 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 29 Apr 2004 13:41:48 +0000 (13:41 +0000)
work when using proxy by converting the IDN-name to the ACE-encoded version
before the request-URL is passed to the proxy.

lib/http.c
lib/url.c

index 4c517eb0e23da03074551880e72a88a728b128ea..fb538e51664166f990a45a44d2a35de6f40c3428 100644 (file)
@@ -1398,7 +1398,40 @@ CURLcode Curl_http(struct connectdata *conn)
   if (conn->bits.httpproxy &&
       !data->set.tunnel_thru_httpproxy &&
       !(conn->protocol&PROT_HTTPS))  {
-    /* The path sent to the proxy is in fact the entire URL */
+    /* The path sent to the proxy is in fact the entire URL. But if the remote
+       host is a IDN-name, we must make sure that the request we produce only
+       uses the encoded host name! */
+    if(conn->host.dispname != conn->host.name) {
+      char *url = data->change.url;
+      char *ptr = strstr(url, conn->host.dispname);
+      if(ptr) {
+        /* This is where the display name starts in the URL, now replace this
+           part with the encoded name. TODO: This method of replacing the host
+           name is rather crude as I believe there's a slight risk that the
+           user has entered a user name or password that contain the host name
+           string. */
+        size_t currlen = strlen(conn->host.dispname);
+        size_t newlen = strlen(conn->host.name);
+        size_t urllen = strlen(url);
+        
+        char *newurl;
+        
+        newurl = malloc(urllen + newlen - currlen + 1);
+
+        /* copy the part before the host name */
+        memcpy(newurl, url, ptr - url);
+        /* append the new host name instead of the old */
+        memcpy(newurl + (ptr - url), conn->host.name, newlen);
+        /* append the piece after the host name */
+        memcpy(newurl + newlen + (ptr - url),
+               ptr + currlen, /* copy the trailing zero byte too */
+               urllen - (ptr-url) - currlen + 1);
+        if(data->change.url_alloc)
+          free(data->change.url);
+        data->change.url = newurl;
+        data->change.url_alloc = TRUE;
+      }
+    }
     ppath = data->change.url;
   }
   if(HTTPREQ_POST_FORM == httpreq) {
index 9c27b1cba2048316d597cd2a602724b7d83a974f..7962d264edb848f759a22c5013c940d6476051cf 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -2963,12 +2963,7 @@ static CURLcode CreateConnection(struct SessionHandle *data,
     /* get the newly set value, not the old one */
     conn->bits.no_body = old_conn->bits.no_body;
 
-    free(conn->host.rawalloc); /* free the newly allocated name buffer */
-    conn->host.rawalloc = old_conn->host.rawalloc; /* use the old one */
-    conn->host.name = old_conn->host.name;
-
-    conn->host.encalloc = old_conn->host.encalloc; /* use the old one */
-    conn->host.dispname = old_conn->host.dispname;
+    free(old_conn->host.rawalloc); /* free the newly allocated name buffer */
 
     free(conn->pathbuffer); /* free the newly allocated path pointer */
     conn->pathbuffer = old_conn->pathbuffer; /* use the old one */
@@ -3017,7 +3012,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
 
     *in_connect = conn;      /* return this instead! */
 
-    infof(data, "Re-using existing connection! (#%d)\n", conn->connectindex);
+    infof(data, "Re-using existing connection! (#%d) with host %s\n",
+          conn->connectindex, conn->host.dispname);
   }
   else {
     /*
@@ -3381,7 +3377,8 @@ CURLcode Curl_done(struct connectdata *conn)
       result = res2;
   }
   else
-    infof(data, "Connection #%d left intact\n", conn->connectindex);
+    infof(data, "Connection #%d to host %s left intact\n",
+          conn->connectindex, conn->host.dispname);
 
   return result;
 }