From mboxrd@z Thu Jan 1 00:00:00 1970 Delivered-To: chneukirchen@gmail.com Received: by 10.239.138.72 with SMTP id o8cs29306hbo; Tue, 22 Jun 2010 08:30:26 -0700 (PDT) Return-Path: Received-SPF: pass (google.com: domain of rack-devel+bncCMqp3omTDRCRroPhBBoEDTeuqQ@googlegroups.com designates 10.216.236.139 as permitted sender) client-ip=10.216.236.139; Authentication-Results: mr.google.com; spf=pass (google.com: domain of rack-devel+bncCMqp3omTDRCRroPhBBoEDTeuqQ@googlegroups.com designates 10.216.236.139 as permitted sender) smtp.mail=rack-devel+bncCMqp3omTDRCRroPhBBoEDTeuqQ@googlegroups.com; dkim=pass header.i=rack-devel+bncCMqp3omTDRCRroPhBBoEDTeuqQ@googlegroups.com Received: from mr.google.com ([10.216.236.139]) by 10.216.236.139 with SMTP id w11mr2355310weq.10.1277220626574 (num_hops = 1); Tue, 22 Jun 2010 08:30:26 -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:received:mime-version:received :in-reply-to:references:from:date:message-id:subject: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=hdKSIVm7bVw1rFSzadkiXLtf2bepyupz8CvMVUA0soA=; b=MMffZ4ne+JtNDHJhqdYU3UBZJy80ZiBHvb2oVYY8kWREsjLXe4jmN3P4tNCAqHqXPC 7DlZJNA9CbY78s6bZCGGswbUeyT+vUFu3dQBuUczFyfIntLpv67vdwt1DB/bW3vE+ugo ZmKeGNtVhaNL8mG3uFoxbmFCmGP/p/175pJTA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:mime-version:in-reply-to:references:from :date:message-id:subject: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=FXB3S5SyTAJpDBbYHwDGx2vOeKZZ4XOHK+gRMfjkEl45c/d1utuv664IprrGwJUiqL tZwMPNlTch+HLXRz5OHnNkI6Sy74LXm717py9XXXxjr2OTrf4Mivh5zf89A5Op7dJckh Sat0idBkVZUeHiF0SUqJy0hZre98QMBkFuqN4= Received: by 10.216.236.139 with SMTP id w11mr487280weq.10.1277220625240; Tue, 22 Jun 2010 08:30:25 -0700 (PDT) X-BeenThere: rack-devel@googlegroups.com Received: by 10.227.87.4 with SMTP id u4ls3334177wbl.2.p; Tue, 22 Jun 2010 08:30:22 -0700 (PDT) Received: by 10.227.134.82 with SMTP id i18mr314437wbt.11.1277220622754; Tue, 22 Jun 2010 08:30:22 -0700 (PDT) Received: by 10.227.134.82 with SMTP id i18mr314436wbt.11.1277220622725; Tue, 22 Jun 2010 08:30:22 -0700 (PDT) Received: from mail-wy0-f181.google.com (mail-wy0-f181.google.com [74.125.82.181]) by gmr-mx.google.com with ESMTP id y32si16404weq.14.2010.06.22.08.30.21; Tue, 22 Jun 2010 08:30:21 -0700 (PDT) Received-SPF: pass (google.com: domain of aslak.hellesoy@gmail.com designates 74.125.82.181 as permitted sender) client-ip=74.125.82.181; Received: by mail-wy0-f181.google.com with SMTP id 35so3213694wyb.12 for ; Tue, 22 Jun 2010 08:30:21 -0700 (PDT) Received: by 10.216.168.81 with SMTP id j59mr4795633wel.61.1277220621355; Tue, 22 Jun 2010 08:30:21 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.167.206 with HTTP; Tue, 22 Jun 2010 08:30:01 -0700 (PDT) In-Reply-To: References: <476e2835-02b3-4ebf-b798-ed502a804fed@x27g2000yqb.googlegroups.com> From: aslak hellesoy Date: Tue, 22 Jun 2010 17:30:01 +0200 Message-ID: Subject: Re: Bug in Rack::JSONP? To: rack-devel@googlegroups.com X-Original-Sender: aslak.hellesoy@gmail.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of aslak.hellesoy@gmail.com designates 74.125.82.181 as permitted sender) smtp.mail=aslak.hellesoy@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 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/952cb23311c69fcad16e5df= ade746a3884b22b9e 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.call= ({}) > + =C2=A0 =C2=A0Rack::JSONP.new(app2).call(request).should.equal app2.call= ({}) > + =C2=A0 =C2=A0Rack::JSONP.new(app3).call(request).should.equal app3.call= ({}) > + =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 o= r 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-p2= 49@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 >> >