]> sjero.net Git - wget/commitdiff
[svn] Added support for Range header.
authormtortonesi <devnull@localhost>
Thu, 17 Aug 2006 09:15:00 +0000 (02:15 -0700)
committermtortonesi <devnull@localhost>
Thu, 17 Aug 2006 09:15:00 +0000 (02:15 -0700)
tests/HTTPServer.pm

index 8950a22de2309d7cb37cfff7dd0863c9005e2873..88224f4f9be1c5b456ba7f2d6478462dc146b3a3 100755 (executable)
@@ -65,7 +65,24 @@ sub run {
                             $con->send_basic_header($tmp->{code}, $resp->message, $resp->protocol);
                             print $con $resp->headers_as_string($CRLF);
                             print $con $CRLF;
-                            print $con $tmp->{content};                                
+                            print $con $tmp->{content};
+                            next;
+                        }
+                        if ($req->header("Range")) {
+                            $req->header("Range") =~ m/bytes=(\d*)-(\d*)/;
+                            my $content_len = length($tmp->{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($tmp->{content}, $start, $len);
                             next;
                         }
                         # fill in content