From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [RFC] extras: include status messages in responses
Date: Tue, 5 Jul 2016 20:39:11 +0000 [thread overview]
Message-ID: <20160705203911.GA29589@dcvr.yhbt.net> (raw)
This is mainly to benefit curl(1) users who forget to use '-f'
to show failures. Not sure if I want to keep this change, it
seems like bloat; but Rack::ShowStatus pages are totally
overkill...
---
It's a reduction in code, at least :> But not runtime code :<
| 5 +++--
| 5 +++--
| 9 +++------
3 files changed, 9 insertions(+), 10 deletions(-)
--git a/extras/autoindex.rb b/extras/autoindex.rb
index 4deb3ef..238edd9 100644
--- a/extras/autoindex.rb
+++ b/extras/autoindex.rb
@@ -168,8 +168,9 @@ def r(code, exc = nil, env = nil)
if Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(code)
[ code, {}, [] ]
else
- h = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
- [ code, h, [] ]
+ msg = "#{code} #{Rack::Utils::HTTP_STATUS_CODES[code.to_i]}\n"
+ h = { 'Content-Type' => 'text/plain', 'Content-Length' => msg.size.to_s }
+ [ code, h, [ msg ] ]
end
end
--git a/extras/try_gzip_static.rb b/extras/try_gzip_static.rb
index ed561cb..d412589 100644
--- a/extras/try_gzip_static.rb
+++ b/extras/try_gzip_static.rb
@@ -216,8 +216,9 @@ def r(code, exc = nil, env = nil)
if Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(code)
[ code, {}, [] ]
else
- h = { 'Content-Type' => 'text/plain', 'Content-Length' => '0' }
- [ code, h, [] ]
+ msg = "#{code} #{Rack::Utils::HTTP_STATUS_CODES[code.to_i]}\n"
+ h = { 'Content-Type' => 'text/plain', 'Content-Length' => msg.size.to_s }
+ [ code, h, [ msg ] ]
end
end
end
--git a/test/test_extras_try_gzip_static.rb b/test/test_extras_try_gzip_static.rb
index 60129df..b6d5943 100644
--- a/test/test_extras_try_gzip_static.rb
+++ b/test/test_extras_try_gzip_static.rb
@@ -125,11 +125,10 @@ def test_gzip_static
req = "#{m} /COPYING HTTP/1.0\r\n" \
"Range: bytes=66666666-\r\nAccept-Encoding: gzip"
- body = check.call(req) do |head|
+ check.call(req) do |head|
assert_match %r{^Content-Range: bytes \*/#{st.size}\r\n}, head
assert_match %r{\AHTTP/1\.1 416 }, head
end
- assert_nil body
end
end
@@ -181,15 +180,13 @@ def test_gzip_static
Timeout.timeout(30) do # 404
%w(GET HEAD).each do |m|
req = "#{m} /cp-ing HTTP/1.0\r\nAccept-Encoding: gzip"
- body = check.call(req) do |head|
+ check.call(req) do |head|
assert_match %r{HTTP/1\.1 404 }, head
end
- assert_nil body
end
- body = check.call("FOO /COPYING HTTP/1.0") do |head|
+ check.call("FOO /COPYING HTTP/1.0") do |head|
assert_match %r{HTTP/1\.1 405 }, head
end
- assert_nil body
end
Net::HTTP.start(host, port) do |http|
--
EW
reply other threads:[~2016-07-05 20:39 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://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160705203911.GA29589@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/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://yhbt.net/yahns.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).