Created
March 4, 2018 03:59
-
-
Save romaimperator/137f0b53362e18852644eff98f7e776b to your computer and use it in GitHub Desktop.
Middleware to support prefixed value in the url
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 MyMiddleware | |
def initialize(app) | |
@app = app | |
@message = message | |
end | |
def call(env) | |
dup._call(env) | |
end | |
def _call(env) | |
_, script_name, request_path = env['REQUEST_PATH'].split('/', 3) | |
env['SCRIPT_NAME'] = '/' + script_name | |
env['PATH_INFO'] = '/' + request_path | |
env['REQUEST_PATH'] = '/' + request_path | |
env['REQUEST_URI'] = '/' + request_path | |
@status, @headers, @response = @app.call(env) | |
[@status, @headers, self] | |
end | |
def each(&block) | |
@response.each(&block) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment