From abf66be35540a8bb8e96aa5ff24108dc569f4f3f Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 16 Mar 2001 16:34:24 +0000 Subject: [PATCH] Various changes: - added "patch_dtd" parameter to /getciconly method - removed "remove_header" feature to the download subroutine - patched response in gz file answering (now use x-gzip encoding header) - remove /conf method - removed hard coded "localhost" url --- helm/http_getter/http_getter.pl.in | 58 ++++++++++++++---------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/helm/http_getter/http_getter.pl.in b/helm/http_getter/http_getter.pl.in index 44001955c..b1840c8f1 100755 --- a/helm/http_getter/http_getter.pl.in +++ b/helm/http_getter/http_getter.pl.in @@ -110,13 +110,18 @@ while (my $c = $d->accept) { # finds the uri, url and filename my $cicuri = $inputuri; my $answerformat = $cgi->param('format'); + my $patch_dtd = $cgi->param('patch_dtd'); $answerformat = "" if (not defined($answerformat)); - + $patch_dtd = "" if (not defined($patch_dtd)); if (($answerformat ne "gz") and ($answerformat ne "normal") and ($answerformat ne "")) { die "Wrong output format: $answerformat, must be 'normal' ". "or 'gz'\n"; } + if (($patch_dtd ne "yes") and ($patch_dtd ne "no") + and ($patch_dtd ne "")) { + die "Wrong param, patch_dtd must be 'yes' or 'no'\n"; + } my $cicfilename = $cicuri; $cicfilename =~ s/cic:(.*)/$1/; @@ -141,10 +146,10 @@ while (my $c = $d->accept) { print_request("cic",$cicuri,$cicurl,$cicfilename); # Retrieves the file - my $ciccontent = download(0,"cic",$cicurl,$cicfilename,$answerformat); + my $ciccontent = download($patch_dtd,"cic",$cicurl,$cicfilename,$answerformat); # Answering the client - answer($c,$ciccontent); + answer($c,$ciccontent,$answerformat); } } elsif ($http_method eq 'GET' and $http_path eq "/getdtd") { my $filename = $inputuri; @@ -161,7 +166,7 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont); + answer($c,$cont,"normal"); } else { die "Could not find DTD!"; } @@ -176,7 +181,7 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont); + answer($c,$cont,"normal"); } else { die "Could not find Style Configuration File!"; } @@ -196,27 +201,17 @@ while (my $c = $d->accept) { $cont .= $_; } close(FD); - answer($c,$cont); + answer($c,$cont,"normal"); } else { die "Could not find XSLT!"; } - } elsif ($http_method eq 'GET' and $http_path eq "/conf") { - my $quoted_html_link = $html_link; - $quoted_html_link =~ s/&/&/g; - $quoted_html_link =~ s//>/g; - $quoted_html_link =~ s/'/'/g; - $quoted_html_link =~ s/"/"/g; - print "\nConfiguration requested, returned #$quoted_html_link#\n"; - $cont = "$quoted_html_link"; - answer($c,$cont); } elsif ($http_method eq 'GET' and $http_path eq "/update") { # rebuild urls_of_uris.db print "Update requested...\n"; mk_urls_of_uris(); kill(USR1,getppid()); # signal changes to parent print " done\n"; - answer($c,"

Update done

"); + answer($c,"

Update done

","normal"); } elsif ($http_method eq 'GET' and $http_path eq "/ls") { # send back keys that begin with a given uri my ($uritype,$uripattern,$uriprefix); @@ -236,22 +231,22 @@ while (my $c = $d->accept) { if (($outype ne 'txt') and ($outype ne 'xml')) { # invalid out type print "Invalid output type specified: $outype\n"; answer($c,"

Invalid output type, may be ". - "\"txt\" or \"xml\"

"); + "\"txt\" or \"xml\"","normal"); } else { # valid output print "BASEURI $baseuri, FORMAT $outype\n"; $cont = finduris($uritype,$uripattern,$outype); - answer($c,$cont); + answer($c,$cont,"normal"); } } else { # invalid uri print "Invalid uri: $baseuri, may begin with 'cic:', ". "'theory:' or '*:'\n"; answer($c,"

Invalid uri , may begin with ". - "\"cic:\", \"theory:\" or \"*:\"

"); + "\"cic:\", \"theory:\" or \"*:\"","normal"); } } elsif ($http_method eq 'GET' and $http_path eq "/help") { print "Help requested!"; answer($c,"

HTTP Getter Version ". - $VERSION."

"); + $VERSION."","normal"); } else { print "\n"; print "INVALID REQUEST!!!!!\n"; @@ -327,7 +322,7 @@ sub finduris { # find uris for cic and theory trees generation } elsif ($format eq "xml") { # XML output $content .= '' . "\n"; $content .= '' . "\n\n"; + $content .= "$myownurl/getdtd?uri=ls.dtd>" . "\n\n"; $content .= "\n"; foreach $key (sort(keys %dirs)) { $content .= "\t
$key
\n"; @@ -444,9 +439,8 @@ sub gzip { # gzip the content argument and save it to filename argument $gz->gzclose(); } -sub download -{ - my ($remove_headers,$str,$url,$filename,$format) = @_; +sub download { + my ($patch_dtd,$str,$url,$filename,$format) = @_; my ($gz, $buffer); #my $debug=1; # for DEBUG only @@ -529,10 +523,7 @@ sub download } # $cont now contained uncompressed data } - if ($remove_headers) { - $cont =~ s/<\?xml [^?]*\?>//sg; - $cont =~ s/]*>//sg; - } else { + if ($patch_dtd eq "yes") { $cont =~ s/DOCTYPE (.*) SYSTEM\s+"http:\/\/www.cs.unibo.it\/helm\/dtd\//DOCTYPE $1 SYSTEM "$myownurl\/getdtd?uri=/g; } if ($format eq "gz") { @@ -551,11 +542,14 @@ sub download return $cont; } -sub answer -{ - my ($c,$cont) = @_; +sub answer { + my ($c,$cont,$contype) = @_; # $contype must be "normal" or "gz" my $res = new HTTP::Response; $res->content($cont); + $res->push_header("Content-Type" => "text/plain"); + if ($contype eq "gz") { + $res->push_header("Content-Encoding" => "x-gzip"); + } $c->send_response($res); } -- 2.39.2