From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] t/httpd-corner: test HTTP chunking with curl
Date: Wed, 24 Feb 2016 04:17:31 +0000 [thread overview]
Message-ID: <20160224041731.25610-1-e@80x24.org> (raw)
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
reply other threads:[~2016-02-24 4:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160224041731.25610-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).