http 0.8.2 → 0.8.3

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: 6175e5c7921354af3518483759cfa8f17066be03
4
- data.tar.gz: 6b58746ee974aaa0c3b05504ef315d20da2ed742
3
+ metadata.gz: 6855d98f9ce4716fb04fda587060dfcc2869b378
4
+ data.tar.gz: cc3dd5823219d9c1043d59a4ecd28783f3a54314
5
5
  SHA512:
6
- metadata.gz: 4a2ee6cd6011bc1cf78c0cdcd4b6a6361485fd2236f384f7ad5db2de9925deee7e4a817d4e2bca57140fb45d22fd7eb5e3fb0cfa0022e89345eaaa62408ced56
7
- data.tar.gz: 1f1c28bc91ec48cbd95df209ee6e205c0a08fbc245e409644d18bac9f7630fcad7fbbfefdc364778aaf437e8a3c081758de312019e003db6c2655f600efdd62d
6
+ metadata.gz: ac67b4ffeddb6b1fc1f53c8c9ccc75cae95dfa2fe834f7c9ef4f997734b846a4f380fdc61c8216239e95fa666b774f1083653193357006a31b7c83404747484b
7
+ data.tar.gz: 5a41152c4bf84a18db3b9bfe93dca7cb94d68176d0c02038efc21c8955915ebbf11a36535c867e762ddb09c7385ea9b235ac37d9fe2b605ce0ea6a20bb8495dc
@@ -57,6 +57,15 @@ Style/Lambda:
57
57
  Style/SingleSpaceBeforeFirstArg:
58
58
  Enabled: false
59
59
 
60
+ Style/SpaceAroundOperators:
61
+ MultiSpaceAllowedForOperators:
62
+ - "="
63
+ - "=>"
64
+ - "||"
65
+ - "||="
66
+ - "&&"
67
+ - "&&="
68
+
60
69
  Style/SpaceInsideHashLiteralBraces:
61
70
  EnforcedStyle: no_space
62
71
 
data/CHANGES.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.8.3 (2015-04-07)
2
+
3
+ * Fix request headline. See #206. (@ixti)
4
+ * Remove deprecated `Request#__method__`. (@ixti)
5
+
6
+
1
7
  ## 0.8.2 (2015-04-06)
2
8
 
3
9
  * Fix Celluloid::IO compatibility. See #203. (@ixti)
@@ -104,8 +104,8 @@ module HTTP
104
104
 
105
105
  # Verify our request isn't going to be made against another URI
106
106
  def verify_connection!(uri)
107
- if default_options.persistent? && base_host(uri) != default_options.persistent
108
- fail StateError, "Persistence is enabled for #{default_options.persistent}, but we got #{base_host(uri)}"
107
+ if default_options.persistent? && uri.origin != default_options.persistent
108
+ fail StateError, "Persistence is enabled for #{default_options.persistent}, but we got #{uri.origin}"
109
109
  # We re-create the connection object because we want to let prior requests
110
110
  # lazily load the body as long as possible, and this mimics prior functionality.
111
111
  elsif @connection && (!@connection.keep_alive? || @connection.expired?)
@@ -117,11 +117,6 @@ module HTTP
117
117
  end
118
118
  end
119
119
 
120
- # Strips out query/path to give us a consistent way of comparing hosts
121
- def base_host(uri)
122
- uri.omit(:query, :path).to_s
123
- end
124
-
125
120
  # Merges query params if needed
126
121
  #
127
122
  # @param [#to_s] uri
@@ -2,6 +2,7 @@ require "http/headers"
2
2
  require "openssl"
3
3
  require "socket"
4
4
  require "http/cache/null_cache"
5
+ require "http/uri"
5
6
 
6
7
  module HTTP
7
8
  class Options
@@ -81,6 +82,14 @@ module HTTP
81
82
  end
82
83
  end
83
84
 
85
+ def persistent=(value)
86
+ @persistent = value ? HTTP::URI.parse(value).origin : nil
87
+ end
88
+
89
+ def persistent?
90
+ !persistent.nil?
91
+ end
92
+
84
93
  def_option :cache do |cache_or_cache_options|
85
94
  if cache_or_cache_options.respond_to? :perform
86
95
  cache_or_cache_options
@@ -90,10 +99,6 @@ module HTTP
90
99
  end
91
100
  end
92
101
 
93
- def persistent?
94
- !persistent.nil? && persistent != ""
95
- end
96
-
97
102
  def [](option)
98
103
  send(option) rescue nil
99
104
  end
@@ -59,13 +59,6 @@ module HTTP
59
59
  # Scheme is normalized to be a lowercase symbol e.g. :http, :https
60
60
  attr_reader :scheme
61
61
 
62
- # The following alias may be removed in two minor versions (0.8.0) or one
63
- # major version (1.0.0)
64
- def __method__(*args)
65
- warn "#{Kernel.caller.first}: [DEPRECATION] HTTP::Request#__method__ is deprecated. Use #method instead."
66
- method(*args)
67
- end
68
-
69
62
  # "Request URI" as per RFC 2616
70
63
  # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html
71
64
  attr_reader :uri
@@ -74,7 +67,7 @@ module HTTP
74
67
  # :nodoc:
75
68
  def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
76
69
  @verb = verb.to_s.downcase.to_sym
77
- @uri = HTTP::URI.parse uri
70
+ @uri = HTTP::URI.parse(uri).normalize
78
71
  @scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym
79
72
 
80
73
  fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
@@ -119,7 +112,8 @@ module HTTP
119
112
 
120
113
  # Compute HTTP request header for direct or proxy request
121
114
  def request_header
122
- "#{verb.to_s.upcase} #{uri.normalize} HTTP/#{version}"
115
+ request_uri = using_proxy? ? uri : uri.omit(:scheme, :authority)
116
+ "#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
123
117
  end
124
118
 
125
119
  # Host for tcp socket
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "0.8.2"
2
+ VERSION = "0.8.3"
3
3
  end
@@ -1,8 +1,9 @@
1
1
  RSpec.describe HTTP::Request do
2
+ let(:proxy) { {} }
2
3
  let(:headers) { {:accept => "text/html"} }
3
- let(:request_uri) { "http://example.com/" }
4
+ let(:request_uri) { "http://example.com/foo?bar=baz#moo" }
4
5
 
5
- subject(:request) { HTTP::Request.new(:get, request_uri, headers) }
6
+ subject(:request) { HTTP::Request.new(:get, request_uri, headers, proxy) }
6
7
 
7
8
  it "includes HTTP::Headers::Mixin" do
8
9
  expect(described_class).to include HTTP::Headers::Mixin
@@ -21,13 +22,6 @@ RSpec.describe HTTP::Request do
21
22
  expect(subject.verb).to eq(:get)
22
23
  end
23
24
 
24
- it "provides a #__method__ method that outputs a deprecation warning and delegates to Object#method" do
25
- warning = capture_warning do
26
- expect(subject.__method__(:verb)).to eq(subject.method(:verb))
27
- end
28
- expect(warning).to match(/\[DEPRECATION\] HTTP::Request#__method__ is deprecated\. Use #method instead\.$/)
29
- end
30
-
31
25
  it "sets given headers" do
32
26
  expect(subject["Accept"]).to eq("text/html")
33
27
  end
@@ -143,4 +137,15 @@ RSpec.describe HTTP::Request do
143
137
  subject { request.caching }
144
138
  it { is_expected.to be_a HTTP::Request::Caching }
145
139
  end
140
+
141
+ describe "#request_header" do
142
+ subject { request.request_header }
143
+
144
+ it { is_expected.to eq "GET /foo?bar=baz#moo HTTP/1.1" }
145
+
146
+ context "with proxy" do
147
+ let(:proxy) { {:user => "user", :pass => "pass"} }
148
+ it { is_expected.to eq "GET http://example.com/foo?bar=baz#moo HTTP/1.1" }
149
+ end
150
+ end
146
151
  end
@@ -152,7 +152,7 @@ RSpec.describe HTTP do
152
152
  it "sets Authorization header with proper BasicAuth value" do
153
153
  client = HTTP.basic_auth :user => "foo", :pass => "bar"
154
154
  expect(client.default_headers[:authorization])
155
- .to match(/^Basic [A-Za-z0-9+\/]+=*$/)
155
+ .to match(%r{^Basic [A-Za-z0-9+/]+=*$})
156
156
  end
157
157
  end
158
158
 
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.2
4
+ version: 0.8.3
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-04-06 00:00:00.000000000 Z
13
+ date: 2015-04-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: http_parser.rb