You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2014/06/13 23:10:52 UTC

svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Author: jim
Date: Fri Jun 13 21:10:51 2014
New Revision: 1602523

URL: http://svn.apache.org/r1602523
Log:
Allow for "magic" scheme "auto" which makes the scheme of
the backend worker match whatever the scheme of the
incoming request was...

For example:

   ProxyPass / auto://foo.example.com/

If the incoming request is http:.../lala then
the resultant will be http://foo.example.com/lala

If it's wws:.../lolo then we'd send
wws://foo.example.com/lolo

Modified:
    httpd/httpd/trunk/modules/proxy/mod_proxy.c
    httpd/httpd/trunk/modules/proxy/proxy_util.c

Modified: httpd/httpd/trunk/modules/proxy/mod_proxy.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy.c?rev=1602523&r1=1602522&r2=1602523&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/mod_proxy.c (original)
+++ httpd/httpd/trunk/modules/proxy/mod_proxy.c Fri Jun 13 21:10:51 2014
@@ -1045,6 +1045,11 @@ static int proxy_handler(request_rec *r)
     }
 
     scheme = apr_pstrndup(r->pool, uri, p - uri);
+
+    if (strcmp(scheme, "auto") == 0) {
+        apr_table_set(r->notes, "auto", uri);
+        uri = apr_pstrcat(r->pool, ap_http_scheme(r), p, NULL);
+    }
     /* Check URI's destination host against NoProxy hosts */
     /* Bypass ProxyRemote server lookup if configured as NoProxy */
     for (direct_connect = i = 0; i < conf->dirconn->nelts &&
@@ -1151,8 +1156,8 @@ static int proxy_handler(request_rec *r)
 
         /* handle the scheme */
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01143)
-                      "Running scheme %s handler (attempt %d)",
-                      scheme, attempts);
+                      "Running scheme %s handler for %s (attempt %d)",
+                      scheme, url, attempts);
         AP_PROXY_RUN(r, worker, conf, url, attempts);
         access_status = proxy_run_scheme_handler(r, worker, conf,
                                                  url, NULL, 0);
@@ -1479,7 +1484,7 @@ static const char *
 
 static char *de_socketfy(apr_pool_t *p, char *url)
 {
-    char *ptr;
+    char *ptr, *ret = url;
     /*
      * We could be passed a URL during the config stage that contains
      * the UDS path... ignore it
@@ -1487,7 +1492,7 @@ static char *de_socketfy(apr_pool_t *p, 
     if (!strncasecmp(url, "unix:", 5) &&
         ((ptr = ap_strchr(url, '|')) != NULL)) {
         /* move past the 'unix:...|' UDS path info */
-        char *ret, *c;
+        char *c;
 
         ret = ptr + 1;
         /* special case: "unix:....|scheme:" is OK, expand
@@ -1498,13 +1503,10 @@ static char *de_socketfy(apr_pool_t *p, 
             return NULL;
         }
         if (c[1] == '\0') {
-            return apr_pstrcat(p, ret, "//localhost", NULL);
-        }
-        else {
-            return ret;
+            ret = apr_pstrcat(p, ret, "//localhost", NULL);
         }
     }
-    return url;
+    return ret;
 }
 
 static const char *

Modified: httpd/httpd/trunk/modules/proxy/proxy_util.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/proxy_util.c?rev=1602523&r1=1602522&r2=1602523&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/proxy/proxy_util.c (original)
+++ httpd/httpd/trunk/modules/proxy/proxy_util.c Fri Jun 13 21:10:51 2014
@@ -1907,7 +1907,11 @@ PROXY_DECLARE(int) ap_proxy_pre_request(
 
     access_status = proxy_run_pre_request(worker, balancer, r, conf, url);
     if (access_status == DECLINED && *balancer == NULL) {
-        *worker = ap_proxy_get_worker(r->pool, NULL, conf, *url);
+        const char *murl;
+        if ((murl = apr_table_get(r->notes, "auto")) == NULL) {
+            murl = *url;
+        }
+        *worker = ap_proxy_get_worker(r->pool, NULL, conf, murl);
         if (*worker) {
             ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r,
                           "%s: found worker %s for %s",



Re: svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Posted by Eric Covener <co...@gmail.com>.
On Sat, Jun 14, 2014 at 6:02 PM, Jim Jagielski <ji...@jagunet.com> wrote:
> I thought RFC 6455 specifies ws and wss...

It doesn't go on the wire.

Once a connection to the server has been established (including a
   connection via a proxy or over a TLS-encrypted tunnel), the client
   MUST send an opening handshake to the server.  The handshake consists
   of an HTTP Upgrade request, along with a list of required and
   optional header fields.  The requirements for this handshake are as
   follows.

   1.   The handshake MUST be a valid HTTP request as specified by
        [RFC2616].

   2.   The method of the request MUST be GET, and the HTTP version MUST
        be at least 1.1.

        For example, if the WebSocket URI is "ws://example.com/chat",
        the first line sent should be "GET /chat HTTP/1.1".



-- 
Eric Covener
covener@gmail.com

Re: svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Posted by Jim Jagielski <ji...@jaguNET.com>.
I thought RFC 6455 specifies ws and wss...

On Jun 14, 2014, at 3:36 PM, Eric Covener <co...@gmail.com> wrote:

> On Sat, Jun 14, 2014 at 3:29 PM, Jim Jagielski <ji...@jagunet.com> wrote:
>> 
>> On Jun 14, 2014, at 7:06 AM, Eric Covener <co...@gmail.com> wrote:
>> 
>>> On Fri, Jun 13, 2014 at 5:10 PM,  <ji...@apache.org> wrote:
>>>> Allow for "magic" scheme "auto" which makes the scheme of
>>>> the backend worker match whatever the scheme of the
>>>> incoming request was...
>>>> 
>>>> For example:
>>>> 
>>>>  ProxyPass / auto://foo.example.com/
>>>> 
>>>> If the incoming request is http:.../lala then
>>>> the resultant will be http://foo.example.com/lala
>>>> 
>>>> If it's wws:.../lolo then we'd send
>>>> wws://foo.example.com/lolo
>>> 
>>> 
>>> Does this work for websockets? Isn't the scheme http:// + Upgrade for
>>> websockets?
>>> 
>>> I thought "auto" would mean the handlers would second-guess the
>>> scheme, but if we replace it in proxy_util.c they cannot do that
>>> anymore.
>> 
>> 
>> I thought the idea/issue was that we wanted, for
>> example, an incoming http request to be handled by the
>> http proxy scheme handler and if it was ws, to be
>> handled by the ws scheme handler. This was not
>> possible with the normal setup
> 
> But a websockets request is a http scheme (really no explicit scheme)
> + an upgrade header.
> 
> GET /chat HTTP/1.1
> Connection: Upgrade
> Upgrade: websocket
> Host: 127.0.0.1:8080
> Origin: 127.0.0.1:8080
> Sec-WebSocket-Version: 13
> Sec-WebSocket-Key: MTMtMTQwMjc3NDQxMzE0Ng==
> 
> HTTP/1.1 101 Switching Protocols
> Upgrade: websocket
> Connection: Upgrade
> Sec-WebSocket-Accept: fVFPYVP6z6n4b2wNyVnJz25W2Os=
> 
> .....&c.....&.d....


Re: svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Posted by Eric Covener <co...@gmail.com>.
On Sat, Jun 14, 2014 at 3:29 PM, Jim Jagielski <ji...@jagunet.com> wrote:
>
> On Jun 14, 2014, at 7:06 AM, Eric Covener <co...@gmail.com> wrote:
>
>> On Fri, Jun 13, 2014 at 5:10 PM,  <ji...@apache.org> wrote:
>>> Allow for "magic" scheme "auto" which makes the scheme of
>>> the backend worker match whatever the scheme of the
>>> incoming request was...
>>>
>>> For example:
>>>
>>>   ProxyPass / auto://foo.example.com/
>>>
>>> If the incoming request is http:.../lala then
>>> the resultant will be http://foo.example.com/lala
>>>
>>> If it's wws:.../lolo then we'd send
>>> wws://foo.example.com/lolo
>>
>>
>> Does this work for websockets? Isn't the scheme http:// + Upgrade for
>> websockets?
>>
>> I thought "auto" would mean the handlers would second-guess the
>> scheme, but if we replace it in proxy_util.c they cannot do that
>> anymore.
>
>
> I thought the idea/issue was that we wanted, for
> example, an incoming http request to be handled by the
> http proxy scheme handler and if it was ws, to be
> handled by the ws scheme handler. This was not
> possible with the normal setup

But a websockets request is a http scheme (really no explicit scheme)
+ an upgrade header.

GET /chat HTTP/1.1
Connection: Upgrade
Upgrade: websocket
Host: 127.0.0.1:8080
Origin: 127.0.0.1:8080
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: MTMtMTQwMjc3NDQxMzE0Ng==

HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: fVFPYVP6z6n4b2wNyVnJz25W2Os=

.....&c.....&.d....

Re: svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Posted by Jim Jagielski <ji...@jaguNET.com>.
On Jun 14, 2014, at 7:06 AM, Eric Covener <co...@gmail.com> wrote:

> On Fri, Jun 13, 2014 at 5:10 PM,  <ji...@apache.org> wrote:
>> Allow for "magic" scheme "auto" which makes the scheme of
>> the backend worker match whatever the scheme of the
>> incoming request was...
>> 
>> For example:
>> 
>>   ProxyPass / auto://foo.example.com/
>> 
>> If the incoming request is http:.../lala then
>> the resultant will be http://foo.example.com/lala
>> 
>> If it's wws:.../lolo then we'd send
>> wws://foo.example.com/lolo
> 
> 
> Does this work for websockets? Isn't the scheme http:// + Upgrade for
> websockets?
> 
> I thought "auto" would mean the handlers would second-guess the
> scheme, but if we replace it in proxy_util.c they cannot do that
> anymore.


I thought the idea/issue was that we wanted, for
example, an incoming http request to be handled by the
http proxy scheme handler and if it was ws, to be
handled by the ws scheme handler. This was not
possible with the normal setup

	ProxyPass / http://foo.bar/

since all requests in this case would go to the
http scheme handler (no matter what the incoming scheme
was) as well as

	ProxyPass / ws://foo.bar/

Which would always go websockets, whether we wanted to
or not. In other words, the incoming scheme determined
the scheme we use on the backend, instead of it being
"hard-coded" in the ProxyPass command.

Not sure if I misunderstood or not :/

Re: svn commit: r1602523 - in /httpd/httpd/trunk/modules/proxy: mod_proxy.c proxy_util.c

Posted by Eric Covener <co...@gmail.com>.
On Fri, Jun 13, 2014 at 5:10 PM,  <ji...@apache.org> wrote:
> Allow for "magic" scheme "auto" which makes the scheme of
> the backend worker match whatever the scheme of the
> incoming request was...
>
> For example:
>
>    ProxyPass / auto://foo.example.com/
>
> If the incoming request is http:.../lala then
> the resultant will be http://foo.example.com/lala
>
> If it's wws:.../lolo then we'd send
> wws://foo.example.com/lolo


Does this work for websockets? Isn't the scheme http:// + Upgrade for
websockets?

I thought "auto" would mean the handlers would second-guess the
scheme, but if we replace it in proxy_util.c they cannot do that
anymore.

-- 
Eric Covener
covener@gmail.com