connection reuse: IDN host names fixed
Use the ACE form of IDN hostnames as key in the connection cache. Add new tests. Closes #592
This commit is contained in:
		 Michael Kaufmann
					Michael Kaufmann
				
			
				
					committed by
					
						 Daniel Stenberg
						Daniel Stenberg
					
				
			
			
				
	
			
			
			 Daniel Stenberg
						Daniel Stenberg
					
				
			
						parent
						
							336e8feec4
						
					
				
				
					commit
					d9b4d1ce20
				
			
							
								
								
									
										56
									
								
								lib/url.c
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								lib/url.c
									
									
									
									
									
								
							| @@ -142,6 +142,7 @@ static struct connectdata * | |||||||
| find_oldest_idle_connection_in_bundle(struct SessionHandle *data, | find_oldest_idle_connection_in_bundle(struct SessionHandle *data, | ||||||
|                                       struct connectbundle *bundle); |                                       struct connectbundle *bundle); | ||||||
| static void conn_free(struct connectdata *conn); | static void conn_free(struct connectdata *conn); | ||||||
|  | static void free_fixed_hostname(struct hostname *host); | ||||||
| static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke); | static void signalPipeClose(struct curl_llist *pipeline, bool pipe_broke); | ||||||
| static CURLcode parse_url_login(struct SessionHandle *data, | static CURLcode parse_url_login(struct SessionHandle *data, | ||||||
|                                 struct connectdata *conn, |                                 struct connectdata *conn, | ||||||
| @@ -2798,23 +2799,8 @@ CURLcode Curl_disconnect(struct connectdata *conn, bool dead_connection) | |||||||
|   infof(data, "Closing connection %ld\n", conn->connection_id); |   infof(data, "Closing connection %ld\n", conn->connection_id); | ||||||
|   Curl_conncache_remove_conn(data->state.conn_cache, conn); |   Curl_conncache_remove_conn(data->state.conn_cache, conn); | ||||||
|  |  | ||||||
| #if defined(USE_LIBIDN) |   free_fixed_hostname(&conn->host); | ||||||
|   if(conn->host.encalloc) |   free_fixed_hostname(&conn->proxy); | ||||||
|     idn_free(conn->host.encalloc); /* encoded host name buffer, must be freed |  | ||||||
|                                       with idn_free() since this was allocated |  | ||||||
|                                       by libidn */ |  | ||||||
|   if(conn->proxy.encalloc) |  | ||||||
|     idn_free(conn->proxy.encalloc); /* encoded proxy name buffer, must be |  | ||||||
|                                        freed with idn_free() since this was |  | ||||||
|                                        allocated by libidn */ |  | ||||||
| #elif defined(USE_WIN32_IDN) |  | ||||||
|   free(conn->host.encalloc); /* encoded host name buffer, must be freed with |  | ||||||
|                                 idn_free() since this was allocated by |  | ||||||
|                                 curl_win32_idn_to_ascii */ |  | ||||||
|   free(conn->proxy.encalloc); /* encoded proxy name buffer, must be freed |  | ||||||
|                                  with idn_free() since this was allocated by |  | ||||||
|                                  curl_win32_idn_to_ascii */ |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
|   Curl_ssl_close(conn, FIRSTSOCKET); |   Curl_ssl_close(conn, FIRSTSOCKET); | ||||||
|  |  | ||||||
| @@ -3786,6 +3772,24 @@ static void fix_hostname(struct SessionHandle *data, | |||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | /* | ||||||
|  |  * Frees data allocated by fix_hostname() | ||||||
|  |  */ | ||||||
|  | static void free_fixed_hostname(struct hostname *host) | ||||||
|  | { | ||||||
|  | #if defined(USE_LIBIDN) | ||||||
|  |   if(host->encalloc) { | ||||||
|  |     idn_free(host->encalloc); /* must be freed with idn_free() since this was | ||||||
|  |                                  allocated by libidn */ | ||||||
|  |     host->encalloc = NULL; | ||||||
|  |   } | ||||||
|  | #elif defined(USE_WIN32_IDN) | ||||||
|  |   free(host->encalloc); /* must be freed withidn_free() since this was | ||||||
|  |                            allocated by curl_win32_idn_to_ascii */ | ||||||
|  |   host->encalloc = NULL; | ||||||
|  | #endif | ||||||
|  | } | ||||||
|  |  | ||||||
| static void llist_dtor(void *user, void *element) | static void llist_dtor(void *user, void *element) | ||||||
| { | { | ||||||
|   (void)user; |   (void)user; | ||||||
| @@ -5242,9 +5246,6 @@ static CURLcode resolve_server(struct SessionHandle *data, | |||||||
|     int rc; |     int rc; | ||||||
|     struct Curl_dns_entry *hostaddr; |     struct Curl_dns_entry *hostaddr; | ||||||
|  |  | ||||||
|     /* set a pointer to the hostname we display */ |  | ||||||
|     fix_hostname(data, conn, &conn->host); |  | ||||||
|  |  | ||||||
| #ifdef USE_UNIX_SOCKETS | #ifdef USE_UNIX_SOCKETS | ||||||
|     if(data->set.str[STRING_UNIX_SOCKET_PATH]) { |     if(data->set.str[STRING_UNIX_SOCKET_PATH]) { | ||||||
|       /* Unix domain sockets are local. The host gets ignored, just use the |       /* Unix domain sockets are local. The host gets ignored, just use the | ||||||
| @@ -5294,9 +5295,6 @@ static CURLcode resolve_server(struct SessionHandle *data, | |||||||
|     else { |     else { | ||||||
|       /* This is a proxy that hasn't been resolved yet. */ |       /* This is a proxy that hasn't been resolved yet. */ | ||||||
|  |  | ||||||
|       /* IDN-fix the proxy name */ |  | ||||||
|       fix_hostname(data, conn, &conn->proxy); |  | ||||||
|  |  | ||||||
|       /* resolve proxy */ |       /* resolve proxy */ | ||||||
|       rc = Curl_resolv_timeout(conn, conn->proxy.name, (int)conn->port, |       rc = Curl_resolv_timeout(conn, conn->proxy.name, (int)conn->port, | ||||||
|                                &hostaddr, timeout_ms); |                                &hostaddr, timeout_ms); | ||||||
| @@ -5328,6 +5326,7 @@ static CURLcode resolve_server(struct SessionHandle *data, | |||||||
| static void reuse_conn(struct connectdata *old_conn, | static void reuse_conn(struct connectdata *old_conn, | ||||||
|                        struct connectdata *conn) |                        struct connectdata *conn) | ||||||
| { | { | ||||||
|  |   free_fixed_hostname(&old_conn->proxy); | ||||||
|   free(old_conn->proxy.rawalloc); |   free(old_conn->proxy.rawalloc); | ||||||
|  |  | ||||||
|   /* free the SSL config struct from this connection struct as this was |   /* free the SSL config struct from this connection struct as this was | ||||||
| @@ -5362,6 +5361,7 @@ static void reuse_conn(struct connectdata *old_conn, | |||||||
|  |  | ||||||
|   /* host can change, when doing keepalive with a proxy or if the case is |   /* host can change, when doing keepalive with a proxy or if the case is | ||||||
|      different this time etc */ |      different this time etc */ | ||||||
|  |   free_fixed_hostname(&conn->host); | ||||||
|   Curl_safefree(conn->host.rawalloc); |   Curl_safefree(conn->host.rawalloc); | ||||||
|   conn->host=old_conn->host; |   conn->host=old_conn->host; | ||||||
|  |  | ||||||
| @@ -5650,6 +5650,13 @@ static CURLcode create_conn(struct SessionHandle *data, | |||||||
|   if((conn->given->flags&PROTOPT_SSL) && conn->bits.httpproxy) |   if((conn->given->flags&PROTOPT_SSL) && conn->bits.httpproxy) | ||||||
|     conn->bits.tunnel_proxy = TRUE; |     conn->bits.tunnel_proxy = TRUE; | ||||||
|  |  | ||||||
|  |   /************************************************************* | ||||||
|  |    * IDN-fix the hostnames | ||||||
|  |    *************************************************************/ | ||||||
|  |   fix_hostname(data, conn, &conn->host); | ||||||
|  |   if(conn->proxy.name && *conn->proxy.name) | ||||||
|  |     fix_hostname(data, conn, &conn->proxy); | ||||||
|  |  | ||||||
|   /************************************************************* |   /************************************************************* | ||||||
|    * Figure out the remote port number and fix it in the URL |    * Figure out the remote port number and fix it in the URL | ||||||
|    *************************************************************/ |    *************************************************************/ | ||||||
| @@ -5794,9 +5801,6 @@ static CURLcode create_conn(struct SessionHandle *data, | |||||||
|     conn = conn_temp; |     conn = conn_temp; | ||||||
|     *in_connect = conn; |     *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 %s %s\n", |     infof(data, "Re-using existing connection! (#%ld) with %s %s\n", | ||||||
|           conn->connection_id, |           conn->connection_id, | ||||||
|           conn->bits.proxy?"proxy":"host", |           conn->bits.proxy?"proxy":"host", | ||||||
|   | |||||||
| @@ -168,4 +168,4 @@ test2008 test2009 test2010 test2011 test2012 test2013 test2014 test2015 \ | |||||||
| test2016 test2017 test2018 test2019 test2020 test2021 test2022 test2023 \ | test2016 test2017 test2018 test2019 test2020 test2021 test2022 test2023 \ | ||||||
| test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \ | test2024 test2025 test2026 test2027 test2028 test2029 test2030 test2031 \ | ||||||
| test2032 test2033 test2034 test2035 test2036 test2037 test2038 test2039 \ | test2032 test2033 test2034 test2035 test2036 test2037 test2038 test2039 \ | ||||||
| test2040 test2041 test2042 test2043 test2044 test2045 | test2040 test2041 test2042 test2043 test2044 test2045 test2046 test2047 | ||||||
|   | |||||||
							
								
								
									
										94
									
								
								tests/data/test2046
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								tests/data/test2046
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | |||||||
|  | <testcase> | ||||||
|  | <info> | ||||||
|  | <keywords> | ||||||
|  | HTTP | ||||||
|  | HTTP GET | ||||||
|  | IDN | ||||||
|  | followlocation | ||||||
|  | --write-out | ||||||
|  | </keywords> | ||||||
|  | </info> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Server-side | ||||||
|  | <reply> | ||||||
|  | <data nocheck="yes"> | ||||||
|  | HTTP/1.1 302 OK swsbounce | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 9 | ||||||
|  | Content-Type: text/plain | ||||||
|  | Location: ./20460001 | ||||||
|  |  | ||||||
|  | redirect | ||||||
|  | </data> | ||||||
|  | <data1 nocheck="yes"> | ||||||
|  | HTTP/1.1 200 OK | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 3 | ||||||
|  | Content-Type: text/plain; charset=us-ascii | ||||||
|  |  | ||||||
|  | OK | ||||||
|  | </data1> | ||||||
|  | </reply> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Client-side | ||||||
|  | <client> | ||||||
|  | <server> | ||||||
|  | http | ||||||
|  | </server> | ||||||
|  | <features> | ||||||
|  | idn | ||||||
|  | </features> | ||||||
|  | <setenv> | ||||||
|  | CHARSET=UTF-8 | ||||||
|  | </setenv> | ||||||
|  |  <name> | ||||||
|  | Connection re-use with IDN host name | ||||||
|  |  </name> | ||||||
|  |  | ||||||
|  |  <command> | ||||||
|  | http://åäö.se:%HTTPPORT/2046 --resolve xn--4cab6c.se:%HTTPPORT:%HOSTIP -w "%{num_connects}\n%{num_redirects}\n%{size_download}\n%{url_effective}\n%{content_type}\n%{response_code}\n" -L | ||||||
|  | </command> | ||||||
|  | </client> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Verify data after the test has been "shot" | ||||||
|  | <verify> | ||||||
|  | <strip> | ||||||
|  | ^User-Agent:.* | ||||||
|  | </strip> | ||||||
|  | <protocol> | ||||||
|  | GET /2046 HTTP/1.1 | ||||||
|  | Host: xn--4cab6c.se:%HTTPPORT | ||||||
|  | Accept: */* | ||||||
|  |  | ||||||
|  | GET /20460001 HTTP/1.1 | ||||||
|  | Host: xn--4cab6c.se:%HTTPPORT | ||||||
|  | Accept: */* | ||||||
|  |  | ||||||
|  | </protocol> | ||||||
|  |  | ||||||
|  | <stdout> | ||||||
|  | HTTP/1.1 302 OK swsbounce | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 9 | ||||||
|  | Content-Type: text/plain | ||||||
|  | Location: ./20460001 | ||||||
|  |  | ||||||
|  | HTTP/1.1 200 OK | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 3 | ||||||
|  | Content-Type: text/plain; charset=us-ascii | ||||||
|  |  | ||||||
|  | OK | ||||||
|  | 1 | ||||||
|  | 1 | ||||||
|  | 3 | ||||||
|  | http://åäö.se:%HTTPPORT/20460001 | ||||||
|  | text/plain; charset=us-ascii | ||||||
|  | 200 | ||||||
|  | </stdout> | ||||||
|  |  | ||||||
|  | </verify> | ||||||
|  | </testcase> | ||||||
							
								
								
									
										97
									
								
								tests/data/test2047
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								tests/data/test2047
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | |||||||
|  | <testcase> | ||||||
|  | <info> | ||||||
|  | <keywords> | ||||||
|  | HTTP | ||||||
|  | HTTP GET | ||||||
|  | HTTP proxy | ||||||
|  | IDN | ||||||
|  | followlocation | ||||||
|  | --write-out | ||||||
|  | </keywords> | ||||||
|  | </info> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Server-side | ||||||
|  | <reply> | ||||||
|  | <data nocheck="yes"> | ||||||
|  | HTTP/1.1 302 OK swsbounce | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 9 | ||||||
|  | Content-Type: text/plain | ||||||
|  | Location: ./20470001 | ||||||
|  |  | ||||||
|  | redirect | ||||||
|  | </data> | ||||||
|  | <data1 nocheck="yes"> | ||||||
|  | HTTP/1.1 200 OK | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 3 | ||||||
|  | Content-Type: text/plain; charset=us-ascii | ||||||
|  |  | ||||||
|  | OK | ||||||
|  | </data1> | ||||||
|  | </reply> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Client-side | ||||||
|  | <client> | ||||||
|  | <server> | ||||||
|  | http | ||||||
|  | </server> | ||||||
|  | <features> | ||||||
|  | idn | ||||||
|  | </features> | ||||||
|  | <setenv> | ||||||
|  | CHARSET=UTF-8 | ||||||
|  | </setenv> | ||||||
|  |  <name> | ||||||
|  | Connection re-use with IDN host name over HTTP proxy | ||||||
|  |  </name> | ||||||
|  |  | ||||||
|  |  <command> | ||||||
|  | http://åäö.se/2047 -x %HOSTIP:%HTTPPORT -w "%{num_connects}\n%{num_redirects}\n%{size_download}\n%{url_effective}\n%{content_type}\n%{response_code}\n" -L | ||||||
|  | </command> | ||||||
|  | </client> | ||||||
|  |  | ||||||
|  | # | ||||||
|  | # Verify data after the test has been "shot" | ||||||
|  | <verify> | ||||||
|  | <strip> | ||||||
|  | ^User-Agent:.* | ||||||
|  | </strip> | ||||||
|  | <protocol> | ||||||
|  | GET http://xn--4cab6c.se/2047 HTTP/1.1 | ||||||
|  | Host: xn--4cab6c.se | ||||||
|  | Accept: */* | ||||||
|  | Proxy-Connection: Keep-Alive | ||||||
|  |  | ||||||
|  | GET http://xn--4cab6c.se/20470001 HTTP/1.1 | ||||||
|  | Host: xn--4cab6c.se | ||||||
|  | Accept: */* | ||||||
|  | Proxy-Connection: Keep-Alive | ||||||
|  |  | ||||||
|  | </protocol> | ||||||
|  |  | ||||||
|  | <stdout> | ||||||
|  | HTTP/1.1 302 OK swsbounce | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 9 | ||||||
|  | Content-Type: text/plain | ||||||
|  | Location: ./20470001 | ||||||
|  |  | ||||||
|  | HTTP/1.1 200 OK | ||||||
|  | Date: Thu, 09 Nov 2010 14:49:00 GMT | ||||||
|  | Content-Length: 3 | ||||||
|  | Content-Type: text/plain; charset=us-ascii | ||||||
|  |  | ||||||
|  | OK | ||||||
|  | 1 | ||||||
|  | 1 | ||||||
|  | 3 | ||||||
|  | http://xn--4cab6c.se/20470001 | ||||||
|  | text/plain; charset=us-ascii | ||||||
|  | 200 | ||||||
|  | </stdout> | ||||||
|  |  | ||||||
|  | </verify> | ||||||
|  | </testcase> | ||||||
		Reference in New Issue
	
	Block a user