rack-devel archive mirror (unofficial) https://groups.google.com/group/rack-devel
 help / color / mirror / Atom feed
From: Gaius <james.a.rosen@gmail.com>
To: Rack Development <rack-devel@googlegroups.com>
Subject: Re: Bug in Rack::JSONP?
Date: Tue, 22 Jun 2010 05:58:41 -0700 (PDT)	[thread overview]
Message-ID: <44413025-01d6-44f5-b552-ceda9ada6a84@j8g2000yqd.googlegroups.com> (raw)
In-Reply-To: <AANLkTilaQRBa7fOCrMMmKdisoEgHhGmXw29aBMXrGOxF@mail.gmail.com>

+1, Magnus

On Jun 22, 8:32 am, Magnus Holm <judo...@gmail.com> wrote:
> What about something like this:
>
> 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
>      #
>      def call(env)
>        status, headers, response = @app.call(env)
> +
> +      if STATUS_WITH_NO_ENTITY_BODY.include?(status)
> +        return status, headers, response
> +      end
>
>        headers = HeaderHash.new(headers)
>        request = 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
>      body = Rack::JSONP.new(app).call(request).last
>      body.should.equal [test_body]
>    end
> -
> +
> +  specify "should not change anything if the request doesn't have a body" do
> +    app1 = lambda { |env| [100, {}, []] }
> +    app2 = lambda { |env| [204, {}, []] }
> +    app3 = lambda { |env| [304, {}, []] }
> +    request = Rack::MockRequest.env_for("/", :params =>
> "callback=foo", 'HTTP_ACCEPT' => 'application/json')
> +
> +    Rack::JSONP.new(app1).call(request).should.equal app1.call({})
> +    Rack::JSONP.new(app2).call(request).should.equal app2.call({})
> +    Rack::JSONP.new(app3).call(request).should.equal app3.call({})
> +  end
>  end
> \ No newline at end of file
>
> // Magnus Holm
>
>
>
> On Tue, Jun 22, 2010 at 14:22, Magnus Holm <judo...@gmail.com> 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øy <aslak.helle...@gmail.com> 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
> >>        /Users/aslakhellesoy/.rvm/gems/ruby-1.8.7-p249@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

  reply	other threads:[~2010-06-22 12:58 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-06-22 12:08 Bug in Rack::JSONP? Aslak Hellesøy
2010-06-22 12:22 ` Magnus Holm
2010-06-22 12:32   ` Magnus Holm
2010-06-22 12:58     ` Gaius [this message]
2010-06-22 15:30     ` aslak hellesoy
2010-06-22 15:48       ` Matt Todd
2010-06-22 17:21       ` Magnus Holm
2010-06-22 17:28         ` aslak hellesoy
2010-06-22 21:18           ` Magnus Holm
2010-06-22 19:49       ` Magnus Holm

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://groups.google.com/group/rack-devel

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44413025-01d6-44f5-b552-ceda9ada6a84@j8g2000yqd.googlegroups.com \
    --to=rack-devel@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).