Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of github.com:rubiii/httpi

  • Loading branch information...
commit acc8a915b6e38d641ac35ea530485628d3ecb117 2 parents 4818c0c + e4e8520
@rubiii rubiii authored
View
4 Gemfile
@@ -1,2 +1,6 @@
source :rubygems
gemspec
+
+group :test do
+ gem "mock-server", :git => "git://github.com/ichverstehe/mock-server.git", :branch => "custom-class"
+end
View
2  httpi.gemspec
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "httpclient", "~> 2.1.5"
s.add_development_dependency "curb", "~> 0.7.8"
- s.add_development_dependency "rspec", "2.0.0"
+ s.add_development_dependency "rspec", "~> 2.2"
s.add_development_dependency "mocha", "~> 0.9.9"
s.add_development_dependency "webmock", "~> 1.4.0"
View
2  lib/httpi/adapter/curb.rb
@@ -68,7 +68,7 @@ def basic_setup(request)
client.proxy_url = request.proxy.to_s if request.proxy
client.timeout = request.read_timeout if request.read_timeout
client.connect_timeout = request.open_timeout if request.open_timeout
- client.headers = request.headers
+ client.headers = request.headers.to_hash
client.verbose = false
end
View
38 spec/integration/request_spec.rb
@@ -1,51 +1,57 @@
require "spec_helper"
require "httpi"
+require "integration/server"
+
+MockServer.new(IntegrationServer, 4000).start
describe HTTPI do
let(:client) { HTTPI }
- # Uses example.com for basic request methods and webdav.org
- # for HTTP basic and digest authentication.
- #
- # http://example.com
- # http://test.webdav.org
-
before :all do
WebMock.allow_net_connect!
- @username = @password = "user1"
+ @username = "admin"
+ @password = "pwd"
@error_message = "Authorization Required"
- @example_web_page = "Example Web Page"
- @content_type = "text/html"
+ @example_web_page = "Hello"
+ @content_type = "text/plain"
end
shared_examples_for "an HTTP client" do
+ it "and send HTTP headers" do
+ request = HTTPI::Request.new :url => "http://localhost:4000/x-header"
+ request.headers["X-Header"] = "HTTPI"
+
+ response = HTTPI.get request, adapter
+ response.body.should include("X-Header is HTTPI")
+ end
+
it "and execute an HTTP GET request" do
- response = HTTPI.get "http://example.com", adapter
+ response = HTTPI.get "http://localhost:4000", adapter
response.body.should include(@example_web_page)
response.headers["Content-Type"].should include(@content_type)
end
it "and execute an HTTP POST request" do
- response = HTTPI.post "http://example.com", "<some>xml</some>", adapter
+ response = HTTPI.post "http://localhost:4000", "<some>xml</some>", adapter
response.body.should include(@example_web_page)
response.headers["Content-Type"].should include(@content_type)
end
it "and execute an HTTP HEAD request" do
- response = HTTPI.head "http://example.com", adapter
+ response = HTTPI.head "http://localhost:4000", adapter
response.code.should == 200
response.headers["Content-Type"].should include(@content_type)
end
it "and execute an HTTP PUT request" do
- response = HTTPI.put "http://example.com", "<some>xml</some>", adapter
+ response = HTTPI.put "http://localhost:4000", "<some>xml</some>", adapter
response.body.should include("PUT is not allowed")
response.headers["Content-Type"].should include(@content_type)
end
it "and execute an HTTP DELETE request" do
- response = HTTPI.delete "http://example.com", adapter
+ response = HTTPI.delete "http://localhost:4000", adapter
response.body.should include("DELETE is not allowed")
response.headers["Content-Type"].should include(@content_type)
end
@@ -53,7 +59,7 @@
shared_examples_for "it works with HTTP basic auth" do
it "and access a secured page" do
- request = HTTPI::Request.new :url => "http://test.webdav.org/auth-basic/"
+ request = HTTPI::Request.new :url => "http://localhost:4000/auth/basic"
request.auth.basic @username, @password
response = HTTPI.get request, adapter
@@ -63,7 +69,7 @@
shared_examples_for "it works with HTTP digest auth" do
it "and access a secured page" do
- request = HTTPI::Request.new :url => "http://test.webdav.org/auth-digest/"
+ request = HTTPI::Request.new :url => "http://localhost:4000/auth/digest"
request.auth.digest @username, @password
response = HTTPI.get request, adapter
View
39 spec/integration/server.rb
@@ -0,0 +1,39 @@
+require "spec_helper"
+require "mock_server"
+
+IntegrationServer = Rack::Builder.new do
+ map "/" do
+ run lambda {|env|
+ case env["REQUEST_METHOD"]
+ when "HEAD" then
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, []]
+ when "GET", "POST" then
+ [200, {"Content-Type" => "text/plain", "Content-Length" => "5"}, ["Hello"]]
+ when "PUT", "DELETE"
+ body = "#{env["REQUEST_METHOD"]} is not allowed"
+ [200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
+ end
+ }
+ end
+
+ map "/x-header" do
+ run lambda {|env|
+ body = "X-Header is #{env["HTTP_X_HEADER"]}"
+ [200, {"Content-Type" => "text/plain", "Content-Length" => body.size.to_s}, [body]]
+ }
+ end
+
+ map "/auth" do
+ map "/basic" do
+ run Rack::Auth::Basic do |user, password|
+ user == "admin" && password == "secret"
+ end
+ end
+
+ map "/digest" do
+ run Rack::Auth::Digest::MD5 do |username|
+ {"admin" => "pwd"}[username]
+ end
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.