http 0.8.4 → 0.8.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +37 -19
- data/http.gemspec +4 -3
- data/lib/http/chainable.rb +26 -5
- data/lib/http/request.rb +5 -2
- data/lib/http/request/writer.rb +2 -2
- data/lib/http/version.rb +1 -1
- data/spec/lib/http/request_spec.rb +2 -2
- metadata +6 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22451fa65c5d83ca271a7ac53671dd039f66f6a
|
4
|
+
data.tar.gz: ceea0aa11f428af8569bd18de9b188bce8cf65c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 624d636385c6eac2b23ac9c1d11b631b676120344db7904381a85b02f4d19e977d6adfc9d3b42a862ea0567052a3ecac19df8818479ff4922a955847c672f0dd
|
7
|
+
data.tar.gz: 5721fc63432acfc6969bc6c6267d2c54565001b09d60e610113a89ebdf84890ef51a2a5ed3e8bdf2bf9a2c6db699fc364b23a666e3e438555edca5b1ad783445
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## master (unreleased)
|
2
2
|
|
3
|
+
* _the future is unwritten_
|
4
|
+
|
5
|
+
|
6
|
+
## 0.8.5 (2015-05-06)
|
7
|
+
|
8
|
+
* Add simple timeouts configuration API. See #205. (@ixti)
|
9
|
+
* Deprecate `Request#request_header`. Use `Request#headline` instead. (@ixti)
|
10
|
+
|
3
11
|
|
4
12
|
## 0.8.4 (2015-04-23)
|
5
13
|
|
data/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2011-
|
1
|
+
Copyright (c) 2011-2015 Tony Arcieri, Erik Michaels-Ober, Alexey V. Zapparov, Zachary Anker
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
![http.rb](https://raw.github.com/httprb/http.rb/master/logo.png)
|
2
|
-
|
1
|
+
# ![http.rb](https://raw.github.com/httprb/http.rb/master/logo.png)
|
2
|
+
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/http.svg)](http://rubygems.org/gems/http)
|
4
4
|
[![Build Status](https://secure.travis-ci.org/httprb/http.rb.svg?branch=master)](http://travis-ci.org/httprb/http.rb)
|
5
5
|
[![Code Climate](https://codeclimate.com/github/httprb/http.rb.svg?branch=master)](https://codeclimate.com/github/httprb/http.rb)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/httprb/http.rb/badge.svg?branch=master)](https://coveralls.io/r/httprb/http.rb)
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
## About
|
10
10
|
|
11
11
|
http.rb is an easy-to-use client library for making requests from Ruby. It uses
|
12
12
|
a simple method chaining system for building requests, similar to Python's [Requests].
|
@@ -19,8 +19,8 @@ natively and outsources the parsing to native extensions.
|
|
19
19
|
[requests]: http://docs.python-requests.org/en/latest/
|
20
20
|
[http_parser.rb]: https://github.com/tmm1/http_parser.rb
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
|
23
|
+
## Help and Discussion
|
24
24
|
|
25
25
|
If you need help or just want to talk about the http.rb,
|
26
26
|
visit the http.rb Google Group:
|
@@ -35,8 +35,8 @@ If you believe you've found a bug, please report it at:
|
|
35
35
|
|
36
36
|
https://github.com/httprb/http.rb/issues
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
|
39
|
+
## Installation
|
40
40
|
|
41
41
|
Add this line to your application's Gemfile:
|
42
42
|
|
@@ -56,17 +56,18 @@ Inside of your Ruby program do:
|
|
56
56
|
|
57
57
|
...to pull it in as a dependency.
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
|
60
|
+
## Documentation
|
61
61
|
|
62
62
|
[Please see the http.rb wiki](https://github.com/httprb/http.rb/wiki)
|
63
63
|
for more detailed documentation and usage notes.
|
64
64
|
|
65
|
-
|
66
|
-
|
65
|
+
|
66
|
+
## Basic Usage
|
67
67
|
|
68
68
|
Here's some simple examples to get you started:
|
69
69
|
|
70
|
+
|
70
71
|
### GET requests
|
71
72
|
|
72
73
|
```ruby
|
@@ -100,6 +101,7 @@ The response body can be streamed with `HTTP::Response::Body#readpartial`:
|
|
100
101
|
In practice you'll want to bind the HTTP::Response::Body to a local variable (e.g.
|
101
102
|
"body") and call readpartial on it repeatedly until it returns `nil`.
|
102
103
|
|
104
|
+
|
103
105
|
### POST requests
|
104
106
|
|
105
107
|
Making POST requests is simple too. Want to POST a form?
|
@@ -136,6 +138,7 @@ HTTP.post("http://examplc.com/resource", :form => {
|
|
136
138
|
|
137
139
|
It's easy!
|
138
140
|
|
141
|
+
|
139
142
|
### Proxy Support
|
140
143
|
|
141
144
|
Making request behind proxy is as simple as making them directly. Just specify
|
@@ -153,6 +156,7 @@ HTTP.via("proxy-hostname.local", 8080, "username", "password")
|
|
153
156
|
.get("http://example.com/resource")
|
154
157
|
```
|
155
158
|
|
159
|
+
|
156
160
|
### Adding Headers
|
157
161
|
|
158
162
|
The HTTP gem uses the concept of chaining to simplify requests. Let's say
|
@@ -184,6 +188,7 @@ HTTP[:accept => "application/json"]
|
|
184
188
|
.get("https://github.com/httprb/http.rb/commit/HEAD")
|
185
189
|
```
|
186
190
|
|
191
|
+
|
187
192
|
### Authorization Header
|
188
193
|
|
189
194
|
With [HTTP Basic Authentication](http://tools.ietf.org/html/rfc2617) using
|
@@ -209,6 +214,7 @@ HTTP.basic_auth(:user => "user", :pass => "pass")
|
|
209
214
|
.get("https://example.com")
|
210
215
|
```
|
211
216
|
|
217
|
+
|
212
218
|
### Content Negotiation
|
213
219
|
|
214
220
|
As important a concept as content negotiation is to HTTP, it sure should be easy,
|
@@ -222,6 +228,7 @@ HTTP.accept(:json).get("https://github.com/httprb/http.rb/commit/HEAD")
|
|
222
228
|
This adds the appropriate Accept header for retrieving a JSON response for the
|
223
229
|
given resource.
|
224
230
|
|
231
|
+
|
225
232
|
### Celluloid::IO Support
|
226
233
|
|
227
234
|
http.rb makes it simple to make multiple concurrent HTTP requests from a
|
@@ -246,6 +253,7 @@ There's a little more to it, but that's the core idea!
|
|
246
253
|
* [Full parallel HTTP fetcher example](https://github.com/httprb/http.rb/wiki/Parallel-requests-with-Celluloid%3A%3AIO)
|
247
254
|
* See also: [Celluloid::IO](https://github.com/celluloid/celluloid-io)
|
248
255
|
|
256
|
+
|
249
257
|
### Caching
|
250
258
|
|
251
259
|
http.rb provides caching of HTTP request (per
|
@@ -267,8 +275,18 @@ http.rb's caching is backed by
|
|
267
275
|
[rack-cache's excellent storage subsystem](http://rtomayko.github.io/rack-cache/storage.html). Any
|
268
276
|
storage URL supported by rack-cache is supported by http.rb's cache.
|
269
277
|
|
270
|
-
|
271
|
-
|
278
|
+
|
279
|
+
### Timeouts
|
280
|
+
|
281
|
+
You can configure http.rb to fail if request (connect / read / write) takes too
|
282
|
+
long:
|
283
|
+
|
284
|
+
``` ruby
|
285
|
+
HTTP.timeout(:connect => 5, :read => 10).get "http://example.com"
|
286
|
+
```
|
287
|
+
|
288
|
+
|
289
|
+
## Supported Ruby Versions
|
272
290
|
|
273
291
|
This library aims to support and is [tested against][travis] the following Ruby
|
274
292
|
versions:
|
@@ -294,8 +312,8 @@ dropped.
|
|
294
312
|
|
295
313
|
[travis]: http://travis-ci.org/httprb/http.rb
|
296
314
|
|
297
|
-
|
298
|
-
|
315
|
+
|
316
|
+
## Contributing to http.rb
|
299
317
|
|
300
318
|
* Fork http.rb on GitHub
|
301
319
|
* Make your changes
|
@@ -304,8 +322,8 @@ Contributing to http.rb
|
|
304
322
|
* If we like them we'll merge them
|
305
323
|
* If we've accepted a patch, feel free to ask for commit access!
|
306
324
|
|
307
|
-
Copyright
|
308
|
-
---------
|
309
325
|
|
310
|
-
Copyright
|
326
|
+
## Copyright
|
327
|
+
|
328
|
+
Copyright (c) 2011-2015 Tony Arcieri, Erik Michaels-Ober, Alexey V. Zapparov, Zachary Anker
|
311
329
|
See LICENSE.txt for further details.
|
data/http.gemspec
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "http/version"
|
3
4
|
|
4
5
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Tony Arcieri", "Erik Michaels-Ober", "
|
6
|
+
gem.authors = ["Tony Arcieri", "Erik Michaels-Ober", "Alexey V. Zapparov", "Zachary Anker"]
|
6
7
|
gem.email = ["bascule@gmail.com"]
|
7
8
|
|
8
9
|
gem.description = <<-DESCRIPTION.strip.gsub(/\s+/, " ")
|
data/lib/http/chainable.rb
CHANGED
@@ -72,6 +72,32 @@ module HTTP
|
|
72
72
|
branch(options).request verb, uri
|
73
73
|
end
|
74
74
|
|
75
|
+
# @overload(options = {})
|
76
|
+
# Syntax sugar for `timeout(:per_operation, options)`
|
77
|
+
# @overload(klass, options = {})
|
78
|
+
# @param [#to_sym] klass
|
79
|
+
# @param [Hash] options
|
80
|
+
# @option options [Float] :read Read timeout
|
81
|
+
# @option options [Float] :write Write timeout
|
82
|
+
# @option options [Float] :connect Connect timeout
|
83
|
+
def timeout(klass, options = {})
|
84
|
+
klass, options = options, {} if klass.is_a? Hash
|
85
|
+
|
86
|
+
klass = case klass.to_sym
|
87
|
+
when :null then HTTP::Timeout::Null
|
88
|
+
when :global then HTTP::Timeout::Global
|
89
|
+
when :per_operation then HTTP::Timeout::PerOperation
|
90
|
+
else fail Error, "Unsupported Timeout class: #{klass}"
|
91
|
+
end
|
92
|
+
|
93
|
+
[:read, :write, :connect].each do |k|
|
94
|
+
next unless options.key? k
|
95
|
+
options["#{k}_timeout".to_sym] = options.delete k
|
96
|
+
end
|
97
|
+
|
98
|
+
branch :timeout_class => klass, :timeout_options => options
|
99
|
+
end
|
100
|
+
|
75
101
|
# @overload persistent(host)
|
76
102
|
# Flags as persistent
|
77
103
|
# @param [String] host
|
@@ -127,11 +153,6 @@ module HTTP
|
|
127
153
|
end
|
128
154
|
alias_method :through, :via
|
129
155
|
|
130
|
-
# Alias for with_response(:object)
|
131
|
-
def stream
|
132
|
-
with_response(:object)
|
133
|
-
end
|
134
|
-
|
135
156
|
# Make client follow redirects.
|
136
157
|
# @param opts
|
137
158
|
# @return [HTTP::Client]
|
data/lib/http/request.rb
CHANGED
@@ -91,7 +91,7 @@ module HTTP
|
|
91
91
|
# Stream the request to a socket
|
92
92
|
def stream(socket)
|
93
93
|
include_proxy_authorization_header if using_authenticated_proxy? && !@uri.https?
|
94
|
-
Request::Writer.new(socket, body, headers,
|
94
|
+
Request::Writer.new(socket, body, headers, headline).stream
|
95
95
|
end
|
96
96
|
|
97
97
|
# Is this request using a proxy?
|
@@ -120,11 +120,14 @@ module HTTP
|
|
120
120
|
end
|
121
121
|
|
122
122
|
# Compute HTTP request header for direct or proxy request
|
123
|
-
def
|
123
|
+
def headline
|
124
124
|
request_uri = using_proxy? ? uri : uri.omit(:scheme, :authority)
|
125
125
|
"#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
|
126
126
|
end
|
127
127
|
|
128
|
+
# @deprecated Will be removed in 1.0.0
|
129
|
+
alias_method :request_header, :headline
|
130
|
+
|
128
131
|
# Compute HTTP request header SSL proxy connection
|
129
132
|
def proxy_connect_header
|
130
133
|
"CONNECT #{@uri.host}:#{@uri.port} HTTP/#{version}"
|
data/lib/http/request/writer.rb
CHANGED
@@ -7,11 +7,11 @@ module HTTP
|
|
7
7
|
# Types valid to be used as body source
|
8
8
|
VALID_BODY_TYPES = [String, NilClass, Enumerable]
|
9
9
|
|
10
|
-
def initialize(socket, body, headers,
|
10
|
+
def initialize(socket, body, headers, headline) # rubocop:disable ParameterLists
|
11
11
|
@body = body
|
12
12
|
@socket = socket
|
13
13
|
@headers = headers
|
14
|
-
@request_header = [
|
14
|
+
@request_header = [headline]
|
15
15
|
|
16
16
|
validate_body_type!
|
17
17
|
end
|
data/lib/http/version.rb
CHANGED
@@ -138,8 +138,8 @@ RSpec.describe HTTP::Request do
|
|
138
138
|
it { is_expected.to be_a HTTP::Request::Caching }
|
139
139
|
end
|
140
140
|
|
141
|
-
describe "#
|
142
|
-
subject { request.
|
141
|
+
describe "#headline" do
|
142
|
+
subject { request.headline }
|
143
143
|
|
144
144
|
it { is_expected.to eq "GET /foo?bar=baz#moo HTTP/1.1" }
|
145
145
|
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony Arcieri
|
8
8
|
- Erik Michaels-Ober
|
9
|
-
-
|
9
|
+
- Alexey V. Zapparov
|
10
|
+
- Zachary Anker
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2015-
|
14
|
+
date: 2015-05-06 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: http_parser.rb
|
@@ -180,45 +181,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
181
|
version: '0'
|
181
182
|
requirements: []
|
182
183
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.
|
184
|
+
rubygems_version: 2.2.2
|
184
185
|
signing_key:
|
185
186
|
specification_version: 4
|
186
187
|
summary: HTTP should be easy
|
187
|
-
test_files:
|
188
|
-
- spec/lib/http/cache/headers_spec.rb
|
189
|
-
- spec/lib/http/cache_spec.rb
|
190
|
-
- spec/lib/http/client_spec.rb
|
191
|
-
- spec/lib/http/content_type_spec.rb
|
192
|
-
- spec/lib/http/headers/mixin_spec.rb
|
193
|
-
- spec/lib/http/headers_spec.rb
|
194
|
-
- spec/lib/http/options/body_spec.rb
|
195
|
-
- spec/lib/http/options/form_spec.rb
|
196
|
-
- spec/lib/http/options/headers_spec.rb
|
197
|
-
- spec/lib/http/options/json_spec.rb
|
198
|
-
- spec/lib/http/options/merge_spec.rb
|
199
|
-
- spec/lib/http/options/new_spec.rb
|
200
|
-
- spec/lib/http/options/proxy_spec.rb
|
201
|
-
- spec/lib/http/options_spec.rb
|
202
|
-
- spec/lib/http/redirector_spec.rb
|
203
|
-
- spec/lib/http/request/caching_spec.rb
|
204
|
-
- spec/lib/http/request/writer_spec.rb
|
205
|
-
- spec/lib/http/request_spec.rb
|
206
|
-
- spec/lib/http/response/body_spec.rb
|
207
|
-
- spec/lib/http/response/caching_spec.rb
|
208
|
-
- spec/lib/http/response/io_body_spec.rb
|
209
|
-
- spec/lib/http/response/status_spec.rb
|
210
|
-
- spec/lib/http/response/string_body_spec.rb
|
211
|
-
- spec/lib/http/response_spec.rb
|
212
|
-
- spec/lib/http_spec.rb
|
213
|
-
- spec/spec_helper.rb
|
214
|
-
- spec/support/black_hole.rb
|
215
|
-
- spec/support/capture_warning.rb
|
216
|
-
- spec/support/connection_reuse_shared.rb
|
217
|
-
- spec/support/dummy_server.rb
|
218
|
-
- spec/support/dummy_server/servlet.rb
|
219
|
-
- spec/support/http_handling_shared.rb
|
220
|
-
- spec/support/proxy_server.rb
|
221
|
-
- spec/support/servers/config.rb
|
222
|
-
- spec/support/servers/runner.rb
|
223
|
-
- spec/support/ssl_helper.rb
|
188
|
+
test_files: []
|
224
189
|
has_rdoc:
|