Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not return a body for HEAD requests #86

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Starman/Server.pm
Expand Up @@ -473,7 +473,7 @@ sub _finalize_response {


if ( $protocol eq 'HTTP/1.1' ) { if ( $protocol eq 'HTTP/1.1' ) {
if ( !exists $headers{'content-length'} ) { if ( !exists $headers{'content-length'} ) {
if ( $status !~ /^1\d\d|[23]04$/ ) { if ( $status !~ /^1\d\d|[23]04$/ && $env->{REQUEST_METHOD} ne 'HEAD' ) {
DEBUG && warn "[$$] Using chunked transfer-encoding to send unknown length body\n"; DEBUG && warn "[$$] Using chunked transfer-encoding to send unknown length body\n";
push @headers, 'Transfer-Encoding: chunked'; push @headers, 'Transfer-Encoding: chunked';
$chunked = 1; $chunked = 1;
Expand Down
43 changes: 43 additions & 0 deletions t/head_no_body.t
@@ -0,0 +1,43 @@
use strict;
use Test::TCP;
use IO::Socket::INET;
use HTTP::Request;
use HTTP::Response;
use Plack::Loader;
use Test::More;

$ENV{PLACK_SERVER} = 'Starman';

test_tcp(
client => sub {
my $port = shift;

my $socket = IO::Socket::INET->new(
PeerAddr => 'localhost',
PeerPort => $port,
Proto => 'tcp'
) or die "Failed to connect to server: $!";

my $request = HTTP::Request->new(
HEAD => '/', [ Host => 'localhost' ]
);
$request->protocol('HTTP/1.1');

$socket->send($request->as_string("\r\n"));

my $buf;
$socket->recv($buf, 1024);

my $res = HTTP::Response->parse($buf);

is $res->content, '';
},
server => sub {
my $port = shift;
my $server = Plack::Loader->auto(port => $port, host => '127.0.0.1');

$server->run(sub { return [ 200, [], [] ] });
}
);

done_testing;