http 0.6.0 → 0.6.1
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 +4 -4
- data/CHANGES.md +12 -2
- data/README.md +14 -12
- data/lib/http/client.rb +2 -1
- data/lib/http/mime_type.rb +1 -1
- data/lib/http/request/writer.rb +2 -2
- data/lib/http/response.rb +6 -0
- data/lib/http/response/body.rb +4 -2
- data/lib/http/version.rb +1 -1
- data/spec/http/client_spec.rb +1 -1
- data/spec/http/request/writer_spec.rb +18 -0
- data/spec/http/response/body_spec.rb +27 -9
- data/spec/http/response_spec.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b8b0bfe4eb9e5d2e91ca1bedb6a5af057481f0
|
4
|
+
data.tar.gz: 056c7f5f2e4ad84615a2e717e01ad332f4b63a21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c947f2225570316f16e42ffe86ec1a609b4e252c9267f2baa09c245437aa312978ce8be229d7048e3feeab9487ccec6c92e19b531f23a6d28afb393db798f81
|
7
|
+
data.tar.gz: a0dcc0530802bb055b30380fcc709a850d126e3ccd29ad91eb1fffddae56ae0319e2e69157e8e888c9cddc9c8d788b771a20bf75463a48231b119a42cfc026ff
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
|
-
0.6.
|
2
|
-
|
1
|
+
0.6.1 (2014-05-07)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Fix request `Content-Length` calculation for Unicode (@challengeechallengee)
|
5
|
+
* Add `Response#flush` (@ixti)
|
6
|
+
* Fix `Response::Body#readpartial` default size (@hannesg, @ixti)
|
7
|
+
* Add missing `CRLF` for chunked bodies (@hannesg)
|
8
|
+
* Fix forgotten CGI require (@ixti)
|
9
|
+
* Improve README (@tarcieri)
|
10
|
+
|
11
|
+
0.6.0 (2014-04-04)
|
12
|
+
------------------
|
3
13
|
|
4
14
|
* Rename `HTTP::Request#method` to `HTTP::Request#verb` (@krainboltgreene)
|
5
15
|
* Add `HTTP::ResponseBody` class (@tarcieri)
|
data/README.md
CHANGED
@@ -23,6 +23,20 @@ extension based on the Node.js parser and a Java port thereof.
|
|
23
23
|
[requests]: http://docs.python-requests.org/en/latest/
|
24
24
|
[http_parser.rb]: https://github.com/tmm1/http_parser.rb
|
25
25
|
|
26
|
+
Help and Discussion
|
27
|
+
-------------------
|
28
|
+
|
29
|
+
If you need help or just want to talk about the Ruby HTTP Gem, [visit our Google
|
30
|
+
Group][googlegroup], or join by email by sending a message to:
|
31
|
+
[ruby-http-gem+subscribe@googlegroups.com][subscribe].
|
32
|
+
|
33
|
+
[googlegroup]: https://groups.google.com/forum/#!forum/ruby-http-gem
|
34
|
+
[subscribe]: mailto:ruby-http-gem+subscribe@googlegroups.com
|
35
|
+
|
36
|
+
If you believe you've found a bug, please report it at:
|
37
|
+
|
38
|
+
https://github.com/tarcieri/http/issues
|
39
|
+
|
26
40
|
Installation
|
27
41
|
------------
|
28
42
|
|
@@ -50,18 +64,6 @@ Documentation
|
|
50
64
|
[Please see the HTTP Gem Wiki](https://github.com/tarcieri/http/wiki)
|
51
65
|
for more detailed documentation and usage notes.
|
52
66
|
|
53
|
-
Support
|
54
|
-
-------
|
55
|
-
|
56
|
-
For help with The HTTP Gem, either open a [Github Issue] or discuss it
|
57
|
-
on the Celluloid mailing list:
|
58
|
-
|
59
|
-
http://groups.google.com/group/celluloid-ruby
|
60
|
-
|
61
|
-
You can also find us on IRC at #celluloid on freenode
|
62
|
-
|
63
|
-
[Github Issue]: https://github.com/tarcieri/http/issues
|
64
|
-
|
65
67
|
Basic Usage
|
66
68
|
-----------
|
67
69
|
|
data/lib/http/client.rb
CHANGED
data/lib/http/mime_type.rb
CHANGED
data/lib/http/request/writer.rb
CHANGED
@@ -35,7 +35,7 @@ module HTTP
|
|
35
35
|
# with
|
36
36
|
def add_body_type_headers
|
37
37
|
if @body.is_a?(String) && !@headers['Content-Length']
|
38
|
-
@request_header << "Content-Length: #{@body.
|
38
|
+
@request_header << "Content-Length: #{@body.bytesize}"
|
39
39
|
elsif @body.is_a?(Enumerable)
|
40
40
|
encoding = @headers['Transfer-Encoding']
|
41
41
|
if encoding == 'chunked'
|
@@ -68,7 +68,7 @@ module HTTP
|
|
68
68
|
elsif @body.is_a?(Enumerable)
|
69
69
|
@body.each do |chunk|
|
70
70
|
@socket << chunk.bytesize.to_s(16) << CRLF
|
71
|
-
@socket << chunk
|
71
|
+
@socket << chunk << CRLF
|
72
72
|
end
|
73
73
|
|
74
74
|
@socket << '0' << CRLF * 2
|
data/lib/http/response.rb
CHANGED
data/lib/http/response/body.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'forwardable'
|
2
|
+
require 'http/client'
|
2
3
|
|
3
4
|
module HTTP
|
4
5
|
class Response
|
@@ -15,9 +16,10 @@ module HTTP
|
|
15
16
|
end
|
16
17
|
|
17
18
|
# Read up to length bytes, but return any data that's available
|
18
|
-
|
19
|
+
# @see HTTP::Client#readpartial
|
20
|
+
def readpartial(*args)
|
19
21
|
stream!
|
20
|
-
@client.readpartial(
|
22
|
+
@client.readpartial(*args)
|
21
23
|
end
|
22
24
|
|
23
25
|
# Iterate over the body, allowing it to be enumerable
|
data/lib/http/version.rb
CHANGED
data/spec/http/client_spec.rb
CHANGED
@@ -91,7 +91,7 @@ describe HTTP::Client do
|
|
91
91
|
|
92
92
|
it 'merges duplicate values' do
|
93
93
|
expect(HTTP::Request).to receive(:new) do |_, uri|
|
94
|
-
expect(
|
94
|
+
expect(uri.query).to match(/^(a=1&a=2|a=2&a=1)$/)
|
95
95
|
end
|
96
96
|
|
97
97
|
client.get('http://example.com/?a=1', :params => {:a => 2})
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe HTTP::Request::Writer do
|
@@ -21,5 +23,21 @@ describe HTTP::Request::Writer do
|
|
21
23
|
it "does throw on a body that isn't string, enumerable or nil" do
|
22
24
|
expect { construct true }.to raise_error
|
23
25
|
end
|
26
|
+
|
27
|
+
it 'writes a chunked request from an Enumerable correctly' do
|
28
|
+
io = StringIO.new
|
29
|
+
writer = HTTP::Request::Writer.new(io, %w[bees cows], [], '')
|
30
|
+
writer.send_request_body
|
31
|
+
io.rewind
|
32
|
+
expect(io.string).to eq "4\r\nbees\r\n4\r\ncows\r\n0\r\n\r\n"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#add_body_type_headers' do
|
37
|
+
it 'properly calculates length of unicode string' do
|
38
|
+
writer = HTTP::Request::Writer.new(nil, 'Привет, мир!', {}, '')
|
39
|
+
writer.add_body_type_headers
|
40
|
+
expect(writer.join_headers).to match(/\r\nContent-Length: 21\r\n/)
|
41
|
+
end
|
24
42
|
end
|
25
43
|
end
|
@@ -1,24 +1,42 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe HTTP::Response::Body do
|
4
|
-
let(:
|
5
|
-
let(:
|
4
|
+
let(:client) { double }
|
5
|
+
let(:chunks) { ['Hello, ', 'World!'] }
|
6
6
|
|
7
|
-
|
7
|
+
before { allow(client).to receive(:readpartial) { chunks.shift } }
|
8
8
|
|
9
|
-
|
10
|
-
response.should_receive(:readpartial).and_return(body)
|
11
|
-
response.should_receive(:readpartial).and_return(nil)
|
12
|
-
end
|
9
|
+
subject(:body) { described_class.new client }
|
13
10
|
|
14
11
|
it 'streams bodies from responses' do
|
15
|
-
expect(subject.to_s).to eq
|
12
|
+
expect(subject.to_s).to eq 'Hello, World!'
|
16
13
|
end
|
17
14
|
|
18
15
|
context 'when body empty' do
|
19
|
-
let(:
|
16
|
+
let(:chunks) { [''] }
|
17
|
+
|
20
18
|
it 'returns responds to empty? with true' do
|
21
19
|
expect(subject).to be_empty
|
22
20
|
end
|
23
21
|
end
|
22
|
+
|
23
|
+
describe '#readpartial' do
|
24
|
+
context 'with size given' do
|
25
|
+
it 'passes value to underlying client' do
|
26
|
+
expect(client).to receive(:readpartial).with(42)
|
27
|
+
body.readpartial 42
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without size given' do
|
32
|
+
it 'does not blows up' do
|
33
|
+
expect { body.readpartial }.to_not raise_error
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'calls underlying client readpartial without specific size' do
|
37
|
+
expect(client).to receive(:readpartial).with no_args
|
38
|
+
body.readpartial
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
24
42
|
end
|
data/spec/http/response_spec.rb
CHANGED
@@ -83,4 +83,18 @@ describe HTTP::Response do
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
describe '#flush' do
|
88
|
+
let(:body) { double :to_s => '' }
|
89
|
+
let(:response) { HTTP::Response.new 200, '1.1', {}, body }
|
90
|
+
|
91
|
+
it 'returns response self-reference' do
|
92
|
+
expect(response.flush).to be response
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'flushes body' do
|
96
|
+
expect(body).to receive :to_s
|
97
|
+
response.flush
|
98
|
+
end
|
99
|
+
end
|
86
100
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tony
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: http_parser.rb
|