]> sjero.net Git - wget/blobdiff - tests/HTTPServer.pm
IDN test.
[wget] / tests / HTTPServer.pm
index 97e91396dcf6e5b6f5ed0105e8cf1cd2fc1ba5ff..01c36957535268e6bc3e693786350f6fc518dd2b 100644 (file)
@@ -27,7 +27,8 @@ sub run {
         my $con = $self->accept();
         print STDERR "Accepted a new connection\n" if $log;
         while (my $req = $con->get_request) {
-            my $url_path = $req->url->path;
+            #my $url_path = $req->url->path;
+            my $url_path = $req->url->as_string;
             if ($url_path =~ m{/$}) { # append 'index.html'
                 $url_path .= 'index.html';
             }
@@ -92,24 +93,35 @@ sub send_response {
             print $con $content;
             next;
         }
-        if ($req->header("Range")) {
+        if ($req->header("Range") && !$url_rec->{'force_code'}) {
             $req->header("Range") =~ m/bytes=(\d*)-(\d*)/;
             my $content_len = length($content);
             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 > 0) {
+                $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 +209,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