Bug 55598 - mod_rewrite unable to proxy websocket URIs
Summary: mod_rewrite unable to proxy websocket URIs
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords: PatchAvailable
Depends on:
Blocks:
 
Reported: 2013-09-26 14:36 UTC by Chris Harris
Modified: 2016-02-16 15:31 UTC (History)
1 user (show)



Attachments
Patch to add websocket protocols to is_absolute_uri(...) (628 bytes, patch)
2013-09-26 14:36 UTC, Chris Harris
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Harris 2013-09-26 14:36:15 UTC
Created attachment 30886 [details]
Patch to add websocket protocols to is_absolute_uri(...)

Given the following rewrite rule:

RewriteRule    ^/ws(.*)$  ws://localhost:9000/ws  [P]

mod_rewrite treats this a filepath so the access log shows:

[26/Sep/2013:09:46:07 -0400] "GET /ws://localhost:9000/ws HTTP/1.1" 400 317

This problem is that is_absolute_uri(...) is returning 0 for URIs starting with ws:// or wss://.

I have attached a patch against HEAD that add a case to is_absolute_uri(...) to match the websocket protocols. This allow websocket traffic to be proxied using mod_rewrite.
Comment 1 Jim Jagielski 2013-10-02 16:39:18 UTC
Committed revision 1528556 in trunk. Will propose for 2.4 backport
Comment 2 Chris Harris 2013-10-15 17:23:57 UTC
Getting this backported to 2.4 would be great.
Comment 3 Alexey 2016-02-16 13:14:41 UTC
Hey there, is it realistic to expect backport on 2.2

httpd-2.2.15-47.el6.centos.3.x86_64

I have tested your patch and it works perfectly. Thank you very much.
I just wonder if custom or official mod_rewrite.so can be approved.
Comment 4 Chris Harris 2016-02-16 13:50:24 UTC
Not sure what the process for backport to 2.2 is, but it seem unlikely I think.
Comment 5 Alexey 2016-02-16 14:57:03 UTC
(In reply to Chris Harris from comment #4)
> Not sure what the process for backport to 2.2 is, but it seem unlikely I
> think.
Ok, thank you,

Just wonder, will this broke current mod_rewrite in any case?

    case 'w':
    case 'W':
        if (!strncasecmp(uri, "s://", 4)) {        /* ws://     */
            return 5;
        }
        else if (!strncasecmp(uri, "ss://", 5)) {  /* wss://    */
            return 6;
        }
        break;
    }

I suppose not and want to build mod_rewrite.rpm just for that needs. (proxy-ing websockets dynamically )

# simply and easy rule like would work ( i checked it, and any variations )
RewriteRule ^websockify/([^/]+)/([^/]+) wss://$1:$2/websockify [P]