Re: URI handling of "//hostname.foo.com/" as base_uri
Ben Scott (scotsman@euphorion.com)
Wed, 18 Apr 2001 16:58:53 -0700
On Wed, Apr 18, 2001 at 04:50:51PM -0700, Gisle Aas wrote:
> The $base argument should be an absolute URI. "//a248.e.akamai.net/.../" is not.
> The doc for the method says:
>
> $uri = URI->new_abs( $str, $base_uri )
> This constructs a new absolute URI object. The $str
> argument can denote a relative or absolute URI. If
> relative, then it will be absolutized using $base_uri
> as base. The $base_uri must be an absolute URI.
>
> This patch also makes your code work, but that is more by accident
> then anything else. The second argument to URI->new_abs() should
> really still be an absolute URI.
>
> I would suggest you use code like this:
>
> sub akamize {
> my($uri, $base) = @_;
> $base = URI->new($base, "http");
> $base->scheme("http") unless $base->scheme; # ensure absoluteness
> $uri = URI->new_abs($uri, $base);
> $uri->scheme(undef); # make it relative
> return $uri;
> }
>
> It should work nicely both with and without the URI.pm patch.
I submit that a handler for relative URIs would be as handy as one for
absolute URIs. Perhaps URI->new_rel needs to be added. In the case
of sourcing images/javascript in a page fetched in both SSL and nonSSL
(and given some time, I'd give others), the ability of using
//hostname/path/file or /path/file in the URI module would be useful.
--
Ben Scott Office (408)894-6807
Comptroller of His Majesty's Fireworks as well as for War as for Triumph