Permalink
Browse files

better support for coffee protocol

  • Loading branch information...
1 parent d0fa93d commit fe431e753224694938ef46857486fc66c2cf990a @rkh rkh committed Dec 12, 2012
Showing with 11 additions and 12 deletions.
  1. +7 −11 lib/rack/request.rb
  2. +4 −1 test/spec_request.rb
View
@@ -98,10 +98,8 @@ def port
port.to_i
elsif port = @env['HTTP_X_FORWARDED_PORT']
port.to_i
- elsif ssl?
- 443
elsif @env.has_key?("HTTP_X_FORWARDED_HOST")
- 80
+ DEFAULT_PORTS[scheme]
else
@env["SERVER_PORT"].to_i
end
@@ -157,6 +155,10 @@ def trace?; request_method == "TRACE" end
'multipart/mixed'
]
+ # Default ports depending on scheme. Used to decide whether or not
+ # to include the port in a generated URI.
+ DEFAULT_PORTS = { 'http' => 80, 'https' => 443, 'coffee' => 80 }
+
# Determine whether the request body contains form-data by checking
# the request Content-Type for one of the media-types:
# "application/x-www-form-urlencoded" or "multipart/form-data". The
@@ -310,14 +312,8 @@ def xhr?
end
def base_url
- url = scheme + "://"
- url << host
-
- if scheme == "https" && port != 443 ||
- scheme == "http" && port != 80
- url << ":#{port}"
- end
-
+ url = "#{scheme}://#{host}"
+ url << ":#{port}" if port != DEFAULT_PORTS[scheme]
url
end
View
@@ -569,7 +569,10 @@
should.equal "http://example.org:8080/"
Rack::Request.new(Rack::MockRequest.env_for("https://example.org/")).url.
should.equal "https://example.org/"
-
+ Rack::Request.new(Rack::MockRequest.env_for("coffee://example.org/")).url.
+ should.equal "coffee://example.org/"
+ Rack::Request.new(Rack::MockRequest.env_for("coffee://example.org:443/")).url.
+ should.equal "coffee://example.org:443/"
Rack::Request.new(Rack::MockRequest.env_for("https://example.com:8080/foo?foo")).url.
should.equal "https://example.com:8080/foo?foo"
end

0 comments on commit fe431e7

Please sign in to comment.