http 0.9.2 → 0.9.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: ab9b540a68db221ff6f7fd5f82ba2b518c80bade
4
- data.tar.gz: 17062a814f863f5fc9c89b5dc3a9f13f785913f6
3
+ metadata.gz: 6d0fc648f6ef248aefe945523640200d4f0f77d2
4
+ data.tar.gz: e84a46fc898596c653dada5f8d8bcf82c5cc0eba
5
5
  SHA512:
6
- metadata.gz: 3894d6b7eb652f73d842492fe11efb2b15070cb9a6aa64759dcbd9bf3249e76c5e154bc453c123601922afcbcab02a8da9858daa0d55b37e9a9fef9ec20ec43e
7
- data.tar.gz: 54245ef8c606aec07ea913e33af03b0356e12fd573c6dff9b5bc952768c37985e44939634d5f81189b8964d117db9e24395ea1803b1f4d1fbfe82f4089c590b8
6
+ metadata.gz: cc8fa5eee19489bfcaa40a046e5699a8f7a99c439223041025348c30bc1e23ba1524692a17dc4d25ba6c1632a0df8923fb0e3f31908c4bdf226660a134ff67d1
7
+ data.tar.gz: 225d15b4e50168746f890d08be499a19ecdf39dc41e111e7471e720f8494d2f3eb305d50dcf1a5fe0f735a165168a53e927402ef4176ebe757780452c8fda334
data/CHANGES.md CHANGED
@@ -1,6 +1,15 @@
1
+ ## 0.9.3 (2015-08-19)
2
+
3
+ * Fixed request URI normalization. See #246. (@ixti)
4
+ - Avoids query component normalization
5
+ - Omits fragment component in headline
6
+
7
+
1
8
  ## 0.9.2 (2015-08-18)
9
+
2
10
  * Fixed exceptionless NIO EOF handling. (@zanker)
3
11
 
12
+
4
13
  ## 0.9.1 (2015-08-14)
5
14
 
6
15
  * Fix params special-chars escaping. See #246. (@ixti)
@@ -12,6 +21,11 @@
12
21
  * JRuby 9000 compatibility
13
22
 
14
23
 
24
+ ## 0.8.14 (2015-08-19)
25
+
26
+ * Backport request URI normalization fixes from master. (@ixti)
27
+
28
+
15
29
  ## 0.8.13 (2015-08-14)
16
30
 
17
31
  * Backport params special-chars escaping fix from `v0.9.1`. (@ixti)
@@ -66,7 +66,7 @@ module HTTP
66
66
  # :nodoc:
67
67
  def initialize(verb, uri, headers = {}, proxy = {}, body = nil, version = "1.1") # rubocop:disable ParameterLists
68
68
  @verb = verb.to_s.downcase.to_sym
69
- @uri = HTTP::URI.parse(uri).normalize
69
+ @uri = normalize_uri uri
70
70
  @scheme = @uri.scheme && @uri.scheme.to_s.downcase.to_sym
71
71
 
72
72
  fail(UnsupportedMethodError, "unknown method: #{verb}") unless METHODS.include?(@verb)
@@ -123,7 +123,7 @@ module HTTP
123
123
  # Compute HTTP request header for direct or proxy request
124
124
  def headline
125
125
  request_uri = using_proxy? ? uri : uri.omit(:scheme, :authority)
126
- "#{verb.to_s.upcase} #{request_uri} HTTP/#{version}"
126
+ "#{verb.to_s.upcase} #{request_uri.omit :fragment} HTTP/#{version}"
127
127
  end
128
128
 
129
129
  # @deprecated Will be removed in 1.0.0
@@ -172,5 +172,18 @@ module HTTP
172
172
  def default_host_header_value
173
173
  PORTS[@scheme] != port ? "#{host}:#{port}" : host
174
174
  end
175
+
176
+ # @return [HTTP::URI] URI with all componentes but query being normalized.
177
+ def normalize_uri(uri)
178
+ uri = HTTP::URI.parse uri
179
+
180
+ HTTP::URI.new(
181
+ :scheme => uri.normalized_scheme,
182
+ :authority => uri.normalized_authority,
183
+ :path => uri.normalized_path,
184
+ :query => uri.query,
185
+ :fragment => uri.normalized_fragment
186
+ )
187
+ end
175
188
  end
176
189
  end
@@ -2,10 +2,10 @@ require "addressable/uri"
2
2
 
3
3
  module HTTP
4
4
  class URI < Addressable::URI
5
- # HTTP scheme
5
+ # @private
6
6
  HTTP_SCHEME = "http".freeze
7
7
 
8
- # HTTPS scheme
8
+ # @private
9
9
  HTTPS_SCHEME = "https".freeze
10
10
 
11
11
  # @return [True] if URI is HTTP
@@ -19,5 +19,10 @@ module HTTP
19
19
  def https?
20
20
  HTTPS_SCHEME == scheme
21
21
  end
22
+
23
+ # @return [String] human-readable representation of URI
24
+ def inspect
25
+ format("#<%s:%#0x URI:%s>", self.class, object_id, to_s)
26
+ end
22
27
  end
23
28
  end
@@ -1,3 +1,3 @@
1
1
  module HTTP
2
- VERSION = "0.9.2".freeze
2
+ VERSION = "0.9.3".freeze
3
3
  end
@@ -1,7 +1,7 @@
1
1
  RSpec.describe HTTP::Request do
2
2
  let(:proxy) { {} }
3
3
  let(:headers) { {:accept => "text/html"} }
4
- let(:request_uri) { "http://example.com/foo?bar=baz#moo" }
4
+ let(:request_uri) { "http://example.com/foo?bar=baz" }
5
5
 
6
6
  subject(:request) { HTTP::Request.new(:get, request_uri, headers, proxy) }
7
7
 
@@ -134,13 +134,38 @@ RSpec.describe HTTP::Request do
134
134
  end
135
135
 
136
136
  describe "#headline" do
137
- subject { request.headline }
137
+ subject(:headline) { request.headline }
138
138
 
139
- it { is_expected.to eq "GET /foo?bar=baz#moo HTTP/1.1" }
139
+ it { is_expected.to eq "GET /foo?bar=baz HTTP/1.1" }
140
+
141
+ context "when URI contains encoded query" do
142
+ let(:encoded_query) { "t=1970-01-01T01%3A00%3A00%2B01%3A00" }
143
+ let(:request_uri) { "http://example.com/foo/?#{encoded_query}" }
144
+
145
+ it "does not unencodes query part" do
146
+ expect(headline).to eq "GET /foo/?#{encoded_query} HTTP/1.1"
147
+ end
148
+ end
149
+
150
+ context "when URI contains non-ASCII path" do
151
+ let(:request_uri) { "http://example.com/キョ" }
152
+
153
+ it "encodes non-ASCII path part" do
154
+ expect(headline).to eq "GET /%E3%82%AD%E3%83%A7 HTTP/1.1"
155
+ end
156
+ end
157
+
158
+ context "when URI contains fragment" do
159
+ let(:request_uri) { "http://example.com/foo#bar" }
160
+
161
+ it "omits fragment part" do
162
+ expect(headline).to eq "GET /foo HTTP/1.1"
163
+ end
164
+ end
140
165
 
141
166
  context "with proxy" do
142
167
  let(:proxy) { {:user => "user", :pass => "pass"} }
143
- it { is_expected.to eq "GET http://example.com/foo?bar=baz#moo HTTP/1.1" }
168
+ it { is_expected.to eq "GET http://example.com/foo?bar=baz HTTP/1.1" }
144
169
  end
145
170
  end
146
171
  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.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Arcieri
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-08-18 00:00:00.000000000 Z
14
+ date: 2015-08-19 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: http_parser.rb
@@ -183,39 +183,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 2.4.6
186
+ rubygems_version: 2.2.3
187
187
  signing_key:
188
188
  specification_version: 4
189
189
  summary: HTTP should be easy
190
- test_files:
191
- - spec/lib/http/client_spec.rb
192
- - spec/lib/http/content_type_spec.rb
193
- - spec/lib/http/headers/mixin_spec.rb
194
- - spec/lib/http/headers_spec.rb
195
- - spec/lib/http/options/body_spec.rb
196
- - spec/lib/http/options/form_spec.rb
197
- - spec/lib/http/options/headers_spec.rb
198
- - spec/lib/http/options/json_spec.rb
199
- - spec/lib/http/options/merge_spec.rb
200
- - spec/lib/http/options/new_spec.rb
201
- - spec/lib/http/options/proxy_spec.rb
202
- - spec/lib/http/options_spec.rb
203
- - spec/lib/http/redirector_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/status_spec.rb
208
- - spec/lib/http/response_spec.rb
209
- - spec/lib/http_spec.rb
210
- - spec/spec_helper.rb
211
- - spec/support/black_hole.rb
212
- - spec/support/capture_warning.rb
213
- - spec/support/connection_reuse_shared.rb
214
- - spec/support/dummy_server.rb
215
- - spec/support/dummy_server/servlet.rb
216
- - spec/support/http_handling_shared.rb
217
- - spec/support/proxy_server.rb
218
- - spec/support/servers/config.rb
219
- - spec/support/servers/runner.rb
220
- - spec/support/ssl_helper.rb
190
+ test_files: []
221
191
  has_rdoc: