Last active
August 27, 2019 06:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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