From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 661522070C; Tue, 5 Jul 2016 20:39:11 +0000 (UTC) Date: Tue, 5 Jul 2016 20:39:11 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [RFC] extras: include status messages in responses Message-ID: <20160705203911.GA29589@dcvr.yhbt.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline List-Id: 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