Permalink
Browse files

Merge branch 'dev' of https://github.com/cherokee/webserver

Conflicts:
	cherokee/source.c
  • Loading branch information...
2 parents 82e2482 + 4536bb7 commit 346efc7287f81be760cf709b5ec01ce1b78679b2 @skinkie committed Nov 21, 2011
@@ -291,6 +291,7 @@ ret_t cherokee_connection_instance_encoder (cherokee_connection_t *conn);
ret_t cherokee_connection_sleep (cherokee_connection_t *conn, cherokee_msec_t msecs);
void cherokee_connection_update_timeout (cherokee_connection_t *conn);
void cherokee_connection_add_expiration_header (cherokee_connection_t *conn, cherokee_buffer_t *buffer, cherokee_boolean_t use_maxage);
+ret_t cherokee_connection_build_host_string (cherokee_connection_t *conn, cherokee_buffer_t *buf);
ret_t cherokee_connection_build_host_port_string (cherokee_connection_t *conn, cherokee_buffer_t *buf);
/* Iteration
View
@@ -559,15 +559,38 @@ cherokee_connection_setup_error_handler (cherokee_connection_t *conn)
ret_t
cherokee_connection_setup_hsts_handler (cherokee_connection_t *conn)
{
- ret_t ret;
+ ret_t ret;
+ cherokee_list_t *i;
+ int port = -1;
+ cherokee_server_t *srv = CONN_SRV(conn);
/* Redirect to:
* "https://" + host + request + query_string
*/
- cherokee_buffer_clean (&conn->redirect);
+ cherokee_buffer_clean (&conn->redirect);
+
+ /* 1.- Proto */
cherokee_buffer_add_str (&conn->redirect, "https://");
- cherokee_connection_build_host_port_string (conn, &conn->redirect);
+ /* 2.- Host */
+ cherokee_connection_build_host_string (conn, &conn->redirect);
+
+ /* 3.- Port */
+ list_for_each (i, &srv->listeners) {
+ if (BIND_IS_TLS(i)) {
+ port = BIND(i)->port;
+ break;
+ }
+ }
+
+ if ((port != -1) &&
+ (! http_port_is_standard (port, true)))
+ {
+ cherokee_buffer_add_char (&conn->redirect, ':');
+ cherokee_buffer_add_ulong10 (&conn->redirect, port);
+ }
+
+ /* 4.- Request */
cherokee_buffer_add_buffer (&conn->redirect, &conn->request);
if (conn->query_string.len > 0) {
@@ -2958,8 +2981,8 @@ cherokee_connection_update_timeout (cherokee_connection_t *conn)
ret_t
-cherokee_connection_build_host_port_string (cherokee_connection_t *conn,
- cherokee_buffer_t *buf)
+cherokee_connection_build_host_string (cherokee_connection_t *conn,
+ cherokee_buffer_t *buf)
{
/* 1st choice: Request host */
if (! cherokee_buffer_is_empty (&conn->host)) {
@@ -2980,6 +3003,22 @@ cherokee_connection_build_host_port_string (cherokee_connection_t *conn,
cherokee_buffer_add_buffer (buf, &conn->bind->server_address);
}
+ return ret_ok;
+}
+
+ret_t
+cherokee_connection_build_host_port_string (cherokee_connection_t *conn,
+ cherokee_buffer_t *buf)
+{
+ ret_t ret;
+
+ /* Host
+ */
+ ret = cherokee_connection_build_host_string (conn, buf);
+ if (unlikely (ret != ret_ok)) {
+ return ret_error;
+ }
+
/* Port
*/
if ((conn->bind != NULL) &&
View
@@ -70,124 +70,135 @@ cherokee_source_mrproper (cherokee_source_t *src)
}
-ret_t
-cherokee_source_connect (cherokee_source_t *src, cherokee_socket_t *sock)
+static ret_t
+source_set_address (cherokee_source_t *src,
+ cherokee_socket_t *sock)
{
ret_t ret;
+ cherokee_boolean_t tested_all;
cherokee_resolv_cache_t *resolv;
+ const struct addrinfo *addr;
+ const struct addrinfo *addr_info = NULL;
- /* Short path: it's already connecting
+ /* Query the resolv cache
*/
- if (sock->socket >= 0) {
- return cherokee_socket_connect (sock);
+ ret = cherokee_resolv_cache_get_default (&resolv);
+ if (unlikely (ret!=ret_ok)) {
+ return ret;
}
- /* Create the new socket and set the target IP info
+ ret = cherokee_resolv_cache_get_addrinfo (resolv, &src->host, &addr_info);
+ if ((ret != ret_ok) || (addr_info == NULL)) {
+ return ret_error;
+ }
+
+ /* Current address
*/
- if (! cherokee_buffer_is_empty (&src->unix_socket)) {
+ if (src->addr_current) {
+ tested_all = false;
+ addr = src->addr_current;
+ } else {
+ tested_all = true;
+ addr = addr_info;
+ }
- /* Create the socket descriptor
- */
- ret = cherokee_socket_create_fd (sock, AF_UNIX);
- if (unlikely (ret != ret_ok)) {
- return ret;
- }
+ /* Create the fd for the address family
+ *
+ * Iterates through the different addresses of the
+ * host and stores a pointer to the first one with
+ * a supported family.
+ */
+ while (addr != NULL) {
+ ret = cherokee_socket_create_fd (sock, addr->ai_family);
- ret = cherokee_socket_gethostbyname (sock, &src->unix_socket);
- if (unlikely (ret != ret_ok)) {
- return ret;
- }
- } else {
- cherokee_boolean_t tested_all;
- const struct addrinfo *addr;
- const struct addrinfo *addr_info = NULL;
+#ifdef TRACE_ENABLED
+ if (cherokee_trace_is_tracing()) {
+ ret_t ret2;
+ char ip[46];
- /* Query the resolv cache
- */
- ret = cherokee_resolv_cache_get_default (&resolv);
- if (unlikely (ret!=ret_ok)) {
- return ret;
+ ret2 = cherokee_ntop (addr->ai_family, addr->ai_addr, ip, sizeof(ip));
+ if (ret2 == ret_ok) {
+ TRACE (ENTRIES, "Connecting to %s, ret=%d\n", ip, ret);
+ }
}
+#endif
- ret = cherokee_resolv_cache_get_addrinfo (resolv, &src->host, &addr_info);
- if ((ret != ret_ok) || (addr_info == NULL)) {
- return ret_error;
+ if (ret == ret_ok) {
+ src->addr_current = addr;
+ break;
}
- /* Current address
- */
- if (src->addr_current) {
- tested_all = false;
- addr = src->addr_current;
- #if 0
- /* The following allows to 'loadbalance' and/or check other sources */
- addr = src->addr_current->ai_next;
- if (addr == NULL)
- addr = addr_info;
- #endif
- } else {
+ addr = addr->ai_next;
+ if (addr == NULL) {
+ if (tested_all) {
+ return ret_error;
+ }
+
tested_all = true;
+ src->addr_current = NULL;
addr = addr_info;
+ continue;
}
- /* Create the fd for the address family
- *
- * Iterates through the different addresses of the
- * host and stores a pointer to the first one with
- * a supported family.
- */
- while (addr != NULL) {
- ret = cherokee_socket_create_fd (sock, addr->ai_family);
+ cherokee_socket_close(sock);
+ }
-#ifdef TRACE_ENABLED
- if (cherokee_trace_is_tracing()) {
- ret_t ret2;
- char ip[46];
-
- ret2 = cherokee_ntop (addr->ai_family, addr->ai_addr, ip, sizeof(ip));
- if (ret2 == ret_ok) {
- TRACE (ENTRIES, "Connecting to %s, ret=%d\n", ip, ret);
- }
- }
-#endif
+ /* Update the new socket with the address info
+ */
+ switch (src->addr_current->ai_family) {
+ case AF_INET:
+ SOCKET_ADDR_IPv4(sock)->sin_port = htons(src->port);
+ break;
+ case AF_INET6:
+ SOCKET_ADDR_IPv6(sock)->sin6_port = htons(src->port);
+ break;
+ default:
+ SHOULDNT_HAPPEN;
+ return ret_error;
+ }
- if (ret == ret_ok) {
- src->addr_current = addr;
- break;
- }
+ ret = cherokee_socket_update_from_addrinfo (sock, src->addr_current, 0);
+ if (unlikely (ret != ret_ok)) {
+ return ret_error;
+ }
- addr = addr->ai_next;
- if (addr == NULL) {
- if (tested_all) {
- return ret_error;
- }
+ return ret_ok;
+}
- tested_all = true;
- src->addr_current = NULL;
- addr = addr_info;
- continue;
- }
- cherokee_socket_close(sock);
- }
+ret_t
+cherokee_source_connect (cherokee_source_t *src, cherokee_socket_t *sock)
+{
+ ret_t ret;
- /* Update the new socket with the address info
+ /* Short path: it's already connecting
+ */
+ if (sock->socket >= 0) {
+ return cherokee_socket_connect (sock);
+ }
+
+ /* Create the new socket and set the target IP info
+ */
+ if (! cherokee_buffer_is_empty (&src->unix_socket)) {
+
+ /* Create the socket descriptor
*/
- switch (src->addr_current->ai_family) {
- case AF_INET:
- SOCKET_ADDR_IPv4(sock)->sin_port = htons(src->port);
- break;
- case AF_INET6:
- SOCKET_ADDR_IPv6(sock)->sin6_port = htons(src->port);
- break;
- default:
- SHOULDNT_HAPPEN;
- return ret_error;
+ ret = cherokee_socket_create_fd (sock, AF_UNIX);
+ if (unlikely (ret != ret_ok)) {
+ return ret;
}
- ret = cherokee_socket_update_from_addrinfo (sock, src->addr_current, 0);
+ ret = cherokee_socket_gethostbyname (sock, &src->unix_socket);
if (unlikely (ret != ret_ok)) {
- return ret_error;
+ return ret;
+ }
+ } else {
+
+ /* Set next IP address
+ */
+ ret = source_set_address (src, sock);
+ if (ret != ret_ok) {
+ return ret;
}
}
@@ -724,6 +724,14 @@ cherokee_source_interpreter_connect_polling (cherokee_source_interpreter_t *src,
/* reset by peer: spawn process? */
TRACE (ENTRIES, "Connection refused (closing fd=%d)\n", socket->socket);
cherokee_socket_close (socket);
+
+ /* Try the next address quickly, if any */
+ if (SOURCE(src)->addr_current) {
+ SOURCE(src)->addr_current = SOURCE(src)->addr_current->ai_next;
+ if (SOURCE(src)->addr_current) {
+ return ret_eagain;
+ }
+ }
break;
default:
View
@@ -29,7 +29,7 @@ def JustBefore (self, www):
#
nested = TestBase(__file__)
nested.request = "GET /digest2/file HTTP/1.0\r\n"
- nested.Run(HOST, PORT, 0)
+ nested.Run(HOST, PORT)
# Parse the authentication information line
#
View
@@ -30,7 +30,7 @@ def JustBefore (self, www):
#
nested = TestBase(__file__)
nested.request = "GET /digest3/file HTTP/1.0\r\n"
- nested.Run(HOST, PORT, 0)
+ nested.Run(HOST, PORT)
# Parse the authentication information line
#
@@ -30,7 +30,7 @@ def JustBefore (self, www):
#
nested = TestBase(__file__)
nested.request = "GET /%s/file HTTP/1.0\r\n" % (DIR)
- nested.Run(HOST, PORT, 0)
+ nested.Run(HOST, PORT)
# Parse the authentication information line
#
@@ -29,7 +29,7 @@ def JustBefore (self, www):
#
nested = TestBase(__file__)
nested.request = "GET /digest_empty/file HTTP/1.0\r\n"
- nested.Run(HOST, PORT, 0)
+ nested.Run(HOST, PORT)
# Parse the authentication information line
#
@@ -38,7 +38,7 @@ def JustBefore (self, www):
#
nested = TestBase(__file__)
nested.request = "GET /%s/file HTTP/1.0\r\n" % (DIR)
- nested.Run(HOST, PORT, 0)
+ nested.Run(HOST, PORT)
# Parse the authentication information line
#
Oops, something went wrong.

0 comments on commit 346efc7

Please sign in to comment.