http 0.8.0.pre → 0.8.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a705cb32b18d35b7b100eea0ac6f6687c8e9140e
4
- data.tar.gz: fff73981101e4bc7a80faeded4d8bde937dd0fa4
3
+ metadata.gz: 45b099ff52ab956294dec51a54255554865482cd
4
+ data.tar.gz: 3bb79e8bc7633787cbb7b8444d0a750d9709663e
5
5
  SHA512:
6
- metadata.gz: 32e0571165aff841356c98fdea9135c6e746a36527f7f7db566effb2321d58dc287b26efbd9651c961cb675fc0621333a12cd0608e3b9cc5a57b0259f220d13d
7
- data.tar.gz: 7b90b9fba3136f9732667dbae22a561b3f338a11f86e70878494d11b657d7cc64e19403ceb1a5898a844c886e384ae31752cf894527404279d3c5d6b79a4cf96
6
+ metadata.gz: b3422f58b0d5d584c9ba8f88f20d24852a4b7aedd4e0f1e640b76e3b70a31c0c404036790ae3cc09991c34644dda22e031d5e5394c393d245b545d7c80c80219
7
+ data.tar.gz: 29e37aff0f285a68671ee35498a955c9b00abba6d39ed43877213db84598ac7c802662e1b2d5c6d98bfd9fa2772c2b34732b797511129d95fba96a55a421beb3
data/CHANGES.md CHANGED
@@ -1,6 +1,7 @@
1
- ## 0.8.0.pre (2015-03-26)
1
+ ## 0.8.0.pre2 (2015-03-27)
2
2
 
3
- * Support for persistent HTTP connections
3
+ * Support for persistent HTTP connections (@zanker)
4
+ * Add caching support. See #77 and #177. (@Asmod4n, @pezra)
4
5
  * Improve servers used in specs boot up. Issue was initially raised up
5
6
  by @olegkovalenko. See #176.
6
7
  * Reflect FormData rename changes (FormData -> HTTP::FormData). (@ixti)
data/lib/http/client.rb CHANGED
@@ -75,14 +75,16 @@ module HTTP
75
75
  # On any exception we reset the conn. This is a safety measure, to ensure
76
76
  # we don't have conns in a bad state resulting in mixed requests/responses
77
77
  rescue
78
- if default_options.persistent? && @connection
79
- @connection.close
80
- @connection = nil
81
- end
78
+ close if default_options.persistent?
82
79
 
83
80
  raise
84
81
  end
85
82
 
83
+ def close
84
+ @connection.close if @connection
85
+ @connection = nil
86
+ end
87
+
86
88
  private
87
89
 
88
90
  # Verify our request isn't going to be made against another URI
@@ -93,7 +95,7 @@ module HTTP
93
95
  # We re-create the connection object because we want to let prior requests
94
96
  # lazily load the body as long as possible, and this mimics prior functionality.
95
97
  elsif !default_options.persistent? || (@connection && !@connection.keep_alive?)
96
- @connection = nil
98
+ close
97
99
  end
98
100
  end
99
101
 
@@ -4,7 +4,7 @@ module HTTP
4
4
  # A connection to the HTTP server
5
5
  class Connection
6
6
  attr_reader :socket, :parser, :persistent,
7
- :pending_request, :pending_response, :sequence_id
7
+ :pending_request, :pending_response
8
8
 
9
9
  # Attempt to read this much data
10
10
  BUFFER_SIZE = 16_384
@@ -13,7 +13,6 @@ module HTTP
13
13
  @persistent = options.persistent?
14
14
 
15
15
  @parser = Response::Parser.new
16
- @sequence_id = 0
17
16
 
18
17
  @socket = options[:socket_class].open(req.socket_host, req.socket_port)
19
18
 
@@ -22,14 +21,13 @@ module HTTP
22
21
 
23
22
  # Send a request to the server
24
23
  def send_request(req)
25
- if pending_request
26
- fail StateError, "Tried to send a request while one is pending already. This cannot be called from multiple threads!"
24
+ if pending_response
25
+ fail StateError, "Tried to send a request while one is pending already. Make sure you read off the body."
27
26
  elsif pending_request
28
27
  fail StateError, "Tried to send a request while a response is pending. Make sure you've fully read the body from the request."
29
28
  end
30
29
 
31
30
  @pending_request = true
32
- @sequence_id += 1
33
31
 
34
32
  req.stream socket
35
33
 
@@ -13,13 +13,10 @@ module HTTP
13
13
  @client = client
14
14
  @streaming = nil
15
15
  @contents = nil
16
- @active_seq = client.sequence_id
17
16
  end
18
17
 
19
18
  # (see HTTP::Client#readpartial)
20
19
  def readpartial(*args)
21
- check_sequence!
22
-
23
20
  stream!
24
21
  @client.readpartial(*args)
25
22
  end
@@ -36,7 +33,6 @@ module HTTP
36
33
  return @contents if @contents
37
34
 
38
35
  fail StateError, "body is being streamed" unless @streaming.nil?
39
- check_sequence!
40
36
 
41
37
  begin
42
38
  @streaming = false
@@ -53,14 +49,6 @@ module HTTP
53
49
  end
54
50
  alias_method :to_str, :to_s
55
51
 
56
- def check_sequence!
57
- return unless @active_seq != @client.sequence_id
58
-
59
- fail StateError, "Sequence ID #{@active_seq} does not match #{@client.sequence_id}. You must read the entire request off."
60
- end
61
-
62
- private :check_sequence!
63
-
64
52
  # Assert that the body is actively being streamed
65
53
  def stream!
66
54
  fail StateError, "body has already been consumed" if @streaming == false
data/lib/http/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "0.8.0.pre"
2
+ VERSION = "0.8.0.pre2"
3
3
  end
@@ -23,14 +23,8 @@ RSpec.shared_context "handles shared connections" do
23
23
 
24
24
  context "when trying to read a stale body" do
25
25
  it "errors" do
26
- first_res = client.get(server.endpoint)
27
- second_res = client.get(server.endpoint)
28
-
29
- # This should work, because it's the last request we made
30
- expect(second_res.body.to_s).to eq("<!doctype html>")
31
-
32
- # This should not work because we've not read anything
33
- expect { first_res.body.to_s }.to raise_error(HTTP::StateError, /Sequence ID 1 does not match 2/i)
26
+ client.get("#{server.endpoint}/not-found")
27
+ expect { client.get(server.endpoint) }.to raise_error(HTTP::StateError, /Tried to send a request/)
34
28
  end
35
29
  end
36
30
 
@@ -46,19 +40,6 @@ RSpec.shared_context "handles shared connections" do
46
40
  end
47
41
  end
48
42
 
49
- context "when streaming" do
50
- it "errors with a stale response" do
51
- first_res = client.get(server.endpoint)
52
- second_res = client.get(server.endpoint)
53
-
54
- # This should work, because it's the last request we made
55
- expect(second_res.body.to_s).to eq("<!doctype html>")
56
-
57
- # This should not work because we've not read anything
58
- expect { first_res.body.each(&:to_s) }.to raise_error(HTTP::StateError, /Sequence ID 1 does not match 2/i)
59
- end
60
- end
61
-
62
43
  context "with a socket issue" do
63
44
  it "transparently reopens" do
64
45
  first_socket = client.get("#{server.endpoint}/socket").body.to_s
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.8.0.pre
4
+ version: 0.8.0.pre2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-03-26 00:00:00.000000000 Z
13
+ date: 2015-03-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http_parser.rb
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  version: 1.3.1
162
162
  requirements: []
163
163
  rubyforge_project:
164
- rubygems_version: 2.4.6
164
+ rubygems_version: 2.4.5
165
165
  signing_key:
166
166
  specification_version: 4
167
167
  summary: HTTP should be easy