verbose messages: fixed output of hostnames in re-used connections
authorDaniel Stenberg <daniel@haxx.se>
Wed, 8 Aug 2012 11:49:35 +0000 (13:49 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 8 Aug 2012 11:57:56 +0000 (13:57 +0200)
I suspect this is a regression introduced in commit 207cf150, included
since 7.24.0.

Avoid showing '(nil)' as hostname in verbose output by making sure the
hostname fixup function is called early enough to set the pointers that
are used for this. The name data is set again for each request even for
re-used connections to handle multiple hostnames over the same
connection (like with proxy) or that the casing etc of the host name is
changed between requests (which has proven to be important at least once
in the past).

Test1011 was modified to use a redirect with a re-used a connection
since it then showed the bug and now lo longer does. There's currently
no easy way to have the test suite detect 'nil' texts in verbose ouputs
so no tests will detect if this problem gets reintroduced.

Bug: http://curl.haxx.se/mail/lib-2012-07/0111.html
Reported by: Gisle Vanem

lib/url.c
tests/data/test1011

index 567f1de..c2f4882 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -4659,13 +4659,12 @@ static CURLcode resolve_server(struct SessionHandle *data,
   /*************************************************************
    * Resolve the name of the server or proxy
    *************************************************************/
-  if(conn->bits.reuse) {
-    /* We're reusing the connection - no need to resolve anything */
+  if(conn->bits.reuse)
+    /* We're reusing the connection - no need to resolve anything, and
+       fix_hostname() was called already in create_conn() for the re-use
+       case. */
     *async = FALSE;
 
-    if(conn->bits.proxy)
-      fix_hostname(data, conn, &conn->host);
-  }
   else {
     /* this is a fresh connect */
     int rc;
@@ -5136,6 +5135,10 @@ static CURLcode create_conn(struct SessionHandle *data,
     free(conn);          /* we don't need this anymore */
     conn = conn_temp;
     *in_connect = conn;
+
+    /* set a pointer to the hostname we display */
+    fix_hostname(data, conn, &conn->host);
+
     infof(data, "Re-using existing connection! (#%ld) with host %s\n",
           conn->connectindex,
           conn->proxy.name?conn->proxy.dispname:conn->host.dispname);
index 62ba074..59829c9 100644 (file)
@@ -10,10 +10,10 @@ followlocation
 # Server-side
 <reply>
 <data>
-HTTP/1.1 301 OK swsclose\r
+HTTP/1.1 301 OK\r
 Location: moo.html&testcase=/10110002\r
 Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Connection: close\r
+Content-Length: 0\r
 \r
 </data>
 <data2>
@@ -25,10 +25,10 @@ Connection: close
 body
 </data2>
 <datacheck>
-HTTP/1.1 301 OK swsclose\r
+HTTP/1.1 301 OK\r
 Location: moo.html&testcase=/10110002\r
 Date: Thu, 09 Nov 2010 14:49:00 GMT\r
-Connection: close\r
+Content-Length: 0\r
 \r
 HTTP/1.1 200 OK swsclose
 Location: this should be ignored