Skip to content

Commit

Permalink
Fix request headline.
Browse files Browse the repository at this point in the history
Resolves #206
  • Loading branch information
ixti committed Apr 7, 2015
1 parent 5b81f62 commit bc9dd60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/http/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class UnsupportedSchemeError < RequestError; end
# :nodoc:
def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
@verb = verb.to_s.downcase.to_sym
@uri = HTTP::URI.parse uri
@uri = HTTP::URI.parse(uri).normalize
@scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym

fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
Expand Down Expand Up @@ -121,7 +121,8 @@ def connect_using_proxy(socket)

# Compute HTTP request header for direct or proxy request
def request_header
"#{verb.to_s.upcase} #{uri.normalize} HTTP/#{version}"
request_uri = using_proxy? ? uri : uri.omit(:scheme, :authority)
"#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
end

# Compute HTTP request header SSL proxy connection
Expand Down
16 changes: 14 additions & 2 deletions spec/lib/http/request_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
RSpec.describe HTTP::Request do
let(:proxy) { {} }
let(:headers) { {:accept => "text/html"} }
let(:request_uri) { "http://example.com/" }
let(:request_uri) { "http://example.com/foo?bar=baz#moo" }

subject(:request) { HTTP::Request.new(:get, request_uri, headers) }
subject(:request) { HTTP::Request.new(:get, request_uri, headers, proxy) }

it "includes HTTP::Headers::Mixin" do
expect(described_class).to include HTTP::Headers::Mixin
Expand Down Expand Up @@ -136,4 +137,15 @@
subject { request.caching }
it { is_expected.to be_a HTTP::Request::Caching }
end

describe "#request_header" do
subject { request.request_header }

it { is_expected.to eq "GET /foo?bar=baz#moo HTTP/1.1" }

context "with proxy" do
let(:proxy) { {:user => "user", :pass => "pass"} }
it { is_expected.to eq "GET http://example.com/foo?bar=baz#moo HTTP/1.1" }
end
end
end

0 comments on commit bc9dd60

Please sign in to comment.