[PATCH] tests: add full URL example
- From:
- Eric Wong
- Date:
- 2011-05-12 @ 02:24
In case anyone is interested in getting the full URL with hostname,
here's how I did it:
From 5979a9b113815721140058d021ecfffc5c529de4 Mon Sep 17 00:00:00 2001
From: Eric Wong <normalperson@yhbt.net>
Date: Wed, 11 May 2011 18:54:47 -0700
Subject: [PATCH] tests: add full URL example
Could be useful for some folks.
---
test/test_clogger.rb | 13 +++++++++++++
1 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/test/test_clogger.rb b/test/test_clogger.rb
index 9440d74..35a211a 100644
--- a/test/test_clogger.rb
+++ b/test/test_clogger.rb
@@ -28,6 +28,7 @@ class TestClogger < Test::Unit::TestCase
"QUERY_STRING" => "goodbye=true",
"rack.errors" => $stderr,
"rack.input" => File.open('/dev/null', 'rb'),
+ "rack.url_scheme" => "http",
"REMOTE_ADDR" => 'home',
}
end
@@ -795,4 +796,16 @@ class TestClogger < Test::Unit::TestCase
assert_equal :PONIES, s[1]
assert_equal 2, s.size
end
+
+ def test_full_uri
+ s = []
+ format = '"$request_method ' \
+ '$env{rack.url_scheme}://$http_host$request_uri $http_version"'
+ app = lambda { |env| [200, [], [] ] }
+ cl = Clogger.new(app, :logger => s, :format => format)
+ @req["HTTP_HOST"] = "example.com"
+ status, headers, body = cl.call(@req)
+ expect = "\"GET http://example.com/hello?goodbye=true HTTP/1.0\"\n"
+ assert_equal [ expect ], s
+ end
end
--
Eric Wong