* [PATCH] http: avoid Nagle on "Content-Length: 0" response
@ 2016-04-29 4:00 Eric Wong
2016-04-29 17:15 ` Eric Wong
0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2016-04-29 4:00 UTC (permalink / raw)
To: spew
Oops, we must use a normal write instead of send(.., MSG_MORE)
when writing responses of "Content-Length: 0".
Fixes: c3eeaf664cf0 ("http: clarify intent for persistence")
This needs a proper test.
---
lib/PublicInbox/HTTP.pm | 11 ++++++-----
t/githttpbackend.psgi | 3 ++-
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 2f50241..3b72d58 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -154,7 +154,7 @@ sub response_header_write {
my $proto = $env->{SERVER_PROTOCOL} or return; # HTTP/0.9 :P
my $status = $res->[0];
my $h = "$proto $status " . status_message($status) . "\r\n";
- my $term;
+ my ($len, $chunked);
my $headers = $res->[1];
for (my $i = 0; $i < @$headers; $i += 2) {
@@ -162,14 +162,15 @@ sub response_header_write {
my $v = $headers->[$i + 1];
next if $k =~ /\A(?:Connection|Date)\z/i;
- if ($k =~ /\AContent-Length\z/ ||
- ($k =~ /\ATransfer-Encoding\z/i && $v =~ /\bchunked\b/i)) {
- $term = 1;
+ $len = $v if $k =~ /\AContent-Length\z/i;
+ if ($k =~ /\ATransfer-Encoding\z/i && $v =~ /\bchunked\b/i) {
+ $chunked = 1;
}
$h .= "$k: $v\r\n";
}
my $conn = $env->{HTTP_CONNECTION} || '';
+ my $term = defined($len) || $chunked;
my $alive = $term &&
(($proto eq 'HTTP/1.1' && $conn !~ /\bclose\b/i) ||
($conn =~ /\bkeep-alive\b/i));
@@ -177,7 +178,7 @@ sub response_header_write {
$h .= 'Connection: ' . ($alive ? 'keep-alive' : 'close');
$h .= "\r\nDate: " . http_date() . "\r\n\r\n";
- if ($term && $env->{REQUEST_METHOD} ne 'HEAD') {
+ if (($len || $chunked) && $env->{REQUEST_METHOD} ne 'HEAD') {
more($self, $h);
} else {
$self->write($h);
diff --git a/t/githttpbackend.psgi b/t/githttpbackend.psgi
index 52b3025..311fab6 100644
--- a/t/githttpbackend.psgi
+++ b/t/githttpbackend.psgi
@@ -18,7 +18,8 @@ builder {
if ($pr->path_info =~ m!\A/(.+)\z!s) {
PublicInbox::GitHTTPBackend::serve($pr, $git, $1);
} else {
- [ 404, [ qw(Content-Type text/plain) ], [] ]
+ [ 404, [ qw(Content-Type text/plain
+ Content-Length 0) ], [] ]
}
}
}
--
EW
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] http: avoid Nagle on "Content-Length: 0" response
2016-04-29 4:00 [PATCH] http: avoid Nagle on "Content-Length: 0" response Eric Wong
@ 2016-04-29 17:15 ` Eric Wong
0 siblings, 0 replies; 2+ messages in thread
From: Eric Wong @ 2016-04-29 17:15 UTC (permalink / raw)
To: spew
Erm, this isn't Nagle. MSG_MORE is the same as TCP_CORK :x
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-04-29 17:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-04-29 4:00 [PATCH] http: avoid Nagle on "Content-Length: 0" response Eric Wong
2016-04-29 17:15 ` 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).