http.rb 0.18.0 → 0.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8f29700e5af2badc9a6207ce6c3cf5ce189c6e282da3955535139b2014c1092
4
- data.tar.gz: 121be70186382dab28df52b69f7a2e5c9501bb5891946865621250e63e85f952
3
+ metadata.gz: 5cdc1621048e0c428eb0b0c2ae81ae534921007746d58b426cc1185e6a77557a
4
+ data.tar.gz: 80f9b3f58b9c410093e74243b6a23ac364a50c3579c47ddf51e3e77e9b80a769
5
5
  SHA512:
6
- metadata.gz: b2a0ed184928d0f3656d8d9d28bcb37098759f94cf37f708c931b020c920d2d2c8f50a5a7856dcb1827759c3d8a917e5824b7266217861f21daca202533003c3
7
- data.tar.gz: 22525a1fa099e471895bfe8cc660c728c3fcc52067b24849079b1f0c3c0e9ed50e64359c92d46de2aed7557b72d4855b39b93ab652a3fd2da122c9e5c3704df7
6
+ metadata.gz: 63d22c4b9ed0a909a8a72dcf9cf00f44d0aad730f5e6bdd0aef6a70616bf27b12b81737ee71f5e5d368d46142355fe7046cafe633d5e6b3b744b4c19c8e42d16
7
+ data.tar.gz: f5bc846fae0969a4892926c1d739a549de54dc1a4765a4996bcbf56144c4d56bfedfb1044fd7399d3cfcfb7cfcd4ee4eca88c11c8c93433b665f1094d96ddd2f
data/CHANGELOG CHANGED
@@ -1,3 +1,25 @@
1
+ # CHANGELOG
2
+
3
+ # 20260520
4
+ # 0.18.2: Fix relative redirect URL construction.
5
+ 1. ~ HTTP.request: Use URI#merge for redirect URL construction. Preserves original scheme, elides default ports, and resolves relative paths per RFC 3986.
6
+ 2. ~ spec/HTTP/get_spec.rb: Update relative-redirect stubs to elide default port; + context for HTTPS relative redirect.
7
+ 3. ~ spec/HTTP/post_spec.rb: Update relative-redirect stubs to elide default port.
8
+ 4. ~ spec/HTTP/put_spec.rb: Update relative-redirect stubs to elide default port.
9
+ 5. ~ spec/HTTP/delete_spec.rb: Update relative-redirect stubs to elide default port.
10
+ 6. ~ HTTP::VERSION: /0.18.1/0.18.2/
11
+ 7. ~ CHANGELOG: + 0.18.2 entry
12
+
13
+ # 20260508
14
+ # 0.18.1: Remove incorrectly added WebDAV verbs.
15
+ 1. - lib/Net/HTTP/Report.rb
16
+ 2. ~ HTTP::VERBS: - require_relative '../Net/HTTP/Report'
17
+ 3. ~ HTTP::VERBS::WITH_BODY: - propfind, proppatch, mkcol, copy, move, lock, unlock, report
18
+ 4. - spec/HTTP/propfind_spec.rb
19
+ 5. - spec/Net/HTTP/Report_spec.rb
20
+ 6. ~ HTTP::VERSION: /0.18.0/0.18.1/
21
+ 7. ~ CHANGELOG: + 0.18.1 entry
22
+
1
23
  # 20260507
2
24
  # 0.18.0: Add all missing HTTP verbs; use meta-programming to define verb methods.
3
25
  1. + HTTP/verbs.rb; including:
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # http
2
2
 
3
- ## Description
4
-
5
3
  For many years this was a personal library, from around the middle of 2009 from what I can ascertain, though in various guises it may have been as early as late 2007.
6
4
 
7
5
  Like many others before and after me with their respective libraries, I created it to simplify the heinous interface that is Net::HTTP. At the time of it's original creation I was doing a lot of a webscraping and didn't want a half-dozen line setup to make simple requests. It has stood the test of time, for me personally insofar as the interface remaining simpler than most other similar libraries, though it is also less full featured, but nevertheless for it's tiny size it packs in quite a bit.
@@ -247,7 +245,7 @@ verify_mode
247
245
 
248
246
  ## Contributing
249
247
 
250
- 1. Fork it ( https://github.com/thoran/http/fork )
248
+ 1. Fork it [https://github.com/thoran/http/fork](https://github.com/thoran/http/fork)
251
249
  2. Create your feature branch (`git checkout -b my-new-feature`)
252
250
  3. Commit your changes (`git commit -am 'Add some feature'`)
253
251
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/HTTP/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '0.18.0'
5
+ VERSION = '0.18.2'
6
6
  end
data/lib/HTTP/request.rb CHANGED
@@ -27,13 +27,8 @@ module HTTP
27
27
  elsif no_redirect
28
28
  return response
29
29
  end
30
- redirect_uri = URI.parse(response.header['location'])
31
- if redirect_uri.scheme
32
- response = get(response.header['location'], {}, {}, options, &block)
33
- else
34
- new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
35
- response = get(new_location, {}, {}, options, &block)
36
- end
30
+ redirect_uri = uri.merge(response.header['location'])
31
+ response = get(redirect_uri.to_s, {}, {}, options, &block)
37
32
  end
38
33
  if block_given?
39
34
  yield response
data/lib/HTTP/verbs.rb CHANGED
@@ -5,14 +5,13 @@ require 'json'
5
5
  require 'net/http'
6
6
 
7
7
  require_relative '../Hash/x_www_form_urlencode'
8
- require_relative '../Net/HTTP/Report'
9
8
  require_relative './request'
10
9
  require_relative '../String/to_const'
11
10
 
12
11
  module HTTP
13
12
  module VERBS
14
13
  WITHOUT_BODY = %i{get delete head options trace}
15
- WITH_BODY = %i{post put patch propfind proppatch mkcol copy move lock unlock report}
14
+ WITH_BODY = %i{post put patch}
16
15
  end
17
16
 
18
17
  VERBS::WITHOUT_BODY.each do |verb|
@@ -173,7 +173,7 @@ describe ".delete" do
173
173
  context "with path only redirection" do
174
174
  let(:request_uri){'http://example.com/path'}
175
175
  let(:redirect_path){'/new_path'}
176
- let(:redirect_uri){"http://example.com:80#{redirect_path}"}
176
+ let(:redirect_uri){"http://example.com#{redirect_path}"}
177
177
 
178
178
  before do
179
179
  stub_request(:get, redirect_uri).
@@ -173,7 +173,7 @@ describe ".get" do
173
173
  context "with path only redirection" do
174
174
  let(:request_uri){'http://example.com/path'}
175
175
  let(:redirect_path){'/new_path'}
176
- let(:redirect_uri){"http://example.com:80#{redirect_path}"}
176
+ let(:redirect_uri){"http://example.com#{redirect_path}"}
177
177
 
178
178
  before do
179
179
  stub_request(:get, redirect_uri).
@@ -212,6 +212,28 @@ describe ".get" do
212
212
  end
213
213
  end
214
214
 
215
+ context "with path only redirection from HTTPS" do
216
+ let(:request_uri){'https://example.com/path'}
217
+ let(:redirect_path){'/new_path'}
218
+ let(:redirect_uri){"https://example.com#{redirect_path}"}
219
+
220
+ before do
221
+ stub_request(:get, redirect_uri).
222
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
223
+ to_return(status: 200, body: '', headers: {})
224
+ stub_request(:get, request_uri).
225
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
226
+ to_return(status: 301, body: '', headers: {'location' => redirect_path})
227
+ end
228
+
229
+ it "preserves the HTTPS scheme on a relative redirect" do
230
+ expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
231
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: true, verify_mode: 0}).and_call_original
232
+ response = HTTP.get(request_uri)
233
+ expect(response.success?).to eq(true)
234
+ end
235
+ end
236
+
215
237
  context "no_redirect true" do
216
238
  let(:request_uri){'http://example.com/path'}
217
239
  let(:redirect_uri){'http://redirected.com'}
@@ -311,7 +311,7 @@ describe ".post" do
311
311
  context "with path only redirection" do
312
312
  let(:request_uri){'http://example.com/path'}
313
313
  let(:redirect_path){'/new_path'}
314
- let(:redirect_uri){"http://example.com:80#{redirect_path}"}
314
+ let(:redirect_uri){"http://example.com#{redirect_path}"}
315
315
 
316
316
  before do
317
317
  stub_request(:get, redirect_uri).
@@ -311,7 +311,7 @@ describe ".put" do
311
311
  context "with path only redirection" do
312
312
  let(:request_uri){'http://example.com/path'}
313
313
  let(:redirect_path){'/new_path'}
314
- let(:redirect_uri){"http://example.com:80#{redirect_path}"}
314
+ let(:redirect_uri){"http://example.com#{redirect_path}"}
315
315
 
316
316
  before do
317
317
  stub_request(:get, redirect_uri).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -79,11 +79,11 @@ files:
79
79
  - README.md
80
80
  - Rakefile
81
81
  - http.rb.gemspec
82
+ - lib/HTTP.rb
82
83
  - lib/HTTP/VERSION.rb
83
84
  - lib/HTTP/request.rb
84
85
  - lib/HTTP/verbs.rb
85
86
  - lib/Hash/x_www_form_urlencode.rb
86
- - lib/Net/HTTP/Report.rb
87
87
  - lib/Net/HTTP/set_options.rb
88
88
  - lib/Net/HTTPRequest/set_headers.rb
89
89
  - lib/Net/HTTPResponse/StatusPredicates.rb
@@ -93,14 +93,11 @@ files:
93
93
  - lib/Thoran/Array/FirstX/firstX.rb
94
94
  - lib/Thoran/String/ToConst/to_const.rb
95
95
  - lib/URI/Generic/use_sslQ.rb
96
- - lib/http.rb
97
96
  - spec/HTTP/delete_spec.rb
98
97
  - spec/HTTP/get_spec.rb
99
98
  - spec/HTTP/head_spec.rb
100
99
  - spec/HTTP/post_spec.rb
101
- - spec/HTTP/propfind_spec.rb
102
100
  - spec/HTTP/put_spec.rb
103
- - spec/Net/HTTP/Report_spec.rb
104
101
  - spec/spec_helper.rb
105
102
  homepage: http://github.com/thoran/HTTP
106
103
  licenses:
@@ -120,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
117
  - !ruby/object:Gem::Version
121
118
  version: '0'
122
119
  requirements: []
123
- rubygems_version: 4.0.11
120
+ rubygems_version: 4.0.12
124
121
  specification_version: 4
125
122
  summary: HTTP made easy.
126
123
  test_files: []
@@ -1,14 +0,0 @@
1
- # Net/HTTP/Report.rb
2
- # Net::HTTP::Report
3
-
4
- require 'net/http'
5
-
6
- module Net
7
- class HTTP
8
- class Report < Net::HTTPRequest
9
- METHOD = 'REPORT'
10
- REQUEST_HAS_BODY = true
11
- RESPONSE_HAS_BODY = true
12
- end
13
- end
14
- end
@@ -1,122 +0,0 @@
1
- # spec/HTTP/propfind_spec.rb
2
-
3
- require_relative '../spec_helper'
4
- require 'http'
5
-
6
- describe ".propfind" do
7
- context "with uri-only supplied" do
8
- before do
9
- stub_request(:propfind, 'http://example.com/dav/').
10
- to_return(status: 207, body: '<multistatus/>', headers: {})
11
- end
12
-
13
- context "uri as a string" do
14
- let(:uri){'http://example.com/dav/'}
15
-
16
- it "returns a response" do
17
- response = HTTP.propfind(uri)
18
- expect(response.code).to eq('207')
19
- end
20
- end
21
-
22
- context "uri as a URI" do
23
- let(:uri){URI.parse('http://example.com/dav/')}
24
-
25
- it "returns a response" do
26
- response = HTTP.propfind(uri)
27
- expect(response.code).to eq('207')
28
- end
29
- end
30
- end
31
-
32
- context "with an XML body" do
33
- let(:uri){'http://example.com/dav/'}
34
- let(:xml) do
35
- '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:"><d:prop><d:displayname/></d:prop></d:propfind>'
36
- end
37
-
38
- before do
39
- stub_request(:propfind, 'http://example.com/dav/').
40
- with(body: xml).
41
- to_return(status: 207, body: '<multistatus/>', headers: {})
42
- end
43
-
44
- it "sends the XML body" do
45
- response = HTTP.propfind(uri, xml, {'Content-Type' => 'application/xml'})
46
- expect(response.code).to eq('207')
47
- end
48
- end
49
-
50
- context "with headers supplied" do
51
- let(:uri){'http://example.com/dav/'}
52
-
53
- before do
54
- stub_request(:propfind, 'http://example.com/dav/').
55
- with(headers: {'Depth' => '1', 'Content-Type' => 'application/xml'}).
56
- to_return(status: 207, body: '<multistatus/>', headers: {})
57
- end
58
-
59
- it "sets the headers on the request" do
60
- response = HTTP.propfind(uri, {}, {'Depth' => '1', 'Content-Type' => 'application/xml'})
61
- expect(response.code).to eq('207')
62
- end
63
- end
64
-
65
- context "with options supplied" do
66
- let(:uri){'http://example.com/dav/'}
67
-
68
- before do
69
- stub_request(:propfind, 'https://example.com:80/dav/').
70
- to_return(status: 207, body: '<multistatus/>', headers: {})
71
- end
72
-
73
- it "sets the use_ssl option on the Net::HTTP instance" do
74
- response = HTTP.propfind(uri, {}, {}, {use_ssl: true})
75
- expect(response.code).to eq('207')
76
- end
77
- end
78
-
79
- context "with block supplied" do
80
- let(:uri){'http://example.com/dav/'}
81
-
82
- before do
83
- stub_request(:propfind, 'http://example.com/dav/').
84
- to_return(status: 207, body: '<multistatus/>', headers: {})
85
- end
86
-
87
- it "yields an instance of Net::HTTPResponse" do
88
- expect{|b| HTTP.propfind(uri, &b)}.to yield_with_args(Net::HTTPResponse)
89
- end
90
- end
91
-
92
- context "with redirection" do
93
- let(:request_uri){'http://example.com/dav/'}
94
- let(:redirect_uri){'http://redirected.com/dav/'}
95
-
96
- before do
97
- stub_request(:propfind, request_uri).
98
- to_return(status: 301, headers: {'location' => redirect_uri})
99
- stub_request(:get, redirect_uri).
100
- to_return(status: 200, body: '', headers: {})
101
- end
102
-
103
- it "follows the redirect" do
104
- response = HTTP.propfind(request_uri)
105
- expect(response.success?).to eq(true)
106
- end
107
- end
108
-
109
- context "no_redirect true" do
110
- let(:request_uri){'http://example.com/dav/'}
111
-
112
- before do
113
- stub_request(:propfind, request_uri).
114
- to_return(status: 301, headers: {'location' => 'http://redirected.com/dav/'})
115
- end
116
-
117
- it "returns the redirect response" do
118
- response = HTTP.propfind(request_uri, {}, {}, {no_redirect: true})
119
- expect(response.redirection?).to eq(true)
120
- end
121
- end
122
- end
@@ -1,22 +0,0 @@
1
- # spec/Net/HTTP/Report_spec.rb
2
-
3
- require_relative '../../spec_helper'
4
- require 'Net/HTTP/Report'
5
-
6
- describe Net::HTTP::Report do
7
- it "is a subclass of Net::HTTPRequest" do
8
- expect(Net::HTTP::Report).to be <= Net::HTTPRequest
9
- end
10
-
11
- it "has the correct METHOD" do
12
- expect(Net::HTTP::Report::METHOD).to eq('REPORT')
13
- end
14
-
15
- it "accepts a body" do
16
- expect(Net::HTTP::Report::REQUEST_HAS_BODY).to eq(true)
17
- end
18
-
19
- it "expects a response body" do
20
- expect(Net::HTTP::Report::RESPONSE_HAS_BODY).to eq(true)
21
- end
22
- end
File without changes