Skip to content

Commit 1ba2367

Browse files
committed
allow base_uri to be specified when creating request
1 parent c288d08 commit 1ba2367

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/webmachine/request.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class Request
2020
# @param [Headers] headers the HTTP request headers
2121
# @param [String,#to_s,#each,nil] body the entity included in the
2222
# request, if present
23-
def initialize(method, uri, headers, body, routing_tokens=nil)
24-
@method, @headers, @body = method, headers, body
23+
def initialize(method, uri, headers, body, routing_tokens=nil, base_uri=nil)
24+
@method, @headers, @body, @base_uri = method, headers, body, base_uri
2525
@uri = build_uri(uri, headers)
2626
@routing_tokens = routing_tokens || @uri.path.match(ROUTING_PATH_MATCH)[1].split(SLASH)
2727
end

spec/webmachine/request_spec.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
let(:headers) { Webmachine::Headers.new }
99
let(:body) { "" }
1010
let(:routing_tokens) { nil }
11-
let(:request) { Webmachine::Request.new(http_method, uri, headers, body, routing_tokens) }
11+
let(:base_uri) { nil }
12+
let(:request) { Webmachine::Request.new(http_method, uri, headers, body, routing_tokens, base_uri) }
1213

1314
it "should provide access to the headers via brackets" do
1415
subject.headers['Accept'] = "*/*"
@@ -31,8 +32,17 @@
3132
expect(subject.content_md5).to be_nil
3233
end
3334

34-
it "should calculate a base URI" do
35-
expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/"))
35+
context "base_uri" do
36+
it "should calculate a base URI" do
37+
expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/"))
38+
end
39+
40+
context "when base_uri has been explicitly set" do
41+
let(:base_uri) { URI.parse("http://localhost:8080/some_base_uri/here") }
42+
it "should use the provided base_uri" do
43+
expect(subject.base_uri).to eq(URI.parse("http://localhost:8080/some_base_uri/here"))
44+
end
45+
end
3646
end
3747

3848
it "should provide a hash of query parameters" do

0 commit comments

Comments
 (0)