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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c81e2f4f9a7626fd58b225bf69772a47bf361c6
4
- data.tar.gz: 31f9bb1e4ceb3494898604e1724de240b8237e43
3
+ metadata.gz: b8b8b0bfe4eb9e5d2e91ca1bedb6a5af057481f0
4
+ data.tar.gz: 056c7f5f2e4ad84615a2e717e01ad332f4b63a21
5
5
  SHA512:
6
- metadata.gz: 637b115774a74b54c7dcede1ab6c4fde01638f329c51dedc83b8ad2cb1129983a888b2aef2442e00a8f68bc36dba614710ec645c009ba3bb47551a8630069add
7
- data.tar.gz: b9b86db8e595bc6bb09862bc9e2f8e529e8e2e2b0c0599214ea24f816e8a30cf948bc5f405d143501cdce5475cf1e2971cf376e46b50dc95a3943adebf00f207
6
+ metadata.gz: 8c947f2225570316f16e42ffe86ec1a609b4e252c9267f2baa09c245437aa312978ce8be229d7048e3feeab9487ccec6c92e19b531f23a6d28afb393db798f81
7
+ data.tar.gz: a0dcc0530802bb055b30380fcc709a850d126e3ccd29ad91eb1fffddae56ae0319e2e69157e8e888c9cddc9c8d788b771a20bf75463a48231b119a42cfc026ff
data/CHANGES.md CHANGED
@@ -1,5 +1,15 @@
1
- 0.6.0
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
@@ -1,6 +1,7 @@
1
+ require 'cgi'
2
+ require 'uri'
1
3
  require 'http/options'
2
4
  require 'http/redirector'
3
- require 'uri'
4
5
 
5
6
  module HTTP
6
7
  # Clients make requests and receive responses
@@ -31,7 +31,7 @@ module HTTP
31
31
  #
32
32
  # @param [#to_s] type
33
33
  # @raise [Error] if no adapter found
34
- # @return [void]
34
+ # @return [Class]
35
35
  def [](type)
36
36
  adapters[normalize type] || fail(Error, "Unknown MIME type: #{type}")
37
37
  end
@@ -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.length}"
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
@@ -95,6 +95,12 @@ module HTTP
95
95
  end
96
96
  alias_method :to_str, :to_s
97
97
 
98
+ # Flushes body and returns self-reference
99
+ def flush
100
+ body.to_s
101
+ self
102
+ end
103
+
98
104
  # Parsed Content-Type header
99
105
  # @return [HTTP::ContentType]
100
106
  def content_type
@@ -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
- def readpartial(length = nil)
19
+ # @see HTTP::Client#readpartial
20
+ def readpartial(*args)
19
21
  stream!
20
- @client.readpartial(length)
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
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
@@ -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(CGI.parse uri.query).to eq('a' => %w[1 2])
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(:body) { 'Hello, world!' }
5
- let(:response) { double(:response) }
4
+ let(:client) { double }
5
+ let(:chunks) { ['Hello, ', 'World!'] }
6
6
 
7
- subject { described_class.new(response) }
7
+ before { allow(client).to receive(:readpartial) { chunks.shift } }
8
8
 
9
- before do
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 body
12
+ expect(subject.to_s).to eq 'Hello, World!'
16
13
  end
17
14
 
18
15
  context 'when body empty' do
19
- let(:body) { '' }
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
@@ -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.0
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-04-04 00:00:00.000000000 Z
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