Decoding HTML requests:
($command, $request, $method) = split(" ",$command);
($document, $request) = split("\\\?",$request);
for (split("&",$request) ) {
s/\+/ /g;
($key, $val) = split("=",$_);
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
$query{$key} = $val;
sub escapeHTML {
my ($self,$toencode,$newlinestoo) = CGI::self_or_default(@_);
return undef unless defined($toencode);
return $toencode if ref($self) && $self->{'dontescape'};
$toencode =~ s{&}{&}gso;
$toencode =~ s{<}{<}gso;
$toencode =~ s{>}{>}gso;
$toencode =~ s{"}{"}gso;
my $latin = uc $self->{'.charset'} eq 'ISO-8859-1' ||
uc $self->{'.charset'} eq 'WINDOWS-1252';
if ($latin) { # bug in some browsers
$toencode =~ s{'}{'}gso;
$toencode =~ s{\x8b}{‹}gso;
$toencode =~ s{\x9b}{›}gso;
if (defined $newlinestoo && $newlinestoo) {
$toencode =~ s{\012}{ }gso;
$toencode =~ s{\015}{ }gso;
}
}
return $toencode;
}
sub unescapeHTML {
my ($self,$string) = CGI::self_or_default(@_);
return undef unless defined($string);
my $latin = defined $self->{'.charset'} ? $self->{'.charset'} =~ /^(ISO-8859-1|WINDOWS-1252)$/i
: 1;
# thanks to Randal Schwartz for the correct solution to this one
$string=~ s[&(.*?);]{
local $_ = $1;
/^amp$/i ? "&" :
/^quot$/i ? '"' :
/^gt$/i ? ">" :
/^lt$/i ? "<" :
/^#(\d+)$/ && $latin ? chr($1) :
/^#x([0-9a-f]+)$/i && $latin ? chr(hex($1)) :
$_
}gex;
return $string;
}
Encodeing CGI Environment Variables for handoff to a CGI program
$ENV{SERVER_SOFTWARE} = 'MyHTTPd/0.1';
$ENV{SERVER_NAME} = Sys::Hostname::hostname();
$ENV{GATEWAY_INTERFACE} = 'CGI/1.1';
$ENV{SERVER_PROTOCOL} = $protocol;
$ENV{SERVER_PORT} = $PORT;
$ENV{REQUEST_METHOD} = $method;
$ENV{QUERY_STRING} = $querydata;
$ENV{REMOTE_ADDR} = $client->peerhost;
$ENV{HTTP_ACCEPT} = $request{'Accept'};
$ENV{HTTP_USER_AGENT} = $request{'User_Agent'};
$ENV{SCRIPT_NAME} = $request->url->epath;
$ENV{CONTENT_LENGTH} = 0;
See also
| file: /techref/language/perl/www.htm, 3KB, , updated: 2001/6/21 12:55, local time: 2009/11/22 08:29,
38.107.191.103:LOG IN
|
| ©2009 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? Please DO link to this page! Digg it! <A HREF="http://www.piclist.com/techref/language/perl/www.htm"> Perl HTTP Services</A> |
| Did you find what you needed? |
|
|
Robotics nuts!Check out http://www.verinet.com/~dlc/ email: dlc@verinet.com... This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.