From 1bb4362cee167ac7aeec910d3f52419e391f1e61 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 5 Jun 2023 10:12:33 +0000 Subject: [PATCH 04/23] port t0000-http-basic.sh to Perl 5 One more socat dependency down... --- t/integration.ru | 16 ++++++++++++++ t/integration.t | 11 ++++++++++ t/t0000-http-basic.sh | 50 ------------------------------------------- 3 files changed, 27 insertions(+), 50 deletions(-) delete mode 100755 t/t0000-http-basic.sh diff --git a/t/integration.ru b/t/integration.ru index 12f5d48..c0bef99 100644 --- a/t/integration.ru +++ b/t/integration.ru @@ -32,6 +32,21 @@ def write_on_close [ 200, { 'transfer-encoding' => 'chunked' }, WriteOnClose.new ] end +def env_dump(env) + require 'json' + h = {} + env.each do |k,v| + case v + when String, Integer, true, false; h[k] = v + else + case k + when 'rack.version', 'rack.after_reply'; h[k] = v + end + end + end + h.to_json +end + run(lambda do |env| case env['REQUEST_METHOD'] when 'GET' @@ -40,6 +55,7 @@ def write_on_close when '/rack-3-array-headers'; [ 200, { 'x-r3' => %w(a b c) }, [] ] when '/nil-header-value'; [ 200, { 'X-Nil' => nil }, [] ] when '/unknown-status-pass-through'; [ '666 I AM THE BEAST', {}, [] ] + when '/env_dump'; [ 200, {}, [ env_dump(env) ] ] when '/write_on_close'; write_on_close end # case PATH_INFO (GET) when 'POST' diff --git a/t/integration.t b/t/integration.t index 3ab5c90..ee22e7e 100644 --- a/t/integration.t +++ b/t/integration.t @@ -47,6 +47,17 @@ is_deeply([ grep(/^x-r3: /, @$hdr) ], [ 'x-r3: a', 'x-r3: b', 'x-r3: c' ], 'rack 3 array headers supported') or diag(explain($hdr)); +SKIP: { + eval { require JSON::PP } or skip "JSON::PP missing: $@", 1; + $c = tcp_connect($srv); + print $c "GET /env_dump\r\n" or die $!; + my $json = do { local $/; readline($c) }; + unlike($json, qr/^Connection: /smi, 'no connection header for 0.9'); + unlike($json, qr!\AHTTP/!s, 'no HTTP/1.x prefix for 0.9'); + my $env = JSON::PP->new->decode($json); + is(ref($env), 'HASH', 'JSON decoded body to hashref'); + is($env->{SERVER_PROTOCOL}, 'HTTP/0.9', 'SERVER_PROTOCOL is 0.9'); +} # cf. $c = tcp_connect($srv); diff --git a/t/t0000-http-basic.sh b/t/t0000-http-basic.sh deleted file mode 100755 index 8ab58ac..0000000 --- a/t/t0000-http-basic.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/bin/sh -. ./test-lib.sh -t_plan 8 "simple HTTP connection tests" - -t_begin "setup and start" && { - unicorn_setup - unicorn -D -c $unicorn_config env.ru - unicorn_wait_start -} - -t_begin "single request" && { - curl -sSfv http://$listen/ -} - -t_begin "check stderr has no errors" && { - check_stderr -} - -t_begin "HTTP/0.9 request should not return headers" && { - ( - printf 'GET /\r\n' - cat $fifo > $tmp & - wait - echo ok > $ok - ) | socat - TCP:$listen > $fifo -} - -t_begin "env.inspect should've put everything on one line" && { - test 1 -eq $(count_lines < $tmp) -} - -t_begin "no headers in output" && { - if grep ^Connection: $tmp - then - die "Connection header found in $tmp" - elif grep ^HTTP/ $tmp - then - die "HTTP/ found in $tmp" - fi -} - -t_begin "killing succeeds" && { - kill $unicorn_pid -} - -t_begin "check stderr has no errors" && { - check_stderr -} - -t_done