I am developing a Sinatra web app and there I want to canonicalize and absolutize a number of URLs. For this, I am using a Rack::Request object:
before do
@cached_request = Rack::Request.new(env)
end
def absolutize(path)
u = URI.parse('/%s' % path) # Ensure leading slash is there
u.scheme = @cached_request.scheme
u.host = @cached_request.host
u.port = @cached_request.port
u.to_s
end
However, even when my app is running on port 9393 the SERVER_PORT variable has 80. I've examined the env object for relevant info but it seems that it hasn't got any information on the request port.
How am I supposed to figure this one out from within the application? I don't see references to the variable in the rack spec...
So far I've tried running the rackup file on Puma and Webrick.
requesthelper from within Sinatra e.g callingrequest.port? See sinatrarb.com/intro#Accessing%20the%20Request%20Object - iain