Hi,

On Mit 16.11.2005 19:09, Alexander Lazic wrote:

@Joe Orton: do you have a patch for mod_proxy_connect?
http://issues.apache.org/bugzilla/show_bug.cgi?id=19188

as joe suggested i have start to implement the connect call with
proxy_connect.c.

I have attached my first attempt, but it always segfaults :-(, fyi i
have try to add as little as necessary to the code.

I have 2 major problems:

1.) when i want to add a parameter to
   proxy_connect.c:ap_proxy_http_handler() i get a
   warning at proxy_connect.c:proxy_hook_scheme_handler(). I have want
   to add a flag to see if the function was called from
   proxy_http.c:ap_proxy_http_create_connection().

2.) i think i use the pools in some wrong way?!

I don't know if i am on the right way. We need these fuction and it
would be nice that the mod_proxy talk 'in the right way' with the
upstream proxies for https_calls in http-context.

Thanx for all who wan't and can help, btw. here the backtrace from the
core:

---
#0  0xb7ca6421 in __read_nocancel () from /lib/tls/libpthread.so.0
(gdb) bt
#0  0xb7ca6421 in __read_nocancel () from /lib/tls/libpthread.so.0
#1  0x080ac2b7 in ap_mpm_pod_check (pod=0xfffffe00) at pod.c:54
#2  0x080aa563 in child_main (child_num_arg=Variable "child_num_arg" is
not available.) at worker.c:1195
#3  0x080aa6d0 in make_child (s=0x80fc850, slot=0) at worker.c:1278
#4  0x080aa77b in startup_children (number_to_start=2) at worker.c:1312
#5  0x080ab1ac in ap_mpm_run (_pconf=0x80f70a8, plog=0x81351a0,
s=0x80fc850) at worker.c:1661
#6  0x080b15ce in main (argc=3, argv=0xbfa0c624) at main.c:618
---

Greetings

Alex
Index: httpd-2.0.x-2005-11-17/modules/proxy/proxy_http.c
===================================================================
--- httpd-2.0.x-2005-11-17/modules/proxy/proxy_http.c   (revision 345304)
+++ httpd-2.0.x-2005-11-17/modules/proxy/proxy_http.c   (working copy)
@@ -31,6 +31,8 @@
     apr_sockaddr_t *addr;
     apr_socket_t   *sock;
     int             close;
+    /* Does use the HTTP connect method to connect to the web server ? */
+    int does_use_http_connect;
 } proxy_http_conn_t;
 
 static apr_status_t ap_proxy_http_cleanup(request_rec *r,
@@ -243,9 +245,12 @@
                                              conn_rec *c, conn_rec **origin,
                                              proxy_conn_rec *backend,
                                              proxy_server_conf *conf,
-                                             const char *proxyname) {
+                                             const char *proxyname,
+                                            char *url,
+                                            apr_port_t proxyport) {
     int failed=0, new=0;
     apr_socket_t *client_socket = NULL;
+    apr_uri_t *uri;
 
     /* We have determined who to connect to. Now make the connection, 
supporting
      * a KeepAlive connection.
@@ -320,10 +325,17 @@
          * For now we do nothing, ie we get DNS round robin.
          * XXX FIXME
          */
-        failed = ap_proxy_connect_to_backend(&p_conn->sock, "HTTP",
+        /*
+       failed = ap_proxy_connect_to_backend(&p_conn->sock, "HTTP",
                                              p_conn->addr, p_conn->name,
                                              conf, r->server, c->pool);
+       */
+       failed = ap_proxy_connect_to_backend(&p_conn->sock,
+                                           (p_conn->does_use_http_connect ? 
"CONNECT" : "HTTP"),
+                                            p_conn->addr, p_conn->name,
+                                            conf, r->server, c->pool);
 
+
         /* handle a permanent error on the connect */
         if (failed) {
             if (proxyname) {
@@ -362,6 +374,11 @@
                              "for %pI (%s)", p_conn->addr, p_conn->name);
                 return HTTP_INTERNAL_SERVER_ERROR;
             }
+           if (p_conn->does_use_http_connect) {
+             apr_uri_parse(c->pool,url, uri);
+             char *connect_url = apr_psprintf(c->pool,"%s:443",uri->hostinfo);
+             ap_proxy_connect_handler(r,conf,connect_url,proxyname,proxyport);
+           }
         }
         else {
             ap_proxy_ssl_disable(backend->connection);
@@ -1599,9 +1616,11 @@
     conn_rec *c = r->connection;
     apr_bucket_brigade *bb = apr_brigade_create(p, c->bucket_alloc);
     apr_uri_t *uri = apr_palloc(r->connection->pool, sizeof(*uri));
-    proxy_http_conn_t *p_conn = apr_pcalloc(r->connection->pool,
+    proxy_http_conn_t *p_conn = (proxy_http_conn_t 
*)apr_pcalloc(r->connection->pool,
                                            sizeof(*p_conn));
 
+    p_conn->does_use_http_connect = 0;
+    
     /* is it for us? */
     if (strncasecmp(url, "https:", 6) == 0) {
         if (!ap_proxy_ssl_enable(NULL)) {
@@ -1611,6 +1630,10 @@
             return DECLINED;
         }
         is_ssl = 1;
+       
+       if (proxyname) {
+         p_conn->does_use_http_connect = 1;
+       }
     }
     else if (!(strncasecmp(url, "http:", 5)==0 || (strncasecmp(url, "ftp:", 
4)==0 && proxyname))) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
@@ -1652,7 +1675,7 @@
 
     /* Step Two: Make the Connection */
     status = ap_proxy_http_create_connection(p, r, p_conn, c, &origin, backend,
-                                             conf, proxyname);
+                                             conf, proxyname,url,proxyport);
     if ( status != OK ) {
         return status;
     }
Index: httpd-2.0.x-2005-11-17/modules/proxy/proxy_connect.c
===================================================================
--- httpd-2.0.x-2005-11-17/modules/proxy/proxy_connect.c        (revision 
345304)
+++ httpd-2.0.x-2005-11-17/modules/proxy/proxy_connect.c        (working copy)
@@ -102,7 +102,7 @@
     if (r->method_number != M_CONNECT) {
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                     "proxy: CONNECT: declining URL %s", url);
-       return DECLINED;
+       /* return DECLINED; */
     }
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,
                 "proxy: CONNECT: serving URL %s", url);
@@ -116,8 +116,8 @@
 
     /* we break the URL into host, port, uri */
     if (APR_SUCCESS != apr_uri_parse_hostinfo(p, url, &uri)) {
-       return ap_proxyerror(r, HTTP_BAD_REQUEST,
-                            apr_pstrcat(p, "URI cannot be parsed: ", url, 
NULL));
+      /* return */ ap_proxyerror(r, HTTP_BAD_REQUEST,
+                            apr_pstrcat(p, "ap_proxy_connect_handler() URI 
cannot be parsed: ", url, NULL));
     }
 
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, r->server,

Reply via email to