From d5d8cd3033c0dc9a65277f0b4cf0fc7f1654500f Mon Sep 17 00:00:00 2001 From: david Date: Fri, 7 Mar 2014 05:54:48 +0000 Subject: [PATCH] Add tests for 0-length POSTs. The non-chunked one fails for me. FAIL HTTP POST Content-Length: 0 Read timeout at ./ncat-test.pl line 2087. --- ncat/test/ncat-test.pl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ncat/test/ncat-test.pl b/ncat/test/ncat-test.pl index bc3e21d8b..5c5e1f68b 100755 --- a/ncat/test/ncat-test.pl +++ b/ncat/test/ncat-test.pl @@ -2079,6 +2079,17 @@ proxy_test_raw "HTTP POST", $resp->content eq "abc\n" or die "Proxy sent \"" . $resp->content . "\""; }; +proxy_test_raw "HTTP POST Content-Length: 0", +[], [], [], sub { + my $req = "POST http://$HOST:$PORT/ HTTP/1.0\r\nContent-Length: 0\r\n\r\n"; + syswrite($c_in, $req); + close($c_in); + my $resp = timeout_read($s_out) or die "Read timeout"; + $resp = HTTP::Request->parse($resp); + $resp->method eq "POST" or die "Proxy sent \"" . $resp->method . "\""; + $resp->content eq "" or die "Proxy sent \"" . $resp->content . "\""; +}; + proxy_test_raw "HTTP POST short Content-Length", [], [], [], sub { my $req = "POST http://$HOST:$PORT/ HTTP/1.0\r\nContent-Length: 2\r\n\r\nabc\n"; @@ -2120,6 +2131,23 @@ proxy_test_raw "HTTP POST chunked transfer encoding", } }; +proxy_test_raw "HTTP POST chunked transfer encoding, no data", +[], [], [], sub { + my $req = "POST http://$HOST:$PORT/ HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n"; + syswrite($c_in, $req); + close($c_in); + my $resp = timeout_read($s_out); + if ($resp) { + $resp = HTTP::Request->parse($resp); + $resp->method eq "POST" or die "Proxy sent \"" . $resp->method . "\""; + $resp->content eq "" or die "Proxy sent \"" . $resp->content . "\""; + } else { + $resp = timeout_read($c_out) or die "Read timeout"; + $resp = HTTP::Response->parse($resp); + $resp->code == 400 or $resp->code == 411 or die "Proxy returned code " . $resp->code; + } +}; + server_client_test "HTTP proxy unknown method", ["--proxy-type", "http"], [], sub { # Supposed to have a port number.