1
votes

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.

1
have you tried the request helper from within Sinatra e.g calling request.port ? See sinatrarb.com/intro#Accessing%20the%20Request%20Object - iain

1 Answers

1
votes

Ok I figured it out. This only happens with requests done through MarsEdit, due to the fact that MarsEdit does not send a port suffix in the Host header (which is what pretty much all Rack servers use to infer the server port).

I've contacted Daniel with a bugreport.