Skip to content

Instantly share code, notes, and snippets.

@namiwang
Last active August 27, 2019 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save namiwang/2e4406030b056210d0d91dc2cdc9b494 to your computer and use it in GitHub Desktop.
Save namiwang/2e4406030b056210d0d91dc2cdc9b494 to your computer and use it in GitHub Desktop.
middleware to simulate PATCH method with a POST when client doesn't support it
class PatchSimulatingMiddleware
def initialize app
@app = app
end
def call env
request = Rack::Request.new(env)
if request.post? && ( request.params['_name'] == 'patch' )
request.set_header 'REQUEST_METHOD', 'PATCH'
end
@app.call env
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment