rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / code / Atom feed
* [PATCH] chunked: do not chunk on pre-HTTP/1.0 clients
@ 2013-11-12 21:07 Eric Wong
  2014-07-15  4:11 ` James Tucker
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Wong @ 2013-11-12 21:07 UTC (permalink / raw)
  To: rack-devel

Ancient HTTP clients which predate HTTP/1.0 may not set HTTP_VERSION
at all, and those do not support chunking.

RFC 1945 describes HTTP/0.9 as well as HTTP/1.0
---
  The following changes since commit df1506b0825a096514fcb3821563bf9e8fd52743:

    Merge pull request #617 from tmm1/builder-warmup (2013-10-25 21:10:40 -0700)

  are available in the git repository at:

    git://bogomips.org/rack.git ancient-chunked

  for you to fetch changes up to fd3b5312625f06baeda726ef4b32e7a3ac336698:

    chunked: do not chunk on pre-HTTP/1.0 clients (2013-11-12 20:58:46 +0000)

 lib/rack/chunked.rb  | 13 ++++++++++++-
 test/spec_chunked.rb | 16 ++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

 Yes, I'm a caveman!

diff --git a/lib/rack/chunked.rb b/lib/rack/chunked.rb
index a400756..ea221fa 100644
--- a/lib/rack/chunked.rb
+++ b/lib/rack/chunked.rb
@@ -39,11 +39,22 @@ module Rack
       @app = app
     end
 
+    # pre-HTTP/1.0 (informally "HTTP/0.9") HTTP requests did not have
+    # a version (nor response headers)
+    def chunkable_version?(ver)
+      case ver
+      when "HTTP/1.0", nil, "HTTP/0.9"
+        false
+      else
+        true
+      end
+    end
+
     def call(env)
       status, headers, body = @app.call(env)
       headers = HeaderHash.new(headers)
 
-      if env['HTTP_VERSION'] == 'HTTP/1.0' ||
+      if ! chunkable_version?(env['HTTP_VERSION']) ||
          STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
          headers['Content-Length'] ||
          headers['Transfer-Encoding']
diff --git a/test/spec_chunked.rb b/test/spec_chunked.rb
index 12f2158..0a6d9ff 100644
--- a/test/spec_chunked.rb
+++ b/test/spec_chunked.rb
@@ -64,6 +64,22 @@ describe Rack::Chunked do
     body.join.should.equal 'Hello World!'
   end
 
+  should 'not modify response when client is ancient, pre-HTTP/1.0' do
+    app = lambda { |env| [200, {"Content-Type" => "text/plain"}, ['Hello', ' ', 'World!']] }
+    check = lambda do
+      status, headers, body = chunked(app).call(@env.dup)
+      status.should.equal 200
+      headers.should.not.include 'Transfer-Encoding'
+      body.join.should.equal 'Hello World!'
+    end
+
+    @env.delete('HTTP_VERSION') # unicorn will do this on pre-HTTP/1.0 requests
+    check.call
+
+    @env['HTTP_VERSION'] = 'HTTP/0.9' # not sure if this happens in practice
+    check.call
+  end
+
   should 'not modify response when Transfer-Encoding header already present' do
     app = lambda { |env|
       [200, {"Content-Type" => "text/plain", 'Transfer-Encoding' => 'identity'}, ['Hello', ' ', 'World!']]
-- 
EW

-- 

--- 
You received this message because you are subscribed to the Google Groups "Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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

* Re: [PATCH] chunked: do not chunk on pre-HTTP/1.0 clients
  2013-11-12 21:07 [PATCH] chunked: do not chunk on pre-HTTP/1.0 clients Eric Wong
@ 2014-07-15  4:11 ` James Tucker
  0 siblings, 0 replies; 2+ messages in thread
From: James Tucker @ 2014-07-15  4:11 UTC (permalink / raw)
  To: rack-devel

[-- Attachment #1: Type: text/plain, Size: 3446 bytes --]

Thanks!


On Tue, Nov 12, 2013 at 1:07 PM, Eric Wong <normalperson@yhbt.net> wrote:

> Ancient HTTP clients which predate HTTP/1.0 may not set HTTP_VERSION
> at all, and those do not support chunking.
>
> RFC 1945 describes HTTP/0.9 as well as HTTP/1.0
> ---
>   The following changes since commit
> df1506b0825a096514fcb3821563bf9e8fd52743:
>
>     Merge pull request #617 from tmm1/builder-warmup (2013-10-25 21:10:40
> -0700)
>
>   are available in the git repository at:
>
>     git://bogomips.org/rack.git ancient-chunked
>
>   for you to fetch changes up to fd3b5312625f06baeda726ef4b32e7a3ac336698:
>
>     chunked: do not chunk on pre-HTTP/1.0 clients (2013-11-12 20:58:46
> +0000)
>
>  lib/rack/chunked.rb  | 13 ++++++++++++-
>  test/spec_chunked.rb | 16 ++++++++++++++++
>  2 files changed, 28 insertions(+), 1 deletion(-)
>
>  Yes, I'm a caveman!
>
> diff --git a/lib/rack/chunked.rb b/lib/rack/chunked.rb
> index a400756..ea221fa 100644
> --- a/lib/rack/chunked.rb
> +++ b/lib/rack/chunked.rb
> @@ -39,11 +39,22 @@ module Rack
>        @app = app
>      end
>
> +    # pre-HTTP/1.0 (informally "HTTP/0.9") HTTP requests did not have
> +    # a version (nor response headers)
> +    def chunkable_version?(ver)
> +      case ver
> +      when "HTTP/1.0", nil, "HTTP/0.9"
> +        false
> +      else
> +        true
> +      end
> +    end
> +
>      def call(env)
>        status, headers, body = @app.call(env)
>        headers = HeaderHash.new(headers)
>
> -      if env['HTTP_VERSION'] == 'HTTP/1.0' ||
> +      if ! chunkable_version?(env['HTTP_VERSION']) ||
>           STATUS_WITH_NO_ENTITY_BODY.include?(status) ||
>           headers['Content-Length'] ||
>           headers['Transfer-Encoding']
> diff --git a/test/spec_chunked.rb b/test/spec_chunked.rb
> index 12f2158..0a6d9ff 100644
> --- a/test/spec_chunked.rb
> +++ b/test/spec_chunked.rb
> @@ -64,6 +64,22 @@ describe Rack::Chunked do
>      body.join.should.equal 'Hello World!'
>    end
>
> +  should 'not modify response when client is ancient, pre-HTTP/1.0' do
> +    app = lambda { |env| [200, {"Content-Type" => "text/plain"},
> ['Hello', ' ', 'World!']] }
> +    check = lambda do
> +      status, headers, body = chunked(app).call(@env.dup)
> +      status.should.equal 200
> +      headers.should.not.include 'Transfer-Encoding'
> +      body.join.should.equal 'Hello World!'
> +    end
> +
> +    @env.delete('HTTP_VERSION') # unicorn will do this on pre-HTTP/1.0
> requests
> +    check.call
> +
> +    @env['HTTP_VERSION'] = 'HTTP/0.9' # not sure if this happens in
> practice
> +    check.call
> +  end
> +
>    should 'not modify response when Transfer-Encoding header already
> present' do
>      app = lambda { |env|
>        [200, {"Content-Type" => "text/plain", 'Transfer-Encoding' =>
> 'identity'}, ['Hello', ' ', 'World!']]
> --
> EW
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Rack Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rack-devel+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups "Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rack-devel+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #2: Type: text/html, Size: 4808 bytes --]

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

end of thread, other threads:[~2014-07-15  4:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-12 21:07 [PATCH] chunked: do not chunk on pre-HTTP/1.0 clients Eric Wong
2014-07-15  4:11 ` James Tucker

rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/rack-devel

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 rack-devel rack-devel/ https://public-inbox.org/rack-devel \
		rack-devel@googlegroups.com
	public-inbox-index rack-devel

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.lang.ruby.rack.devel
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.lang.ruby.rack.devel
	nntp://news.gmane.io/gmane.comp.lang.ruby.rack.devel
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/rack.git

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