File: http.pm

package info (click to toggle)
liburi-perl 1.04-2
  • links: PTS
  • area: main
  • in suites: potato
  • size: 464 kB
  • ctags: 184
  • sloc: perl: 2,488; makefile: 53; sh: 17
file content (34 lines) | stat: -rw-r--r-- 726 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package URI::http;

require URI::_server;
@ISA=qw(URI::_server);

use strict;
use vars qw(%unreserved_escape);

sub default_port { 80 }

sub canonical
{
    my $self = shift;
    my $other = $self->SUPER::canonical;

    my $slash_path = defined($other->authority) &&
        !length($other->path) && !defined($other->query);

    if ($slash_path || $$other =~ /%/) {
	$other = $other->clone if $other == $self;
	unless (%unreserved_escape) {
	    for ("A" .. "Z", "a" .. "z", "0" .."9",
		 "-", "_", ".", "!", "~", "*", "'", "(", ")"
		) {
		$unreserved_escape{sprintf "%%%02X", ord($_)} = $_;
	    }
	}
	$$other =~ s/(%[0-9A-F]{2})/$unreserved_escape{$1} || $1/ge;
	$other->path("/") if $slash_path;
    }
    $other;
}

1;