user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] t/git-http-backend.t: remove TEST_CHUNK env setting
@ 2018-12-25 11:14  5% Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2018-12-25 11:14 UTC (permalink / raw)
  To: meta

TEST_CHUNK hast not been relevant since 2016:
(commit bb38f0fcce73904e "http: chunk in the server, not middleware")
---
 t/git-http-backend.t | 1 -
 1 file changed, 1 deletion(-)

diff --git a/t/git-http-backend.t b/t/git-http-backend.t
index cb5e5d2..046a778 100644
--- a/t/git-http-backend.t
+++ b/t/git-http-backend.t
@@ -57,7 +57,6 @@ my $get_maxrss = sub {
 		dup2(fileno($sock), 3) or die "dup2 failed: $!\n";
 		$ENV{LISTEN_PID} = $$;
 		$ENV{LISTEN_FDS} = 1;
-		$ENV{TEST_CHUNK} = '1';
 		exec $httpd, "--stdout=$out", "--stderr=$err", $psgi;
 		die "FAIL: $!\n";
 	}
-- 
EW


^ permalink raw reply	[relevance 5%]

* [PATCH] http: avoid uninitialized variable
  2016-05-23  7:19  7% [PATCH] http: chunk in the server, not middleware Eric Wong
@ 2016-05-24  0:50  5% ` Eric Wong
  0 siblings, 0 replies; 3+ results
From: Eric Wong @ 2016-05-24  0:50 UTC (permalink / raw)
  To: meta

Oops, really gotta start checking logs in tests :x

Fixes: bb38f0fcce739 ("http: chunk in the server, not middleware")
---
 lib/PublicInbox/HTTP.pm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 77b178c..104a213 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -190,6 +190,7 @@ sub response_header_write {
 		$alive = 1;
 		$h .= "Connection: keep-alive\r\n";
 	} else {
+		$alive = 0;
 		$h .= "Connection: close\r\n";
 	}
 	$h .= 'Date: ' . http_date() . "\r\n\r\n";

^ permalink raw reply	[relevance 5%]

* [PATCH] http: chunk in the server, not middleware
@ 2016-05-23  7:19  7% Eric Wong
  2016-05-24  0:50  5% ` [PATCH] http: avoid uninitialized variable Eric Wong
  0 siblings, 1 reply; 3+ results
From: Eric Wong @ 2016-05-23  7:19 UTC (permalink / raw)
  To: meta

Since PSGI does not require Transfer-Encoding: chunked or
Content-Length, we cannot expect random apps we host to chunk
their responses.

Thus, to improve interoperability, chunk at the HTTP layer like
other PSGI servers do.  I'm chosing a more syscall-intensive method
(via multiple send(...MSG_MORE) for now to reduce copy + packet
overhead.
---
 examples/public-inbox.psgi |  5 -----
 lib/PublicInbox/HTTP.pm    | 39 +++++++++++++++++++++++++++++++--------
 script/public-inbox-httpd  |  1 -
 t/git-http-backend.psgi    |  1 -
 4 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/examples/public-inbox.psgi b/examples/public-inbox.psgi
index 876fc76..4edbf5e 100644
--- a/examples/public-inbox.psgi
+++ b/examples/public-inbox.psgi
@@ -12,11 +12,6 @@ PublicInbox::WWW->preload;
 use Plack::Builder;
 my $www = PublicInbox::WWW->new;
 builder {
-	# Chunked middleware conflicts with Starman:
-	# https://github.com/miyagawa/Starman/issues/23
-	# However, it is strongly recommended to enable it if using
-	# public-inbox-httpd to allow persistent connections
-	# enable 'Chunked';
 	eval {
 		enable 'Deflater',
 			content_type => [ qw(
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 480800b..77b178c 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -180,12 +180,19 @@ sub response_header_write {
 
 	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));
-
-	$h .= 'Connection: ' . ($alive ? 'keep-alive' : 'close');
-	$h .= "\r\nDate: " . http_date() . "\r\n\r\n";
+	my $prot_persist = ($proto eq 'HTTP/1.1') && ($conn !~ /\bclose\b/i);
+	my $alive;
+	if (!$term && $prot_persist) { # auto-chunk
+		$chunked = $alive = 2;
+		$h .= "Transfer-Encoding: chunked\r\n";
+		# no need for "Connection: keep-alive" with HTTP/1.1
+	} elsif ($term && ($prot_persist || ($conn =~ /\bkeep-alive\b/i))) {
+		$alive = 1;
+		$h .= "Connection: keep-alive\r\n";
+	} else {
+		$h .= "Connection: close\r\n";
+	}
+	$h .= 'Date: ' . http_date() . "\r\n\r\n";
 
 	if (($len || $chunked) && $env->{REQUEST_METHOD} ne 'HEAD') {
 		more($self, $h);
@@ -195,13 +202,29 @@ sub response_header_write {
 	$alive;
 }
 
+# middlewares such as Deflater may write empty strings
+sub chunked_wcb ($) {
+	my ($self) = @_;
+	sub {
+		return if $_[0] eq '';
+		more($self, sprintf("%x\r\n", bytes::length($_[0])));
+		more($self, $_[0]);
+		$self->write("\r\n");
+	}
+}
+
+sub identity_wcb ($) {
+	my ($self) = @_;
+	sub { $self->write(\($_[0])) if $_[0] ne '' }
+}
+
 sub response_write {
 	my ($self, $env, $res) = @_;
 	my $alive = response_header_write($self, $env, $res);
 
-	# middlewares such as Deflater may write empty strings
-	my $write = sub { $self->write(\($_[0])) if $_[0] ne '' };
+	my $write = $alive == 2 ? chunked_wcb($self) : identity_wcb($self);
 	my $close = sub {
+		$self->write("0\r\n\r\n") if $alive == 2;
 		if ($alive) {
 			$self->event_write; # watch for readability if done
 		} else {
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index b29effc..f19582f 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -25,7 +25,6 @@ my $refresh = sub {
 		PublicInbox::WWW->preload;
 		my $www = PublicInbox::WWW->new;
 		$app = builder {
-			enable 'Chunked';
 			eval {
 				enable 'Deflater',
 					content_type => [ qw(
diff --git a/t/git-http-backend.psgi b/t/git-http-backend.psgi
index 8cec7d3..c960714 100644
--- a/t/git-http-backend.psgi
+++ b/t/git-http-backend.psgi
@@ -11,7 +11,6 @@ use BSD::Resource qw(getrusage);
 my $git_dir = $ENV{GIANT_GIT_DIR} or die 'GIANT_GIT_DIR not defined in env';
 my $git = PublicInbox::Git->new($git_dir);
 builder {
-	enable 'Chunked' if $ENV{TEST_CHUNK};
 	enable 'Head';
 	sub {
 		my ($env) = @_;

^ permalink raw reply	[relevance 7%]

Results 1-3 of 3 | reverse | sort options + mbox downloads above
-- links below jump to the message on this page --
2016-05-23  7:19  7% [PATCH] http: chunk in the server, not middleware Eric Wong
2016-05-24  0:50  5% ` [PATCH] http: avoid uninitialized variable Eric Wong
2018-12-25 11:14  5% [PATCH] t/git-http-backend.t: remove TEST_CHUNK env setting Eric Wong

Code repositories for project(s) associated with this 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).