-#!/usr/bin/perl -w
-
package HTTPServer;
use strict;
+use warnings;
use HTTP::Daemon;
use HTTP::Status;
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;
}
my $authhdr = $req->header('Authorization');
# Have we sent the challenge yet?
- unless (defined $url_rec->{auth_challenged}
- && $url_rec->{auth_challenged}) {
+ unless ($url_rec->{auth_challenged} || $url_rec->{auth_no_challenge}) {
# Since we haven't challenged yet, we'd better not
# have received authentication (for our testing purposes).
if ($authhdr) {
# failed it.
$code = 400;
$msg = "You didn't send auth after I sent challenge";
+ if ($url_rec->{auth_no_challenge}) {
+ $msg = "--auth-no-challenge but no auth sent."
+ }
} else {
my ($sent_method) = ($authhdr =~ /^(\S+)/g);
unless ($sent_method eq $url_rec->{'auth_method'}) {
}
}
+sub _substitute_port {
+ my $self = shift;
+ my $ret = shift;
+ $ret =~ s/{{port}}/$self->sockport/eg;
+ return $ret;
+}
+
1;
# vim: et ts=4 sw=4