From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.76.159.169 with SMTP id xd9csp146486oab; Mon, 14 Jul 2014 21:11:36 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncBD75LW742ECRB56TSKPAKGQEXDRC4UI@googlegroups.com designates 10.50.78.138 as permitted sender) client-ip=10.50.78.138 Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncBD75LW742ECRB56TSKPAKGQEXDRC4UI@googlegroups.com designates 10.50.78.138 as permitted sender) smtp.mail=rack-devel+bncBD75LW742ECRB56TSKPAKGQEXDRC4UI@googlegroups.com; dkim=pass header.i=@googlegroups.com X-Received: from mr.google.com ([10.50.78.138]) by 10.50.78.138 with SMTP id b10mr315064igx.17.1405397496144 (num_hops = 1); Mon, 14 Jul 2014 21:11:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe:content-type; bh=LPvZF18Gs9bUK9I4K4t7yqZlEpbA7kA/VDFgcGIKUBI=; b=DAApJWOF6G+k/cYKaz9QtoSxtn+A3nnU90ZCDIu4hhTectminM9oguVtiHvR7zMHyK ES0eAYfr9D2KVWibxSURjizScoGObDK7fk4AfACE2xNsW2svrgE+Dt+ZqjDfsJd8o87C UREVcm+L7BPnENGWmCE0VHVtjIX/WIKcyAVYfLudRUgwGV2UWCS9lyBUDShL71dni/eC 1FQ9xWaTWK5GFdoVzFvUvi3uMegwhuy/62fTBhOMssafJ+f3/i899JpDkC38Bo23mU0c i3IhQF0MAuxyHmsu66wUVMCk15vHsSzvAmvt7Xvc8WPcxtAhaHYWq41fsvFwB7ntaHBC S2UA== X-Received: by 10.50.78.138 with SMTP id b10mr50537igx.17.1405397496016; Mon, 14 Jul 2014 21:11:36 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.50.73.227 with SMTP id o3ls133776igv.27.gmail; Mon, 14 Jul 2014 21:11:35 -0700 (PDT) X-Received: by 10.66.65.109 with SMTP id w13mr10085309pas.21.1405397495096; Mon, 14 Jul 2014 21:11:35 -0700 (PDT) Received: from mail-ob0-x236.google.com (mail-ob0-x236.google.com [2607:f8b0:4003:c01::236]) by gmr-mx.google.com with ESMTPS id g19si369460igh.3.2014.07.14.21.11.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 14 Jul 2014 21:11:35 -0700 (PDT) Received-SPF: pass (google.com: domain of jftucker@gmail.com designates 2607:f8b0:4003:c01::236 as permitted sender) client-ip=2607:f8b0:4003:c01::236; Received: by mail-ob0-f182.google.com with SMTP id wm4so5204626obc.13 for ; Mon, 14 Jul 2014 21:11:34 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.60.132.44 with SMTP id or12mr22362818oeb.60.1405397494769; Mon, 14 Jul 2014 21:11:34 -0700 (PDT) Received: by 10.76.71.197 with HTTP; Mon, 14 Jul 2014 21:11:34 -0700 (PDT) In-Reply-To: <20131112210724.GA25638@dcvr.yhbt.net> References: <20131112210724.GA25638@dcvr.yhbt.net> Date: Mon, 14 Jul 2014 21:11:34 -0700 Message-ID: Subject: Re: [PATCH] chunked: do not chunk on pre-HTTP/1.0 clients From: James Tucker To: rack-devel@googlegroups.com X-Original-Sender: jftucker@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of jftucker@gmail.com designates 2607:f8b0:4003:c01::236 as permitted sender) smtp.mail=jftucker@gmail.com; dkim=pass header.i=@gmail.com; dmarc=pass (p=NONE dis=NONE) header.from=gmail.com Reply-To: rack-devel@googlegroups.com Precedence: list Mailing-list: list rack-devel@googlegroups.com; contact rack-devel+owners@googlegroups.com List-ID: X-Google-Group-Id: 486215384060 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Content-Type: multipart/alternative; boundary=047d7b4726c871ad2204fe339ab4 --047d7b4726c871ad2204fe339ab4 Content-Type: text/plain; charset=UTF-8 Thanks! On Tue, Nov 12, 2013 at 1:07 PM, Eric Wong 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. --047d7b4726c871ad2204fe339ab4 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks!


On Tue, Nov 12, 2013 at 1:07 PM, Eric Wong <normalper= son@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
---
=C2=A0 The following changes since commit df1506b0825a096514fcb3821563bf9e8= fd52743:

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

=C2=A0 are available in the git repository at:

=C2=A0 =C2=A0 git://bogomips.org/rack.git ancient-chunked

=C2=A0 for you to fetch changes up to fd3b5312625f06baeda726ef4b32e7a3ac336= 698:

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

=C2=A0lib/rack/chunked.rb =C2=A0| 13 ++++++++++++-
=C2=A0test/spec_chunked.rb | 16 ++++++++++++++++
=C2=A02 files changed, 28 insertions(+), 1 deletion(-)

=C2=A0Yes, 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
=C2=A0 =C2=A0 =C2=A0 =C2=A0@app =3D app
=C2=A0 =C2=A0 =C2=A0end

+ =C2=A0 =C2=A0# pre-HTTP/1.0 (informally "HTTP/0.9") HTTP reques= ts did not have
+ =C2=A0 =C2=A0# a version (nor response headers)
+ =C2=A0 =C2=A0def chunkable_version?(ver)
+ =C2=A0 =C2=A0 =C2=A0case ver
+ =C2=A0 =C2=A0 =C2=A0when "HTTP/1.0", nil, "HTTP/0.9"<= br> + =C2=A0 =C2=A0 =C2=A0 =C2=A0false
+ =C2=A0 =C2=A0 =C2=A0else
+ =C2=A0 =C2=A0 =C2=A0 =C2=A0true
+ =C2=A0 =C2=A0 =C2=A0end
+ =C2=A0 =C2=A0end
+
=C2=A0 =C2=A0 =C2=A0def call(env)
=C2=A0 =C2=A0 =C2=A0 =C2=A0status, headers, body =3D @app.call(env)
=C2=A0 =C2=A0 =C2=A0 =C2=A0headers =3D HeaderHash.new(headers)

- =C2=A0 =C2=A0 =C2=A0if env['HTTP_VERSION'] =3D=3D 'HTTP/1.0&#= 39; ||
+ =C2=A0 =C2=A0 =C2=A0if ! chunkable_version?(env['HTTP_VERSION']) = ||
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 STATUS_WITH_NO_ENTITY_BODY.include?(stat= us) ||
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 headers['Content-Length'] ||
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 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
=C2=A0 =C2=A0 =C2=A0body.join.should.equal 'Hello World!'
=C2=A0 =C2=A0end

+ =C2=A0should 'not modify response when client is ancient, pre-HTTP/1.= 0' do
+ =C2=A0 =C2=A0app =3D lambda { |env| [200, {"Content-Type" =3D&g= t; "text/plain"}, ['Hello', ' ', 'World!'= ]] }
+ =C2=A0 =C2=A0check =3D lambda do
+ =C2=A0 =C2=A0 =C2=A0status, headers, body =3D chunked(app).call(@env.dup)=
+ =C2=A0 =C2=A0 =C2=A0status.should.equal 200
+ =C2=A0 =C2=A0 =C2=A0headers.should.not.include 'Transfer-Encoding'= ;
+ =C2=A0 =C2=A0 =C2=A0body.join.should.equal 'Hello World!'
+ =C2=A0 =C2=A0end
+
+ =C2=A0 =C2=A0@env.delete('HTTP_VERSION') # unicorn will do this o= n pre-HTTP/1.0 requests
+ =C2=A0 =C2=A0check.call
+
+ =C2=A0 =C2=A0@env['HTTP_VERSION'] =3D 'HTTP/0.9' # not su= re if this happens in practice
+ =C2=A0 =C2=A0check.call
+ =C2=A0end
+
=C2=A0 =C2=A0should 'not modify response when Transfer-Encoding header = already present' do
=C2=A0 =C2=A0 =C2=A0app =3D lambda { |env|
=C2=A0 =C2=A0 =C2=A0 =C2=A0[200, {"Content-Type" =3D> "te= xt/plain", 'Transfer-Encoding' =3D> 'identity'}, [&= #39;Hello', ' ', 'World!']]
--
EW

--

---
You received this message because you are subscribed to the Google Groups &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-d= evel+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 &= quot;Rack Development" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to rack-dev= el+unsubscribe@googlegroups.com.
For more options, visit http= s://groups.google.com/d/optout.
--047d7b4726c871ad2204fe339ab4--