http 0.4.0 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of http might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.travis.yml +8 -3
- data/CHANGES.md +8 -0
- data/Gemfile +6 -0
- data/Guardfile +9 -0
- data/README.md +47 -8
- data/examples/celluloid.rb +12 -0
- data/http.gemspec +0 -1
- data/lib/http.rb +0 -7
- data/lib/http/chainable.rb +3 -0
- data/lib/http/client.rb +20 -16
- data/lib/http/options.rb +28 -8
- data/lib/http/request.rb +23 -1
- data/lib/http/request_stream.rb +4 -0
- data/lib/http/response.rb +25 -0
- data/lib/http/response_parser.rb +4 -0
- data/lib/http/version.rb +1 -1
- data/spec/http/options/merge_spec.rb +9 -2
- data/spec/http/options_spec.rb +9 -15
- data/spec/http_spec.rb +11 -11
- data/spec/spec_helper.rb +2 -0
- data/spec/support/example_server.rb +6 -0
- metadata +72 -103
- data/lib/http/streaming_body.rb +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 791f3d5774fd363cb1ddd109f8004f161150d997
|
4
|
+
data.tar.gz: 0f8bf2bdc69d3d8fb0c9484c1b218529c933150d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8b139d07c564495baf15eebd76e26872492db144b6a9efdef7464feea44894f36d8b17814ad0bdb90590d4dc84273178a3f72c9b6321b314744f3fae5ad5773
|
7
|
+
data.tar.gz: 830899cd441d80980f388e7c771987782e7503647bf5b5434ad2650d811d032207e35f4137adc3e68c3c8b184ad9ed3898bfcc481c6aa28835821ced914c44dd
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service-name: travis-pro
|
data/.travis.yml
CHANGED
@@ -1,11 +1,16 @@
|
|
1
1
|
rvm:
|
2
2
|
- 1.8.7
|
3
|
-
- 1.9.2
|
4
3
|
- 1.9.3
|
4
|
+
- 2.0.0
|
5
5
|
- ree
|
6
|
-
|
6
|
+
- ruby-head
|
7
7
|
- jruby-18mode
|
8
8
|
- jruby-19mode
|
9
|
-
|
9
|
+
- jruby-head
|
10
10
|
- rbx-18mode
|
11
11
|
- rbx-19mode
|
12
|
+
|
13
|
+
matrix:
|
14
|
+
allow_failures:
|
15
|
+
- rvm: ruby-head
|
16
|
+
- rvm: jruby-head
|
data/CHANGES.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
0.5.0.pre
|
2
|
+
---------
|
3
|
+
* Add query string support
|
4
|
+
* New response delegator allows Http.get(uri).response
|
5
|
+
* Http::Chainable#stream provides a shorter alias for
|
6
|
+
with_response(:object)
|
7
|
+
* Better string inspect for Http::Response
|
8
|
+
|
1
9
|
0.4.0
|
2
10
|
-----
|
3
11
|
* Fix bug accessing https URLs
|
data/Gemfile
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
2
|
|
3
3
|
gem 'jruby-openssl' if defined? JRUBY_VERSION
|
4
|
+
gem 'coveralls', :require => false
|
4
5
|
|
5
6
|
# Specify your gem's dependencies in http.gemspec
|
6
7
|
gemspec
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'guard-rspec'
|
11
|
+
gem 'celluloid-io' if RUBY_VERSION >= "1.9.3"
|
12
|
+
end
|
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,11 +1,38 @@
|
|
1
|
-
Http
|
2
|
-
|
1
|
+
The Http Gem*
|
2
|
+
==============
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/http.png)](http://rubygems.org/gems/http)
|
3
4
|
[![Build Status](https://secure.travis-ci.org/tarcieri/http.png?branch=master)](http://travis-ci.org/tarcieri/http)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/tarcieri/http.png)](https://codeclimate.com/github/tarcieri/http)
|
6
|
+
[![Coverage Status](https://coveralls.io/repos/tarcieri/http/badge.png?branch=master)](https://coveralls.io/r/tarcieri/http)
|
4
7
|
|
5
|
-
|
6
|
-
|
8
|
+
*NOTE: this gem has the worst name in the history of SEO. But perhaps we can fix
|
9
|
+
that if we all refer to it as "The HTTP Gem". Entering that phrase into Google
|
10
|
+
actually pulls it up as #4 for me!
|
7
11
|
|
8
|
-
The Http
|
12
|
+
The Http Gem is an easy-to-use client library for making requests from Ruby. It uses
|
13
|
+
a simple method chaining system for building requests, similar to libraries
|
14
|
+
like JQuery or Python's [Requests](http://docs.python-requests.org/en/latest/).
|
15
|
+
|
16
|
+
Installation
|
17
|
+
------------
|
18
|
+
|
19
|
+
Add this line to your application's Gemfile:
|
20
|
+
|
21
|
+
gem 'http'
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install http
|
30
|
+
|
31
|
+
Inside of your Ruby program do:
|
32
|
+
|
33
|
+
require 'http'
|
34
|
+
|
35
|
+
...to pull it in as a dependency.
|
9
36
|
|
10
37
|
Making Requests
|
11
38
|
---------------
|
@@ -13,16 +40,28 @@ Making Requests
|
|
13
40
|
Let's start with getting things:
|
14
41
|
|
15
42
|
```ruby
|
16
|
-
Http.get
|
43
|
+
>> Http.get("http://www.google.com")
|
44
|
+
=> "<html><head><meta http-equiv=\"content-type\" content=..."
|
17
45
|
```
|
18
46
|
|
19
|
-
That's it! The result is the response body.
|
47
|
+
That's it! The result is the response body as a string. To obtain an Http::Response object
|
48
|
+
instead of the response body, chain `.response` on the end of the request:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
>> Http.get("http://www.google.com").response
|
52
|
+
=> #<HTTP/1.0 200 OK @headers={"Content-Type"=>"text/html; charset=UTF-8", "Date"=>"Fri, ...>
|
53
|
+
```
|
20
54
|
|
21
55
|
Making POST requests is simple too. Want to POST a form?
|
22
56
|
|
23
57
|
```ruby
|
24
58
|
Http.post "http://example.com/resource", :form => {:foo => "42"}
|
25
59
|
```
|
60
|
+
Making GET requests with query string parameters is as simple.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Http.get "http://example.com/resource", :params => {:foo => "bar"}
|
64
|
+
```
|
26
65
|
|
27
66
|
Want to POST with a specific body, JSON for instance?
|
28
67
|
|
@@ -113,4 +152,4 @@ Contributing to Http
|
|
113
152
|
Copyright
|
114
153
|
---------
|
115
154
|
|
116
|
-
Copyright (c)
|
155
|
+
Copyright (c) 2013 Tony Arcieri. See LICENSE.txt for further details.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Example of using the Http Gem with Celluloid::IO
|
4
|
+
# Make sure to 'gem install celluloid-io' before running
|
5
|
+
#
|
6
|
+
# Run as: bundle exec examples/celluloid.rb
|
7
|
+
#
|
8
|
+
|
9
|
+
require 'celluloid/io'
|
10
|
+
require 'http'
|
11
|
+
|
12
|
+
puts Http.get("https://www.google.com/", :socket_class => Celluloid::IO::TCPSocket, :ssl_socket_class => Celluloid::IO::SSLSocket)
|
data/http.gemspec
CHANGED
data/lib/http.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'certified'
|
3
2
|
require 'http/parser'
|
4
3
|
require 'http/version'
|
5
4
|
|
@@ -20,15 +19,9 @@ module HTTP
|
|
20
19
|
# The method given was not understood
|
21
20
|
class UnsupportedMethodError < ArgumentError; end
|
22
21
|
|
23
|
-
# Valid HTTP methods
|
24
|
-
METHODS = [:get, :head, :post, :put, :delete, :trace, :options, :connect, :patch]
|
25
|
-
|
26
22
|
# Matches HTTP header names when in "Canonical-Http-Format"
|
27
23
|
CANONICAL_HEADER = /^[A-Z][a-z]*(-[A-Z][a-z]*)*$/
|
28
24
|
|
29
|
-
# CRLF is the universal HTTP delimiter
|
30
|
-
CRLF = "\r\n"
|
31
|
-
|
32
25
|
class << self
|
33
26
|
# Http[:accept => 'text/html'].get(...)
|
34
27
|
alias_method :[], :with_headers
|
data/lib/http/chainable.rb
CHANGED
data/lib/http/client.rb
CHANGED
@@ -13,7 +13,7 @@ module HTTP
|
|
13
13
|
@default_options = Options.new(default_options)
|
14
14
|
end
|
15
15
|
|
16
|
-
def body(opts,headers)
|
16
|
+
def body(opts, headers)
|
17
17
|
if opts.body
|
18
18
|
body = opts.body
|
19
19
|
elsif opts.form
|
@@ -31,14 +31,17 @@ module HTTP
|
|
31
31
|
proxy = opts.proxy
|
32
32
|
|
33
33
|
method_body = body(opts, headers)
|
34
|
-
|
34
|
+
if opts.params
|
35
|
+
uri="#{uri}?#{URI.encode_www_form(opts.params)}"
|
36
|
+
end
|
35
37
|
|
38
|
+
request = Request.new method, uri, headers, proxy, method_body
|
36
39
|
if opts.follow
|
37
40
|
code = 302
|
38
41
|
while code == 302 or code == 301
|
39
42
|
# if the uri isn't fully formed complete it
|
40
43
|
if not uri.match /\./
|
41
|
-
uri = "
|
44
|
+
uri = "#{method}://#{host}#{uri}"
|
42
45
|
end
|
43
46
|
host = URI.parse(uri).host
|
44
47
|
opts.headers["Host"] = host
|
@@ -76,22 +79,19 @@ module HTTP
|
|
76
79
|
|
77
80
|
begin
|
78
81
|
parser << socket.readpartial(BUFFER_SIZE) until parser.headers
|
79
|
-
rescue IOError, Errno::ECONNRESET, Errno::EPIPE
|
80
|
-
|
81
|
-
raise "zomg IO troubles: #{$!.message}"
|
82
|
+
rescue IOError, Errno::ECONNRESET, Errno::EPIPE => ex
|
83
|
+
raise IOError, "problem making HTTP request: #{ex}"
|
82
84
|
end
|
83
85
|
|
84
86
|
response = Http::Response.new(parser.status_code, parser.http_version, parser.headers) do
|
85
|
-
if @body_remaining
|
86
|
-
chunk = parser.chunk
|
87
|
-
unless chunk
|
87
|
+
if !parser.finished? || (@body_remaining && @body_remaining > 0)
|
88
|
+
chunk = parser.chunk || begin
|
88
89
|
parser << socket.readpartial(BUFFER_SIZE)
|
89
|
-
chunk
|
90
|
-
return unless chunk
|
90
|
+
parser.chunk || ""
|
91
91
|
end
|
92
92
|
|
93
|
-
@body_remaining -= chunk.length
|
94
|
-
@body_remaining = nil if @body_remaining < 1
|
93
|
+
@body_remaining -= chunk.length if @body_remaining
|
94
|
+
@body_remaining = nil if @body_remaining && @body_remaining < 1
|
95
95
|
|
96
96
|
chunk
|
97
97
|
end
|
@@ -104,13 +104,17 @@ module HTTP
|
|
104
104
|
def format_response(method, response, option)
|
105
105
|
case option
|
106
106
|
when :auto, NilClass
|
107
|
-
method == :head
|
107
|
+
if method == :head
|
108
|
+
response
|
109
|
+
else
|
110
|
+
Http::Response::BodyDelegator.new(response, response.parse_body)
|
111
|
+
end
|
108
112
|
when :object
|
109
113
|
response
|
110
114
|
when :parsed_body
|
111
|
-
response.parse_body
|
115
|
+
Http::Response::BodyDelegator.new(response, response.parse_body)
|
112
116
|
when :body
|
113
|
-
response
|
117
|
+
Http::Response::BodyDelegator.new(response)
|
114
118
|
else raise ArgumentError, "invalid response type: #{option}"
|
115
119
|
end
|
116
120
|
end
|
data/lib/http/options.rb
CHANGED
@@ -10,6 +10,9 @@ module HTTP
|
|
10
10
|
# Http headers to include in the request
|
11
11
|
attr_accessor :headers
|
12
12
|
|
13
|
+
# Query string params to add to the url
|
14
|
+
attr_accessor :params
|
15
|
+
|
13
16
|
# Form data to embed in the request
|
14
17
|
attr_accessor :form
|
15
18
|
|
@@ -31,7 +34,7 @@ module HTTP
|
|
31
34
|
# Follow redirects
|
32
35
|
attr_accessor :follow
|
33
36
|
|
34
|
-
protected :response=, :headers=, :proxy=, :form=, :callbacks=, :follow=
|
37
|
+
protected :response=, :headers=, :proxy=, :params=, :form=, :callbacks=, :follow=
|
35
38
|
|
36
39
|
@default_socket_class = TCPSocket
|
37
40
|
@default_ssl_socket_class = OpenSSL::SSL::SSLSocket
|
@@ -51,6 +54,7 @@ module HTTP
|
|
51
54
|
@proxy = options[:proxy] || {}
|
52
55
|
@callbacks = options[:callbacks] || {:request => [], :response => []}
|
53
56
|
@body = options[:body]
|
57
|
+
@params = options[:params]
|
54
58
|
@form = options[:form]
|
55
59
|
@follow = options[:follow]
|
56
60
|
|
@@ -85,6 +89,12 @@ module HTTP
|
|
85
89
|
end
|
86
90
|
end
|
87
91
|
|
92
|
+
def with_params(params)
|
93
|
+
dup do |opts|
|
94
|
+
opts.params = params
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
88
98
|
def with_form(form)
|
89
99
|
dup do |opts|
|
90
100
|
opts.form = form
|
@@ -135,17 +145,27 @@ module HTTP
|
|
135
145
|
v2
|
136
146
|
end
|
137
147
|
end
|
148
|
+
|
138
149
|
Options.new(merged)
|
139
150
|
end
|
140
151
|
|
141
152
|
def to_hash
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
153
|
+
# FIXME: hardcoding these fields blows! We should have a declarative
|
154
|
+
# way of specifying all the options fields, and ensure they *all*
|
155
|
+
# get serialized here, rather than manually having to add them each time
|
156
|
+
{
|
157
|
+
:response => response,
|
158
|
+
:headers => headers,
|
159
|
+
:proxy => proxy,
|
160
|
+
:params => params,
|
161
|
+
:form => form,
|
162
|
+
:body => body,
|
163
|
+
:callbacks => callbacks,
|
164
|
+
:follow => follow,
|
165
|
+
:socket_class => socket_class,
|
166
|
+
:ssl_socket_class => ssl_socket_class,
|
167
|
+
:ssl_context => ssl_context
|
168
|
+
}
|
149
169
|
end
|
150
170
|
|
151
171
|
def dup
|
data/lib/http/request.rb
CHANGED
@@ -1,5 +1,25 @@
|
|
1
|
+
require 'http/request_stream'
|
2
|
+
|
1
3
|
module HTTP
|
2
4
|
class Request
|
5
|
+
# RFC 2616: Hypertext Transfer Protocol -- HTTP/1.1
|
6
|
+
METHODS = [:options, :get, :head, :post, :put, :delete, :trace, :connect]
|
7
|
+
|
8
|
+
# RFC 2518: HTTP Extensions for Distributed Authoring -- WEBDAV
|
9
|
+
METHODS.concat [:propfind, :proppatch, :mkcol, :copy, :move, :lock, :unlock]
|
10
|
+
|
11
|
+
# RFC 3648: WebDAV Ordered Collections Protocol
|
12
|
+
METHODS.concat [:orderpatch]
|
13
|
+
|
14
|
+
# RFC 3744: WebDAV Access Control Protocol
|
15
|
+
METHODS.concat [:acl]
|
16
|
+
|
17
|
+
# draft-dusseault-http-patch: PATCH Method for HTTP
|
18
|
+
METHODS.concat [:patch]
|
19
|
+
|
20
|
+
# draft-reschke-webdav-search: WebDAV Search
|
21
|
+
METHODS.concat [:search]
|
22
|
+
|
3
23
|
# Method is given as a lowercase symbol e.g. :get, :post
|
4
24
|
attr_reader :method
|
5
25
|
|
@@ -33,7 +53,9 @@ module HTTP
|
|
33
53
|
|
34
54
|
# Stream the request to a socket
|
35
55
|
def stream(socket)
|
36
|
-
|
56
|
+
path = uri.query ? "#{uri.path}?#{uri.query}" : uri.path
|
57
|
+
path = "/" if path.empty?
|
58
|
+
request_header = "#{method.to_s.upcase} #{path} HTTP/#{version}"
|
37
59
|
rs = Http::RequestStream.new socket, body, @headers, request_header
|
38
60
|
rs.stream
|
39
61
|
end
|
data/lib/http/request_stream.rb
CHANGED
data/lib/http/response.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
|
1
3
|
module HTTP
|
2
4
|
class Response
|
3
5
|
STATUS_CODES = {
|
@@ -92,6 +94,12 @@ module HTTP
|
|
92
94
|
end
|
93
95
|
end
|
94
96
|
|
97
|
+
# Obtain the 'Reason-Phrase' for the response
|
98
|
+
def reason
|
99
|
+
# FIXME: should get the real reason phrase from the parser
|
100
|
+
STATUS_CODES[@status]
|
101
|
+
end
|
102
|
+
|
95
103
|
# Get a header value
|
96
104
|
def [](name)
|
97
105
|
@headers[name] || @headers[Http.canonicalize_header(name)]
|
@@ -128,5 +136,22 @@ module HTTP
|
|
128
136
|
def to_a
|
129
137
|
[status, headers, parse_body]
|
130
138
|
end
|
139
|
+
|
140
|
+
# Inspect a response
|
141
|
+
def inspect
|
142
|
+
"#<#{self.class}/#{@version} #{status} #{reason} @headers=#{@headers.inspect}>"
|
143
|
+
end
|
144
|
+
|
145
|
+
class BodyDelegator < ::Delegator
|
146
|
+
attr_reader :response
|
147
|
+
|
148
|
+
def initialize(response, body = response.body)
|
149
|
+
super(body)
|
150
|
+
@response, @body = response, body
|
151
|
+
end
|
152
|
+
|
153
|
+
def __getobj__; @body; end
|
154
|
+
def __setobj__(obj); @body = obj; end
|
155
|
+
end
|
131
156
|
end
|
132
157
|
end
|
data/lib/http/response_parser.rb
CHANGED
data/lib/http/version.rb
CHANGED
@@ -17,8 +17,11 @@ describe Http::Options, "merge" do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'merges as excepted in complex cases' do
|
20
|
+
# FIXME: yuck :(
|
21
|
+
|
20
22
|
foo = Http::Options.new(
|
21
23
|
:response => :body,
|
24
|
+
:params => {:baz => 'bar'},
|
22
25
|
:form => {:foo => 'foo'},
|
23
26
|
:body => "body-foo",
|
24
27
|
:headers => {:accept => "json", :foo => 'foo'},
|
@@ -26,6 +29,7 @@ describe Http::Options, "merge" do
|
|
26
29
|
:callbacks => {:request => ["common"], :response => ["foo"]})
|
27
30
|
bar = Http::Options.new(
|
28
31
|
:response => :parsed_body,
|
32
|
+
:params => {:plop => 'plip'},
|
29
33
|
:form => {:bar => 'bar'},
|
30
34
|
:body => "body-bar",
|
31
35
|
:headers => {:accept => "xml", :bar => 'bar'},
|
@@ -33,13 +37,16 @@ describe Http::Options, "merge" do
|
|
33
37
|
:callbacks => {:request => ["common"], :response => ["bar"]})
|
34
38
|
foo.merge(bar).to_hash.should eq(
|
35
39
|
:response => :parsed_body,
|
40
|
+
:params=>{:plop=>"plip"},
|
36
41
|
:form => {:bar => 'bar'},
|
37
42
|
:body => "body-bar",
|
38
43
|
:headers => {:accept => "xml", :foo => "foo", :bar => 'bar', "User-Agent" => user_agent},
|
39
44
|
:proxy => {:proxy_address => "127.0.0.1", :proxy_port => 8080},
|
40
45
|
:callbacks => {:request => ["common"], :response => ["foo", "bar"]},
|
41
|
-
:follow => nil
|
46
|
+
:follow => nil,
|
47
|
+
:socket_class => described_class.default_socket_class,
|
48
|
+
:ssl_socket_class => described_class.default_ssl_socket_class,
|
49
|
+
:ssl_context => nil
|
42
50
|
)
|
43
51
|
end
|
44
|
-
|
45
52
|
end
|
data/spec/http/options_spec.rb
CHANGED
@@ -1,26 +1,20 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Http::Options do
|
4
|
+
subject { described_class.new(:response => :body) }
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
options[:response].should eq(:body)
|
9
|
-
options[:nosuchone].should be_nil
|
6
|
+
it "behaves like a Hash for reading" do
|
7
|
+
subject[:response].should eq(:body)
|
8
|
+
subject[:nosuchone].should be_nil
|
10
9
|
end
|
11
10
|
|
12
|
-
it '
|
13
|
-
|
14
|
-
|
11
|
+
it "it's gois able to coerce to a Hash" do
|
12
|
+
subject.to_hash.should be_a(Hash)
|
13
|
+
subject.to_hash[:response].should eq(:body)
|
15
14
|
end
|
16
15
|
|
17
|
-
it
|
18
|
-
|
19
|
-
options.with_response(:notrecognized)
|
20
|
-
true.should be_false
|
21
|
-
rescue ArgumentError => ex
|
22
|
-
puts ex.backtrace.first.should match(/options_spec/)
|
23
|
-
end
|
16
|
+
it "raises ArgumentError with invalid options" do
|
17
|
+
expect { subject.with_response(:notrecognized) }.to raise_exception(ArgumentError)
|
24
18
|
end
|
25
19
|
|
26
20
|
end
|
data/spec/http_spec.rb
CHANGED
@@ -11,17 +11,9 @@ describe Http do
|
|
11
11
|
response.should match(/<!doctype html>/)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "should be easy to get a
|
15
|
-
response = Http.
|
16
|
-
response
|
17
|
-
end
|
18
|
-
|
19
|
-
it "can get some real world sites, following redirects if necessary" do
|
20
|
-
sites = ["http://github.com/", "http://xkcd.com/", "http://www.spotify.com/"]
|
21
|
-
sites.each do |site|
|
22
|
-
resp = Http.with_response(:object).with_follow(true).get site
|
23
|
-
resp.status.should == 200
|
24
|
-
end
|
14
|
+
it "should be easy to get a response object" do
|
15
|
+
response = Http.get(test_endpoint).response
|
16
|
+
response.should be_a Http::Response
|
25
17
|
end
|
26
18
|
|
27
19
|
context "with_response" do
|
@@ -31,6 +23,14 @@ describe Http do
|
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
26
|
+
context "with query string parameters" do
|
27
|
+
|
28
|
+
it "should be easy" do
|
29
|
+
response = Http.get "#{test_endpoint}params" , :params => {:foo => 'bar'}
|
30
|
+
response.should match(/Params!/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
34
|
context "with headers" do
|
35
35
|
it "should be easy" do
|
36
36
|
response = Http.accept(:json).get test_endpoint
|
data/spec/spec_helper.rb
CHANGED
@@ -4,6 +4,7 @@ class ExampleService < WEBrick::HTTPServlet::AbstractServlet
|
|
4
4
|
PORT = 65432
|
5
5
|
|
6
6
|
def do_GET(request, response)
|
7
|
+
|
7
8
|
case request.path
|
8
9
|
when "/"
|
9
10
|
response.status = 200
|
@@ -16,6 +17,11 @@ class ExampleService < WEBrick::HTTPServlet::AbstractServlet
|
|
16
17
|
response['Content-Type'] = 'text/html'
|
17
18
|
response.body = "<!doctype html>"
|
18
19
|
end
|
20
|
+
when "/params"
|
21
|
+
if request.query_string="foo=bar"
|
22
|
+
response.status = 200
|
23
|
+
response.body = "Params!"
|
24
|
+
end
|
19
25
|
when "/proxy"
|
20
26
|
response.status = 200
|
21
27
|
response.body = "Proxy!"
|
metadata
CHANGED
@@ -1,110 +1,90 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 0
|
10
|
-
version: 0.4.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0.pre
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Tony Arcieri
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: http_parser.rb
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
hash: 3
|
28
|
-
segments:
|
29
|
-
- 0
|
30
|
-
version: "0"
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
31
20
|
type: :runtime
|
32
|
-
requirement: *id001
|
33
21
|
prerelease: false
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
hash: 3
|
42
|
-
segments:
|
43
|
-
- 0
|
44
|
-
version: "0"
|
45
|
-
type: :runtime
|
46
|
-
requirement: *id002
|
47
|
-
prerelease: false
|
48
|
-
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
49
28
|
name: rake
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
hash: 3
|
56
|
-
segments:
|
57
|
-
- 0
|
58
|
-
version: "0"
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
59
34
|
type: :development
|
60
|
-
requirement: *id003
|
61
35
|
prerelease: false
|
62
|
-
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
63
42
|
name: rspec
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
hash: 3
|
70
|
-
segments:
|
71
|
-
- 0
|
72
|
-
version: "0"
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
73
48
|
type: :development
|
74
|
-
requirement: *id004
|
75
49
|
prerelease: false
|
76
|
-
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
77
56
|
name: json
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
hash: 3
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
version: "0"
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
87
62
|
type: :development
|
88
|
-
requirement: *id005
|
89
63
|
prerelease: false
|
90
|
-
|
91
|
-
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: HTTP so awesome it will lure Catherine Zeta Jones into your unicorn petting
|
70
|
+
zoo
|
71
|
+
email:
|
92
72
|
- tony.arcieri@gmail.com
|
93
73
|
executables: []
|
94
|
-
|
95
74
|
extensions: []
|
96
|
-
|
97
75
|
extra_rdoc_files: []
|
98
|
-
|
99
|
-
|
76
|
+
files:
|
77
|
+
- .coveralls.yml
|
100
78
|
- .gitignore
|
101
79
|
- .rspec
|
102
80
|
- .travis.yml
|
103
81
|
- CHANGES.md
|
104
82
|
- Gemfile
|
83
|
+
- Guardfile
|
105
84
|
- LICENSE.txt
|
106
85
|
- README.md
|
107
86
|
- Rakefile
|
87
|
+
- examples/celluloid.rb
|
108
88
|
- http.gemspec
|
109
89
|
- lib/http.rb
|
110
90
|
- lib/http/chainable.rb
|
@@ -117,7 +97,6 @@ files:
|
|
117
97
|
- lib/http/request_stream.rb
|
118
98
|
- lib/http/response.rb
|
119
99
|
- lib/http/response_parser.rb
|
120
|
-
- lib/http/streaming_body.rb
|
121
100
|
- lib/http/uri_backport.rb
|
122
101
|
- lib/http/version.rb
|
123
102
|
- spec/http/compat/curb_spec.rb
|
@@ -138,38 +117,28 @@ files:
|
|
138
117
|
- spec/support/proxy_server.rb
|
139
118
|
homepage: https://github.com/tarcieri/http
|
140
119
|
licenses: []
|
141
|
-
|
120
|
+
metadata: {}
|
142
121
|
post_install_message:
|
143
122
|
rdoc_options: []
|
144
|
-
|
145
|
-
require_paths:
|
123
|
+
require_paths:
|
146
124
|
- lib
|
147
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
none: false
|
158
|
-
requirements:
|
159
|
-
- - ">="
|
160
|
-
- !ruby/object:Gem::Version
|
161
|
-
hash: 3
|
162
|
-
segments:
|
163
|
-
- 0
|
164
|
-
version: "0"
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - '>='
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - '>'
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.3.1
|
165
135
|
requirements: []
|
166
|
-
|
167
136
|
rubyforge_project:
|
168
|
-
rubygems_version:
|
137
|
+
rubygems_version: 2.0.3
|
169
138
|
signing_key:
|
170
|
-
specification_version:
|
139
|
+
specification_version: 4
|
171
140
|
summary: HTTP should be easy
|
172
|
-
test_files:
|
141
|
+
test_files:
|
173
142
|
- spec/http/compat/curb_spec.rb
|
174
143
|
- spec/http/options/body_spec.rb
|
175
144
|
- spec/http/options/callbacks_spec.rb
|
data/lib/http/streaming_body.rb
DELETED
File without changes
|