X-Git-Url: http://sjero.net/git/?p=wget;a=blobdiff_plain;f=tests%2FHTTPServer.pm;h=dbfa3ef1ce8cea7d87c2c1d140d5634b018a60b9;hp=97e91396dcf6e5b6f5ed0105e8cf1cd2fc1ba5ff;hb=d3007f1b3a5d033babe40bc4c56a899eb3b10bfa;hpb=e4600575bb4e2d2a6b9e2c543d0920b969d98e55 diff --git a/tests/HTTPServer.pm b/tests/HTTPServer.pm index 97e91396..dbfa3ef1 100644 --- a/tests/HTTPServer.pm +++ b/tests/HTTPServer.pm @@ -98,18 +98,29 @@ sub send_response { my $start = $1 ? $1 : 0; my $end = $2 ? $2 : ($content_len - 1); my $len = $2 ? ($2 - $start) : ($content_len - $start); - $resp->header("Accept-Ranges" => "bytes"); - $resp->header("Content-Length" => $len); - $resp->header("Content-Range" => "bytes $start-$end/$content_len"); - $resp->header("Keep-Alive" => "timeout=15, max=100"); - $resp->header("Connection" => "Keep-Alive"); - $con->send_basic_header(206, "Partial Content", $resp->protocol); - print $con $resp->headers_as_string($CRLF); - print $con $CRLF; - print $con substr($content, $start, $len); + if ($len) { + $resp->header("Accept-Ranges" => "bytes"); + $resp->header("Content-Length" => $len); + $resp->header("Content-Range" + => "bytes $start-$end/$content_len"); + $resp->header("Keep-Alive" => "timeout=15, max=100"); + $resp->header("Connection" => "Keep-Alive"); + $con->send_basic_header(206, + "Partial Content", $resp->protocol); + print $con $resp->headers_as_string($CRLF); + print $con $CRLF; + print $con substr($content, $start, $len); + } else { + $con->send_basic_header(416, "Range Not Satisfiable", + $resp->protocol); + $resp->header("Keep-Alive" => "timeout=15, max=100"); + $resp->header("Connection" => "Keep-Alive"); + print $con $CRLF; + } next; } # fill in content + $content = $self->_substitute_port($content); $resp->content($content); print STDERR "HTTP::Response with content: \n", $resp->as_string if $log; } @@ -197,6 +208,13 @@ sub verify_auth_basic { } } +sub _substitute_port { + my $self = shift; + my $ret = shift; + $ret =~ s/{{port}}/$self->sockport/eg; + return $ret; +} + 1; # vim: et ts=4 sw=4