diff --git a/server.pl b/server.pl index c3dfa32..876b3ba 100644 --- a/server.pl +++ b/server.pl @@ -175,6 +175,11 @@ if (defined $ENV{'LOCAL_DOMAINS'}) { $type = 'application/json'; } my $length = length($body); + $body = '' if $cgi->request_method() eq 'HEAD'; + my $content_header = ''; + if ($length > 0) { + $content_header = "\nContent-Type: $type\nContent-Length: $length"; + } my $now = time; my $date = HTTP::Date::time2str($now); my $redirect_header = ''; @@ -189,9 +194,7 @@ if (defined $ENV{'LOCAL_DOMAINS'}) { print <{'mtime'}; - if ($cgi->request_method() ne 'HEAD') { - if ($format eq 'application/json') { - $body = encode_json($plan); - } elsif ($format eq 'text/html') { - $body = encode_entities($plan->{'plan'}); - $body =~ s/\n/
\n/g; - } else { - $body = $plan->{'plan'}; - } + if ($format eq 'application/json') { + $body = encode_json($plan); + } elsif ($format eq 'text/html') { + $body = encode_entities($plan->{'plan'}); + $body =~ s/\n/
\n/g; + } else { + $body = $plan->{'plan'}; } print_response($cgi, 200, $body, $format, undef, $mtime); } diff --git a/test/run.sh b/test/run.sh index e0af33b..f814227 100755 --- a/test/run.sh +++ b/test/run.sh @@ -181,7 +181,7 @@ curl_test 'Get authentication token' 200 'application/json' -u $TEST_USER:test12 token=$(echo "$TEST_CONTENT" | jq -r '.token') -curl_test 'No plan by default' 404 'text/plain' localhost:$PORT/plan/$TEST_USER +curl_test 'No plan by default' 404 '' localhost:$PORT/plan/$TEST_USER curl_test 'Reject bad authentication token' 401 'application/json' -XPUT -d '{"plan":"something","auth":"wrong"}' localhost:$PORT/plan/$TEST_USER @@ -218,11 +218,11 @@ curl_test 'Check missing plan in json using accept' 404 'application/json' -H 'A curl_test 'Check missing plan in json using querystring' 404 'application/json' localhost:$PORT/plan/testuser@exampl3.com?format=json -curl_test 'Check missing plan in html using accept' 404 'text/html' -H 'Accept: text/html' localhost:$PORT/plan/testuser@exampl3.com +curl_test 'Check missing plan in html using accept' 404 '' -H 'Accept: text/html' localhost:$PORT/plan/testuser@exampl3.com -curl_test 'Check missing plan in html using querystring' 404 'text/html' localhost:$PORT/plan/testuser@exampl3.com?format=html +curl_test 'Check missing plan in html using querystring' 404 '' localhost:$PORT/plan/testuser@exampl3.com?format=html -curl_test 'Check missing plan in text by omitting accept' 404 'text/plain' localhost:$PORT/plan/testuser@exampl3.com +curl_test 'Check missing plan in text by omitting accept' 404 '' localhost:$PORT/plan/testuser@exampl3.com curl_test 'Delete authentication token' 200 'application/json' -u $TEST_USER:test1234 -XDELETE localhost:$PORT/token