Sha256: b1814e599c2cb5df56394d76272cafba8d96f0f08edefa59a175fa368574e665

Contents?: true

Size: 853 Bytes

Versions: 40

Compression:

Stored size: 853 Bytes

Contents

module Unpoly
  module Rails
    ##
    # Installs a `before_action` into all controllers which echoes the
    # request's URL as a response header `X-Up-Location` and the request's
    # HTTP method as `X-Up-Method`.
    #
    # The Unpoly frontend requires these headers to detect redirects,
    # which are otherwise undetectable for an AJAX client.
    module RequestEchoHeaders

      def self.included(base)
        if base.respond_to?(:before_action)
          base.before_action :set_up_request_echo_headers
        else
          base.before_filter :set_up_request_echo_headers
        end
      end

      private
      
      def set_up_request_echo_headers
        headers['X-Up-Location'] = request.original_url
        headers['X-Up-Method'] = request.method
      end

      ActionController::Base.send(:include, self)

    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
unpoly-rails-0.55.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.55.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.54.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.54.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.53.4 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.53.3 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.53.2 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.53.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.53.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.52.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.51.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.51.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.50.2 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.50.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.50.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.37.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.36.2 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.36.1 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.36.0 lib/unpoly/rails/request_echo_headers.rb
unpoly-rails-0.35.2 lib/unpoly/rails/request_echo_headers.rb