unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH] examples/public-inbox.psgi: make output chunky by default
@ 2015-12-25 12:06 Eric Wong
  2015-12-25 12:06 ` [PATCH] view: favor whitespace wrap in <head> Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2015-12-25 12:06 UTC (permalink / raw)
  To: meta

HTTP/1.1 clients will want persistent connections and
need to know response terminations.
---
 examples/public-inbox.psgi | 1 +
 t/plack.t                  | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/public-inbox.psgi b/examples/public-inbox.psgi
index b0b9ae9..4d34b42 100644
--- a/examples/public-inbox.psgi
+++ b/examples/public-inbox.psgi
@@ -12,6 +12,7 @@ use Plack::Builder;
 my $have_deflater = eval { require Plack::Middleware::Deflater; 1 };
 
 builder {
+	enable 'Plack::Middleware::Chunked';
 	if ($have_deflater) {
 		enable "Deflater",
 			content_type => [ 'text/html', 'text/plain',
diff --git a/t/plack.t b/t/plack.t
index 560080f..31ec58d 100644
--- a/t/plack.t
+++ b/t/plack.t
@@ -116,7 +116,7 @@ EOF
 		my ($cb) = @_;
 		my $res = $cb->(GET($pfx . '/blah%40example.com/raw'));
 		is(200, $res->code, 'success response received for /*/raw');
-		like($res->content, qr!\AFrom !, "mbox returned");
+		like($res->content, qr!^From !sm, "mbox returned");
 	});
 
 	# legacy redirects
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] view: favor whitespace wrap in <head>
  2015-12-25 12:06 [PATCH] examples/public-inbox.psgi: make output chunky by default Eric Wong
@ 2015-12-25 12:06 ` Eric Wong
  2015-12-26  0:57   ` [PATCH] searchview: fixup stupid syntax error Eric Wong
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Wong @ 2015-12-25 12:06 UTC (permalink / raw)
  To: meta

If we bite the bullet and rely on inline CSS, we might as well
only specify it once per page instead of inline in every <pre>
tag which may handle UGC.  So this actually saves us a small
amount of bandwith on most pages which have multiple <pre>
start tags.
---
 lib/PublicInbox/Feed.pm       |  8 ++++----
 lib/PublicInbox/Hval.pm       |  3 ++-
 lib/PublicInbox/SearchView.pm |  2 +-
 lib/PublicInbox/View.pm       | 18 ++++++++++--------
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 150bea0..7ebc050 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -128,18 +128,18 @@ sub emit_html_index {
 	my $top = "<b>$title</b> (<a\nhref=\"$atom_url\">Atom feed</a>)";
 
 	if ($srch) {
-		$top = qq{<form\naction=""><tt>$top} .
+		$top = qq{<form\naction=""><pre>$top} .
 			  qq{ <input\nname=q\ntype=text />} .
 			  qq{<input\ntype=submit\nvalue=search />} .
-			  qq{</tt></form>} .
-			  PublicInbox::Hval::PRE;
+			  q{</pre></form><pre>}
 	} else {
-		$top = PublicInbox::Hval::PRE . $top . "\n";
+		$top = '<pre>' . $top . "\n";
 	}
 
 	$fh->write("<html><head><title>$title</title>" .
 		   "<link\nrel=alternate\ntitle=\"Atom feed\"\n".
 		   "href=\"$atom_url\"\ntype=\"application/atom+xml\"/>" .
+		   PublicInbox::Hval::STYLE .
 		   "</head><body>$top");
 
 	# if the 'r' query parameter is given, it is a legacy permalink
diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm
index e0b85c6..5a86935 100644
--- a/lib/PublicInbox/Hval.pm
+++ b/lib/PublicInbox/Hval.pm
@@ -13,7 +13,8 @@ use PublicInbox::MID qw/mid_clean/;
 # for user-generated content (UGC) which may have excessively long lines
 # and screw up rendering on some browsers.  This is the only CSS style
 # feature we use.
-use constant PRE => "<pre\nstyle=\"white-space:pre-wrap\">";
+use constant STYLE => '<style>pre{white-space:pre-wrap}</style>';
+use constant PRE => "<pre\nstyle=\"white-space:pre-wrap\">"; # legacy
 
 my $enc_ascii = find_encoding('us-ascii');
 
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index fec4f39..5b15e0d 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -32,7 +32,7 @@ sub sres_top_html {
 		$total = $mset->get_matches_estimated;
 	};
 	my $err = $@;
-	my $res = html_start($q, $ctx) . PublicInbox::Hval::PRE;
+	my $res = html_start($q, $ctx) . '<pre>'
 	if ($err) {
 		$code = 400;
 		$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 523d27f..7603c51 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -38,7 +38,7 @@ sub msg_html {
 	}
 	headers_to_html_header($mime, $full_pfx, $ctx) .
 		multipart_text_as_html($mime, $full_pfx) .
-		'</pre><hr />' . PublicInbox::Hval::PRE .
+		'</pre><hr /><pre>' .
 		html_footer($mime, 1, $full_pfx, $ctx) .
 		$footer .
 		'</pre></body></html>';
@@ -47,6 +47,7 @@ sub msg_html {
 sub feed_entry {
 	my ($class, $mime, $full_pfx) = @_;
 
+	# no <head> here for <style>...
 	PublicInbox::Hval::PRE .
 		multipart_text_as_html($mime, $full_pfx) . '</pre>';
 }
@@ -107,7 +108,7 @@ sub index_entry {
 	if ($level) {
 		$rv .= '<td><pre>' . (INDENT x $level) . '</pre></td>';
 	}
-	$rv .= "<td\nid=s$midx>" . PublicInbox::Hval::PRE;
+	$rv .= "<td\nid=s$midx><pre>";
 	$rv .= "<b\nid=$id>$subj</b>\n";
 	$rv .= "- $from @ $ts UTC - ";
 	$rv .= "<a\nhref=\"#s$next\">next</a>";
@@ -206,8 +207,8 @@ sub emit_thread_html {
 	$next .= "\ndownload thread: ";
 	$next .= "<a\n$MBOX_TITLE\nhref=\"../t.mbox.gz\">mbox.gz</a>";
 	$next .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>";
-	$cb->write("<hr />" . PublicInbox::Hval::PRE . $next . "\n\n".
-		$foot .  "</pre></body></html>");
+	$cb->write('<hr /><pre>' . $next . "\n\n".
+			$foot .  '</pre></body></html>');
 	$cb->close;
 }
 
@@ -451,8 +452,8 @@ sub headers_to_html_header {
 	}
 	$rv .= "\n";
 
-	("<html><head><title>".  join(' - ', @title) .
-	 "</title>$atom</head><body>" . PublicInbox::Hval::PRE . $rv);
+	("<html><head><title>".  join(' - ', @title) . "</title>$atom".
+	 PublicInbox::Hval::STYLE . "</head><body><pre>" . $rv);
 }
 
 sub thread_inline {
@@ -616,6 +617,7 @@ sub thread_html_head {
 	$$cb->write("<html><head><title>$s</title>".
 		qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
 		qq!href="../t.atom"\ntype="application/atom+xml"/>! .
+		PublicInbox::Hval::STYLE .
 		"</head><body>");
 }
 
@@ -639,8 +641,8 @@ sub ghost_parent {
 sub ghost_table {
 	my ($upfx, $mid, $level) = @_;
 	"<table\nsummary=ghost><tr><td>" .
-		(INDENT x $level) . "</td><td>" .
-		PublicInbox::Hval::PRE . ghost_parent($upfx, $mid) .
+		(INDENT x $level) . '</td><td><pre>' .
+		ghost_parent($upfx, $mid) .
 		'</pre></td></table>';
 }
 
-- 
EW


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] searchview: fixup stupid syntax error
  2015-12-25 12:06 ` [PATCH] view: favor whitespace wrap in <head> Eric Wong
@ 2015-12-26  0:57   ` Eric Wong
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-12-26  0:57 UTC (permalink / raw)
  To: meta

Fixes: commit 398e29344ecc43548a7d3998bb5d2fcee62d66cd
("view: favor whitespace wrap in <head>")

Oops.
---
 lib/PublicInbox/SearchView.pm | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 5b15e0d..9a58156 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -32,7 +32,7 @@ sub sres_top_html {
 		$total = $mset->get_matches_estimated;
 	};
 	my $err = $@;
-	my $res = html_start($q, $ctx) . '<pre>'
+	my $res = html_start($q, $ctx) . '<pre>';
 	if ($err) {
 		$code = 400;
 		$res .= err_txt($err) . "</pre><hr /><pre>" . foot($ctx);
-- 
EW

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-26  0:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-25 12:06 [PATCH] examples/public-inbox.psgi: make output chunky by default Eric Wong
2015-12-25 12:06 ` [PATCH] view: favor whitespace wrap in <head> Eric Wong
2015-12-26  0:57   ` [PATCH] searchview: fixup stupid syntax error 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).