Sha256: 24f7fce868480af3f3461bebcb00d3ff2a7e0c87c12a073415cc9355c4ca2f08

Contents?: true

Size: 794 Bytes

Versions: 2

Compression:

Stored size: 794 Bytes

Contents

module Remotipart

  # A middleware to look for our form parameters and 
  # encourage Rails to respond with the requested format
  class Middleware
    def initialize app
      @app = app
    end

    def call env
      # Get request params
      params = Rack::Request.new(env).params

      if params
        # This was using an iframe transport, and is therefore an XHR
        # This is required if we're going to override the http_accept
        if params['X-Requested-With'] == 'IFrame'
          env['HTTP_X_REQUESTED_WITH'] = 'xmlhttprequest'
        end

        # Override the accepted format, because it isn't what we really want
        if params['X-Http-Accept']
          env['HTTP_ACCEPT'] = params['X-Http-Accept']
        end
      end

      @app.call(env)
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/remotipart-1.2.1/lib/remotipart/middleware.rb
remotipart-1.2.1 lib/remotipart/middleware.rb