From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.239.138.72 with SMTP id o8cs39141hbo; Tue, 22 Jun 2010 12:49:31 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncCL6b8N6VCBDKp4ThBBoEV9y2HA@googlegroups.com designates 10.223.4.202 as permitted sender) client-ip=10.223.4.202; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncCL6b8N6VCBDKp4ThBBoEV9y2HA@googlegroups.com designates 10.223.4.202 as permitted sender) smtp.mail=rack-devel+bncCL6b8N6VCBDKp4ThBBoEV9y2HA@googlegroups.com; dkim=pass header.i=rack-devel+bncCL6b8N6VCBDKp4ThBBoEV9y2HA@googlegroups.com Received: from mr.google.com ([10.223.4.202]) by 10.223.4.202 with SMTP id 10mr685911fas.47.1277236171731 (num_hops = 1); Tue, 22 Jun 2010 12:49:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=domainkey-signature:received:x-beenthere:received:received:received :received:received-spf:received:mime-version:received:received :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 :content-transfer-encoding; bh=XJvgR7vOTewm9L5dZ3G+4dbhDgMxCidctqnJbQfJZko=; b=NllMYLL6KHUcq9z4TTYt17ihQ9EcsXBGiE54HQILefYnfcfZExYCf1ofyDOrMUvrP9 Clq3iplnDa1QYhPzvrfsCBqsSBQmB3B6kq9G1w7K9oaqMaVTFNOrEILabrn1E/3C/j12 tuob+C89A0KMyv8WhCZ5ghePTRwqMsw3/MCpU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf: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:content-transfer-encoding; b=6bZmqxelQbt0oLt07mE6Fw5fVLfhqc5ZZlGF+cTWiepPz1GV5K8he6AiYKLld3Ixl3 Iq3TVyKlv9cKmJW7IoGchHNZ2i8KfTgx7N4qt1z5T0xWk6KY4D8owi9YRd8Z3kVZCUor 3eLFAOW3XAxKoN+R5i70JMxiR3m47cz5wuqEw= Received: by 10.223.4.202 with SMTP id 10mr116095fas.47.1277236170498; Tue, 22 Jun 2010 12:49:30 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.223.66.18 with SMTP id l18ls2150807fai.1.p; Tue, 22 Jun 2010 12:49:29 -0700 (PDT) Received: by 10.223.26.72 with SMTP id d8mr410500fac.27.1277236169071; Tue, 22 Jun 2010 12:49:29 -0700 (PDT) Received: by 10.223.26.72 with SMTP id d8mr410499fac.27.1277236169039; Tue, 22 Jun 2010 12:49:29 -0700 (PDT) Received: from mail-fx0-f50.google.com (mail-fx0-f50.google.com [209.85.161.50]) by gmr-mx.google.com with ESMTP id x13si5352442fah.3.2010.06.22.12.49.28; Tue, 22 Jun 2010 12:49:28 -0700 (PDT) Received-SPF: pass (google.com: domain of judofyr@gmail.com designates 209.85.161.50 as permitted sender) client-ip=209.85.161.50; Received: by mail-fx0-f50.google.com with SMTP id 6so1273527fxm.37 for ; Tue, 22 Jun 2010 12:49:28 -0700 (PDT) MIME-Version: 1.0 Received: by 10.103.50.13 with SMTP id c13mr2237171muk.63.1277236167820; Tue, 22 Jun 2010 12:49:27 -0700 (PDT) Received: by 10.102.220.15 with HTTP; Tue, 22 Jun 2010 12:49:27 -0700 (PDT) In-Reply-To: References: <476e2835-02b3-4ebf-b798-ed502a804fed@x27g2000yqb.googlegroups.com> Date: Tue, 22 Jun 2010 21:49:27 +0200 Message-ID: Subject: Re: Bug in Rack::JSONP? From: Magnus Holm To: "rack-devel@googlegroups.com" X-Original-Sender: judofyr@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of judofyr@gmail.com designates 209.85.161.50 as permitted sender) smtp.mail=judofyr@gmail.com; dkim=pass (test mode) header.i=@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: List-Post: , List-Help: , List-Archive: Sender: rack-devel@googlegroups.com List-Subscribe: , List-Unsubscribe: , Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable I simply don't really see the value of a fork instead of a simple patchfile. 6 months from now nearly all forks are gone - this piece of text lives on forever in all clients and archives. On Tuesday, June 22, 2010, aslak hellesoy wrote: > On Tue, Jun 22, 2010 at 2:32 PM, Magnus Holm wrote: >> What about something like this: >> > > Thanks a ton Magnus - this works great for me. > I see you haven't pushed anything, so I have pushed this to my own > fork in case someone wants to merge it in. I hope so, it's obviously a > bug (and a bugfix). > > http://github.com/aslakhellesoy/rack-contrib/commit/952cb23311c69fcad16e5= dfade746a3884b22b9e > > Aslak > >> diff --git a/lib/rack/contrib/jsonp.rb b/lib/rack/contrib/jsonp.rb >> index 723d63a..7eefe00 100644 >> --- a/lib/rack/contrib/jsonp.rb >> +++ b/lib/rack/contrib/jsonp.rb >> @@ -19,6 +19,10 @@ module Rack >> =C2=A0 =C2=A0 # >> =C2=A0 =C2=A0 def call(env) >> =C2=A0 =C2=A0 =C2=A0 status, headers, response =3D @app.call(env) >> + >> + =C2=A0 =C2=A0 =C2=A0if STATUS_WITH_NO_ENTITY_BODY.include?(status) >> + =C2=A0 =C2=A0 =C2=A0 =C2=A0return status, headers, response >> + =C2=A0 =C2=A0 =C2=A0end >> >> =C2=A0 =C2=A0 =C2=A0 headers =3D HeaderHash.new(headers) >> =C2=A0 =C2=A0 =C2=A0 request =3D Rack::Request.new(env) >> diff --git a/test/spec_rack_jsonp.rb b/test/spec_rack_jsonp.rb >> index eb6570f..c1abc59 100644 >> --- a/test/spec_rack_jsonp.rb >> +++ b/test/spec_rack_jsonp.rb >> @@ -69,5 +69,15 @@ context "Rack::JSONP" do >> =C2=A0 =C2=A0 body =3D Rack::JSONP.new(app).call(request).last >> =C2=A0 =C2=A0 body.should.equal [test_body] >> =C2=A0 end >> - >> + >> + =C2=A0specify "should not change anything if the request doesn't have = a body" do >> + =C2=A0 =C2=A0app1 =3D lambda { |env| [100, {}, []] } >> + =C2=A0 =C2=A0app2 =3D lambda { |env| [204, {}, []] } >> + =C2=A0 =C2=A0app3 =3D lambda { |env| [304, {}, []] } >> + =C2=A0 =C2=A0request =3D Rack::MockRequest.env_for("/", :params =3D> >> "callback=3Dfoo", 'HTTP_ACCEPT' =3D> 'application/json') >> + >> + =C2=A0 =C2=A0Rack::JSONP.new(app1).call(request).should.equal app1.cal= l({}) >> + =C2=A0 =C2=A0Rack::JSONP.new(app2).call(request).should.equal app2.cal= l({}) >> + =C2=A0 =C2=A0Rack::JSONP.new(app3).call(request).should.equal app3.cal= l({}) >> + =C2=A0end >> =C2=A0end >> \ No newline at end of file >> >> >> // Magnus Holm >> >> >> >> On Tue, Jun 22, 2010 at 14:22, Magnus Holm wrote: >>> From the spec: "There must be a Content-Type, except when the Status >>> is 1xx, 204 or 304, in which case there must be none given." >>> >>> I guess we should rather make JSONP a noop when the status is 1xx, 204 = or 304. >>> >>> // Magnus Holm >>> >>> >>> On Tue, Jun 22, 2010 at 14:08, Aslak Helles=C3=B8y wrote: >>>> Hi all, >>>> >>>> I'm using Rack::JSONP from rack-contrib in a Sinatra project. When I >>>> issue a GET request that's not JSON (and that doesn't set a Content- >>>> Type header, I get: >>>> >>>> NoMethodError: undefined method `include?' for nil:NilClass >>>> =C2=A0 =C2=A0 =C2=A0 =C2=A0/Users/aslakhellesoy/.rvm/gems/ruby-1.8.7-p= 249@cukepatch/gems/rack- >>>> contrib-1.0.1/lib/rack/contrib/jsonp.rb:44:in `is_json?' >>>> >>>> Am I the only one running into this? Should I patch with: >>>> >>>> (headers['Content-Type'] || []).include?('application/json') in rack- >>>> contrib-1.0.1/lib/rack/contrib/jsonp.rb:44 >>>> >>>> Or is it better to patch rack to return an empty array instead of nil >>>> in #headers. >>>> >>>> I'm on rack 1.2.1 and Sinatra 1.0. >>>> >>>> Cheers, >>>> Aslak >>> >> > --=20 // Magnus Holm