Skip to content

Commit 093c5ab

Browse files
committed
Fix HEAD request in dummyhttpserver
It should not return a body. Libcurl seems to report an "weird server response" error if there is a body.
1 parent c295ac7 commit 093c5ab

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

dummyhttpserver

+11-11
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ sub reply {
5656
push @hdrs, "Content-Length: ".length($str) if defined($str);
5757
my $data = join("\r\n", @hdrs)."\r\n\r\n";
5858
$data .= $str if defined $str;
59-
fcntl($sock, F_SETFL,O_NONBLOCK);
59+
fcntl($sock, F_SETFL, O_NONBLOCK);
6060
my $dummy = '';
6161
1 while sysread($sock, $dummy, 1024, 0);
62-
fcntl($sock, F_SETFL,0);
62+
fcntl($sock, F_SETFL, 0);
6363
replyraw($data);
6464
}
6565

@@ -206,23 +206,23 @@ eval {
206206
die("stat: $!\n") unless @s;
207207
my $l = $s[7];
208208
reply(undef, "Content-Length: $l", 'Content-Type: application/octet-stream');
209+
$l = 0 if $action eq 'HEAD';
209210
my $data;
210-
while (1) {
211-
last unless $l;
212-
my $r = sysread($f, $data, 8192);
211+
while ($l > 0) {
212+
die("unexpected EOF in data\n") unless sysread($f, $data, 8192);
213213
$data = substr($data, 0, $l) if length($data) > $l;
214214
$l -= length($data);
215-
while (length($data)) {
216-
my $l2 = syswrite($sock, $data, length($data));
217-
die("socket write: $!\n") unless $l2;
218-
$data = substr($data, $l2);
219-
}
215+
replyraw($data);
220216
}
221217
close($f);
222218
} else {
223219
die("404 File not found\n");
224220
}
225221
};
226-
reply_error($@) if $@;
222+
if ($@) {
223+
my $err = $@;
224+
eval { reply_error($err) };
225+
print "[$@]" if $@;
226+
}
227227
close $sock;
228228
print "[$status $path]";

0 commit comments

Comments
 (0)