yahns Ruby server user/dev discussion
 help / color / Atom feed
* [RFC] extras: include status messages in responses
@ 2016-07-05 20:39 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-07-05 20:39 UTC (permalink / raw)
  To: yahns-public

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 :<

 extras/autoindex.rb                 | 5 +++--
 extras/try_gzip_static.rb           | 5 +++--
 test/test_extras_try_gzip_static.rb | 9 +++------
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --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
 
diff --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
diff --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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-05 20:39 [RFC] extras: include status messages in responses Eric Wong

yahns Ruby server user/dev discussion

Archives are clonable:
	git clone --mirror https://yhbt.net/yahns-public
	git clone --mirror http://ou63pmih66umazou.onion/yahns-public

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns
	nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.yahns

 note: .onion URLs require Tor: https://www.torproject.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox