Skip to content

Commit

Permalink
Automatically set the Host header from the URI
Browse files Browse the repository at this point in the history
Closes #32.
  • Loading branch information
sferik committed Sep 9, 2013
1 parent 0bf78f9 commit 1a16779
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/http/request.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(method, uri, headers = {}, proxy = {}, body = nil, version = "1.1
key ||= Http.canonicalize_header(name)
@headers[key] = value
end
@headers["Host"] ||= @uri.host

@proxy, @body, @version = proxy, body, version
end
Expand Down
19 changes: 19 additions & 0 deletions spec/http/request_spec.rb
@@ -0,0 +1,19 @@
require 'spec_helper'

describe Http::Request do
describe "headers" do
subject { Http::Request.new(:get, "http://example.com/", :accept => "text/html") }

it "sets explicit headers" do
subject["Accept"].should eq("text/html")
end

it "sets implicit headers" do
subject["Host"].should eq("example.com")
end

it "provides a #headers accessor" do
subject.headers.should eq("Accept" => "text/html", "Host" => "example.com")
end
end
end

0 comments on commit 1a16779

Please sign in to comment.