Skip to content

Instantly share code, notes, and snippets.

@armstrjare
Created March 26, 2012 21:09
Show Gist options
  • Save armstrjare/2209743 to your computer and use it in GitHub Desktop.
Save armstrjare/2209743 to your computer and use it in GitHub Desktop.
# from koz, tweaked
class FixAcceptsBehaviourMiddleware
def initialize(app, formats, logger = Rails.logger)
@app = app
@formats = formats
@logger = logger
end
def call(env)
current_accept_header = env["HTTP_ACCEPT"].to_s.split(",")
if (@formats & current_accept_header).empty? && !env["HTTP_X_REQUESTED_WITH"]
@logger.warn("Rewriting accepts header from '#{env["HTTP_ACCEPT"]}' to 'text/html'.") if @logger
env["HTTP_ACCEPT"] = "text/html"
end
@app.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment