HTTP-Proxy - Suggestion for mutator to convert unknown schemes

Posted on Sun Aug 14 07:55:35 2005 by bblakley
Suggestion for mutator to convert unknown schemes

First I'll set the stage so you know where I'm coming from.

I wrote a specialized proxy server that uses HTTP::Proxy as it's core, with other features like proxy cookie support, authentication, and domain redirection built in. The program is targeted primarily toward wireless Internet users (like cell phones) that want to run their own proxy server to provide Internet access for their device, instead of paying their carrier $5 a month to use the carrier's proxy. These wireless users have some special needs, not the least of which being that most cell phone Internet browsers don't have cookie support (they just ignore them). So, my proxy server grabs Set-Cookie headers and stores them on a per-user basis, and then puts appropriate Cookie headers into requests when the user requests a page from a host for which cookies have been stored. Another specialized need for these users is that most carriers try to make it difficult for the user to run their own proxy by hard coding the home page of the browser to something impossible like "http://homepage". My proxy server identifies those "local domain" requests (anything without a TLD) and redirects the browser to a homepage of the users choice.

However it has recently come to light that one major carrier locks the phone's homepage to "proxy:homepage". This is insidious because most proxy servers (HTTP::Proxy included) see "proxy:" as specifying a protocol/scheme (like http, https, etc.). HTTP::Proxy therefore returns a 501 error when a request for "proxy:homepage" comes through.

I was able to fix this situation with a change to HTTP::Proxy. At line 328 in Proxy.pm in 0.15 contains this code:

# can we serve this protocol? if ( !$self->agent->is_protocol_supported( my $s = $req->uri->scheme ) ) { # should this be 400 Bad Request? $response = HTTP::Response->new( 501, 'Not Implemented' ); $response->content_type( "text/plain" ); $response->content("Scheme $s is not supported by this proxy."); $self->response($response); goto SEND; }

I remarked out that code and replaced it with this code:

if (!$self->agent->is_protocol_supported($req->uri->scheme)) { $req->uri->scheme('http'); }

What this does is basically say, if you get a request for a scheme/protocol you don't know about, change the protocol to 'http'. This allows the request to pass through and make it into my request header filter, where I identify it as a local domain request (because the host is blank and therefore there is no TLD which is what I am looking for). Since my proxy redirects all local domain requests to the user's homepage of choice, it cleanly works around the "proxy:homepage" problem.

I'm not saying you'd want HTTP::Proxy to work this way by default. What would be nice however is something like an 'overrideUnknownSchemes' mutator that if set to a true value would cause HTTP::Proxy to behave the way my new code illustrates. This would save me from having to run a proprietary (modified) version of HTTP::Proxy (which is something I'd rather not do).

I realize this is a little esoteric and might not matter to anyone but me, but it is a simple change and you never know who might benefit from it in some other oddball scenario.

Direct Responses: 883 | Write a response