]> granicus.if.org Git - apache/commitdiff
Added ap_proxy_connection_create function that makes
authorWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 11 Aug 2004 22:36:28 +0000 (22:36 +0000)
committerWilliam A. Rowe Jr <wrowe@apache.org>
Wed, 11 Aug 2004 22:36:28 +0000 (22:36 +0000)
conn_rec for opened connection. It is used bt http(s) and ftp for
bounding the backend connection to client connection with the same id's.

Submitted by: mturk

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@104597 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.h
modules/proxy/proxy_util.c

index 58f9befc311cdbf4b444da94616e0e66073059dc..4002c6f37bd1ff92df11f4f196084e9e166f1d51 100644 (file)
@@ -364,7 +364,8 @@ PROXY_DECLARE(apr_status_t) ap_proxy_destroy_connection(proxy_conn_rec *conn);
 PROXY_DECLARE(apr_status_t) ap_proxy_close_connection(proxy_conn_rec *conn);
 PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function, proxy_conn_rec *conn, proxy_worker *worker,
                                             proxy_server_conf *conf, server_rec *s);
-
+PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function, proxy_conn_rec *conn,
+                                              proxy_server_conf *conf, conn_rec *c, server_rec *s);
 /* For proxy_util */
 extern module PROXY_DECLARE_DATA proxy_module;
 
index 9cbd1937e2e7c521a15848c65444ce4bf5a4f0c8..4546ef653e10783265f3c6a6d24ff6e0898b2adb 100644 (file)
@@ -1636,9 +1636,70 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
             backend_addr = backend_addr->next;
             continue;
         }
-        conn->sock   = newsock;
-        conn->worker = worker;
-        connected    = 1;
+        
+        conn->sock     = newsock;
+        conn->worker   = worker;
+        /* XXX: the hostname will go from proxy_conn_rec
+         * keep for now.
+         * We will 'optimize' later, both code and unneeded data
+         */
+        conn->hostname = worker->hostname;
+        connected      = 1;
     }
-    return connected ? 0 : 1;
+    return connected ? OK : DECLINED;
+}
+
+PROXY_DECLARE(int) ap_proxy_connection_create(const char *proxy_function,
+                                              proxy_conn_rec *conn,
+                                              proxy_server_conf *conf,
+                                              conn_rec *c,
+                                              server_rec *s)
+{
+    proxy_worker *worker = conn->worker;
+    apr_sockaddr_t *backend_addr = worker->cp->addr;
+
+    /* The socket is now open, create a new backend server connection 
+    * 
+    */
+    conn->connection = ap_run_create_connection(c->pool, s, conn->sock,
+                                                c->id, c->sbh,
+                                                c->bucket_alloc);
+
+    if (!conn->connection) {
+        /* the peer reset the connection already; ap_run_create_connection() 
+        * closed the socket
+        */
+        ap_log_error(APLOG_MARK, APLOG_DEBUG, 0,
+                     s, "proxy: %s: an error occurred creating a "
+                     "new connection to %pI (%s)", proxy_function,
+                     backend_addr, conn->hostname);
+        /* XXX: Will be closed when proxy_conn is closed */
+        apr_socket_close(conn->sock);
+        conn->sock = NULL;
+        return HTTP_INTERNAL_SERVER_ERROR;
+    }
+
+    /* For ssl connection to backend */
+    if (conn->is_ssl) {
+        if (!ap_proxy_ssl_enable(conn->connection)) {
+            ap_log_error(APLOG_MARK, APLOG_ERR, 0,
+                         s, "proxy: %s: failed to enable ssl support "
+                         "for %pI (%s)", proxy_function, 
+                         backend_addr, conn->hostname);
+            return HTTP_INTERNAL_SERVER_ERROR;
+        }
+    }
+    else {
+        /* TODO: See if this will break FTP */
+        ap_proxy_ssl_disable(conn->connection);
+    }
+
+    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, s,
+                 "proxy: %s: connection complete to %pI (%s)",
+                 proxy_function, backend_addr, conn->hostname);
+
+    /* set up the connection filters */
+    ap_run_pre_connection(conn->connection, conn->sock);
+
+    return OK;
 }