* [PATCH] t/httpd-corner: test HTTP chunking with curl
@ 2016-02-24 4:17 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-02-24 4:17 UTC (permalink / raw)
To: meta
Just in case my knowledge of chunking is wrong.
---
t/httpd-corner.t | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/t/httpd-corner.t b/t/httpd-corner.t
index 5834c1b..366e56c 100644
--- a/t/httpd-corner.t
+++ b/t/httpd-corner.t
@@ -16,7 +16,7 @@ use Digest::SHA qw(sha1_hex);
use File::Temp qw/tempdir/;
use Cwd qw/getcwd/;
use IO::Socket;
-use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD);
+use Fcntl qw(FD_CLOEXEC F_SETFD F_GETFD :seek);
use Socket qw(SO_KEEPALIVE IPPROTO_TCP TCP_NODELAY);
my $tmpdir = tempdir(CLEANUP => 1);
my $err = "$tmpdir/stderr.log";
@@ -82,6 +82,43 @@ my $check_self = sub {
is($body, sha1_hex($str), 'read expected body');
};
+SKIP: {
+ use POSIX qw(dup2);
+ use IO::File;
+ my $have_curl = 0;
+ foreach my $p (split(':', $ENV{PATH})) {
+ -x "$p/curl" or next;
+ $have_curl = 1;
+ last;
+ }
+ my $ntest = 2;
+ $have_curl or skip('curl(1) missing', $ntest);
+ my $url = 'http://' . $sock->sockhost . ':' . $sock->sockport . '/sha1';
+ my ($r, $w);
+ pipe($r, $w) or die "pipe: $!";
+ my $tout = IO::File->new_tmpfile or die "new_tmpfile: $!";
+ my $pid = fork;
+ defined $pid or die "fork: $!";
+ my @cmd = (qw(curl --tcp-nodelay --no-buffer -T- -HExpect: -sS), $url);
+ if ($pid == 0) {
+ dup2(fileno($r), 0) or die "redirect stdin failed: $!\n";
+ dup2(fileno($tout), 1) or die "redirect stdout failed: $!\n";
+ exec(@cmd) or die 'exec `' . join(' '). "' failed: $!\n";
+ }
+ $w->autoflush(1);
+ foreach my $c ('a'..'z') {
+ print $w $c or die "failed to write to curl: $!";
+ delay();
+ }
+ close $w or die "close write pipe: $!";
+ close $r or die "close read pipe: $!";
+ my $kid = waitpid $pid, 0;
+ is($?, 0, 'curl exited successfully');
+ $tout->sysseek(0, SEEK_SET);
+ $tout->sysread(my $buf, 100);
+ is($buf, sha1_hex($str), 'read expected body');
+}
+
{
my $conn = conn_for($sock, '1.1 pipeline together');
$conn->write("PUT /sha1 HTTP/1.1\r\nUser-agent: hello\r\n\r\n" .
--
EW
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-02-24 4:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-24 4:17 [PATCH] t/httpd-corner: test HTTP chunking with curl Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).