http.rb 0.12.1 → 0.13.1

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: 64b5868b1582ef96a23021bef26cbfaa4e7ee7a63f28566e20c5f53d6ba91356
4
- data.tar.gz: 9af58e51678e5b6ba65d55ffdca2d2382cde427fb7e2db2a5999a1e137344969
3
+ metadata.gz: 1dde44381215bd0f99a698070bbf0a95ca4178fa8a796ed9de6ca7114d9f4cf1
4
+ data.tar.gz: 9c2186e4d466a1fa2eedb8ad0c305b1d631e22453c0275ac1309d2b7cafedaa6
5
5
  SHA512:
6
- metadata.gz: 291e79fc695b67dde10145d69311a79c2529f9cac03a217abbbeb254920c8aa137e0220f0e3f2eba3d46b482757a5c1777197fb4dc758dc0adb67918039a5924
7
- data.tar.gz: ec2e4b6caf7878518de41ceec6881ebb957dfcca50bc9e3aaa4295b9893ff825459e374c3ebaaf22c6ec1eadb9c6e762459d833f71fbe71397c6b91fb44a217c
6
+ metadata.gz: aebcba1e71b81d0c8f02b51fa88c1655f752a37a8ef987d16a53e2ba2459d29a17757225703de090c7beb9d5e938e08224350b4dd844943252811c9c8c339228
7
+ data.tar.gz: c5110f64b0918ffb3e855b834af2177e99c3efcec4b57ab217c0536fa522359755204ad2a21b24ce62ffbe99d71695e56f9cbc9a48e29dae4e46abf81fff47a9
data/README.md CHANGED
@@ -19,7 +19,7 @@ Perhaps someone will appreciate its relative simplicity, since it is much smalle
19
19
 
20
20
  Add this line to your application's Gemfile:
21
21
 
22
- gem 'http.rb'
22
+ gem 'HTTP.rb'
23
23
 
24
24
  And then execute:
25
25
 
@@ -27,7 +27,7 @@ And then execute:
27
27
 
28
28
  Or install it yourself as:
29
29
 
30
- $ gem install http.rb
30
+ $ gem install HTTP.rb
31
31
 
32
32
 
33
33
  ## Usage
@@ -75,6 +75,56 @@ HTTP.post('http://example.com', {a: 1, b: 2}, {'User-Agent'=>'Custom'}, {use_ssl
75
75
  # Do stuff with a subclass of Net::HTTPResponse here...
76
76
  end
77
77
 
78
+ # Preventing redirections
79
+
80
+ HTTP.get('http://example.com', {}, {}, {no_redirect: true})
81
+ # => #<Net::HTTPResponse @code=3xx>
82
+
83
+ # Response status predicate methods
84
+
85
+ # 1xx
86
+ response = HTTP.get('http://example.com')
87
+ response.informational?
88
+ # => true
89
+
90
+ # 2xx
91
+ response = HTTP.get('http://example.com')
92
+ response.success?
93
+ # => true
94
+
95
+ # 3xx
96
+ response = HTTP.get('http://example.com', {}, {}, {no_redirect: true})
97
+ response.redirection?
98
+ # => true
99
+ response.success?
100
+ # => false
101
+
102
+ response = HTTP.get('http://example.com', {}, {}, {no_redirect: false})
103
+ response.redirection?
104
+ # => false
105
+ response.success?
106
+ # => true
107
+
108
+ response = HTTP.get('http://example.com')
109
+ response.redirection?
110
+ # => false
111
+ response.success?
112
+ # => true
113
+
114
+ # 4xx
115
+ response = HTTP.get('http://example.com')
116
+ response.client_error?
117
+ # => true
118
+ response.error?
119
+ # => true
120
+
121
+ # 5xx
122
+ response = HTTP.get('http://example.com')
123
+ response.server_error?
124
+ # => true
125
+ response.error?
126
+ # => true
127
+
78
128
  # Including it in a class
79
129
 
80
130
  class A
@@ -93,8 +143,13 @@ end
93
143
 
94
144
  ```
95
145
 
96
- ## Allowed values for the options hash (which passes through to Net::HTTP)
146
+ ## Allowed values for the options hash
147
+ #### (These pass through to Net::HTTP, except for `no_redirect`.)
148
+
97
149
  ```Ruby
150
+ no_redirect
151
+ # Prevents redirection if a 3xx response is encountered.
152
+
98
153
  ca_file
99
154
  # Sets path of a CA certification file in PEM format.
100
155
  #
data/http.rb.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
- s.name = 'http.rb' # I would have preferred 'http', but there's a library called http.rb with the gem name of http. Confusing, eh?
3
- s.version = '0.12.1'
4
- s.date = '2025-02-07'
2
+ s.name = 'http.rb'
3
+ s.version = '0.13.1'
4
+ s.date = '2025-03-04'
5
5
 
6
6
  s.summary = "HTTP made easy."
7
7
  s.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
@@ -20,6 +20,4 @@ Gem::Specification.new do |s|
20
20
  ].flatten
21
21
 
22
22
  s.require_paths = ['lib']
23
-
24
- s.has_rdoc = false
25
23
  end
data/lib/HTTP/get.rb CHANGED
@@ -11,6 +11,7 @@ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
11
11
  require 'Hash/x_www_form_urlencode'
12
12
  require 'Net/HTTP/set_options'
13
13
  require 'Net/HTTP/Get/set_headers'
14
+ require 'Net/HTTPResponse/StatusPredicates'
14
15
  require 'URI/Generic/use_sslQ'
15
16
 
16
17
  module HTTP
@@ -18,6 +19,7 @@ module HTTP
18
19
  def get(uri, args = {}, headers = {}, options = {}, &block)
19
20
  uri = uri.is_a?(URI) ? uri : URI.parse(uri)
20
21
  http = Net::HTTP.new(uri.host, uri.port)
22
+ no_redirect = options.delete(:no_redirect)
21
23
  options[:use_ssl] ||= uri.use_ssl?
22
24
  options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
23
25
  http.options = options
@@ -26,6 +28,11 @@ module HTTP
26
28
  request_object.basic_auth(uri.user, uri.password) if uri.user
27
29
  response = http.request(request_object)
28
30
  if response.code =~ /^3/
31
+ if block_given? && no_redirect
32
+ yield response
33
+ elsif no_redirect
34
+ return response
35
+ end
29
36
  redirect_uri = URI.parse(response.header['location'])
30
37
  if redirect_uri.scheme
31
38
  response = get(response.header['location'], {}, {}, options, &block)
data/lib/HTTP/post.rb CHANGED
@@ -12,6 +12,7 @@ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
12
12
  require 'HTTP/get'
13
13
  require 'Net/HTTP/set_options'
14
14
  require 'Net/HTTP/Post/set_headers'
15
+ require 'Net/HTTPResponse/StatusPredicates'
15
16
  require 'URI/Generic/use_sslQ'
16
17
 
17
18
  module HTTP
@@ -19,6 +20,7 @@ module HTTP
19
20
  def post(uri, data = {}, headers = {}, options = {}, &block)
20
21
  uri = uri.is_a?(URI) ? uri : URI.parse(uri)
21
22
  http = Net::HTTP.new(uri.host, uri.port)
23
+ no_redirect = options.delete(:no_redirect)
22
24
  options[:use_ssl] ||= uri.use_ssl?
23
25
  options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
24
26
  http.options = options
@@ -32,6 +34,11 @@ module HTTP
32
34
  request_object.basic_auth(uri.user, uri.password) if uri.user
33
35
  response = http.request(request_object)
34
36
  if response.code =~ /^3/
37
+ if block_given? && no_redirect
38
+ yield response
39
+ elsif no_redirect
40
+ return response
41
+ end
35
42
  redirect_uri = URI.parse(response.header['location'])
36
43
  if redirect_uri.scheme
37
44
  response = get(response.header['location'], {}, {}, options, &block)
@@ -0,0 +1,33 @@
1
+ module Net
2
+ class HTTPResponse
3
+ module StatusPredicates
4
+ def informational?
5
+ @code =~ /^1/ ? true : false
6
+ end
7
+
8
+ def successful?
9
+ @code =~ /^2/ ? true : false
10
+ end
11
+ alias_method :success?, :successful?
12
+ alias_method :ok?, :successful?
13
+
14
+ def redirection?
15
+ @code =~ /^3/ ? true : false
16
+ end
17
+
18
+ def client_error?
19
+ @code =~ /^4/ ? true : false
20
+ end
21
+
22
+ def server_error?
23
+ @code =~ /^5/ ? true : false
24
+ end
25
+
26
+ def error?
27
+ client_error? || server_error?
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Net::HTTPResponse.include(Net::HTTPResponse::StatusPredicates)
@@ -21,12 +21,14 @@ describe ".get" do
21
21
 
22
22
  it "creates an instance of URI" do
23
23
  expect(URI).to receive(:parse).with(uri).and_return(parsed_uri)
24
- HTTP.get(uri)
24
+ response = HTTP.get(uri)
25
+ expect(response.success?).to eq(true)
25
26
  end
26
27
 
27
28
  it "creates a new Net::HTTP object" do
28
29
  expect(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
29
- HTTP.get(uri)
30
+ response = HTTP.get(uri)
31
+ expect(response.success?).to eq(true)
30
32
  end
31
33
  end
32
34
 
@@ -42,7 +44,8 @@ describe ".get" do
42
44
 
43
45
  it "creates a new Net::HTTP object" do
44
46
  expect(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_return(net_http_object)
45
- HTTP.get(uri)
47
+ response = HTTP.get(uri)
48
+ expect(response.success?).to eq(true)
46
49
  end
47
50
  end
48
51
  end
@@ -63,12 +66,14 @@ describe ".get" do
63
66
 
64
67
  it "x_www_form_urlencode's the args" do
65
68
  expect(args).to receive(:x_www_form_urlencode).and_return(x_www_form_urlencoded_arguments)
66
- HTTP.get(uri, args)
69
+ response = HTTP.get(uri, args)
70
+ expect(response.success?).to eq(true)
67
71
  end
68
72
 
69
73
  it "creates a new Net::HTTP::Get object" do
70
74
  expect(Net::HTTP::Get).to receive(:new).with(get_argument).and_return(request_object)
71
- HTTP.get(uri, args)
75
+ response = HTTP.get(uri, args)
76
+ expect(response.success?).to eq(true)
72
77
  end
73
78
  end
74
79
 
@@ -87,8 +92,9 @@ describe ".get" do
87
92
 
88
93
  it "sets the headers on the request object" do
89
94
  allow(Net::HTTP::Get).to receive(:new).with(get_argument).and_return(request_object)
90
- HTTP.get(uri, {}, headers)
95
+ response = HTTP.get(uri, {}, headers)
91
96
  expect(request_object['User-Agent']).to eq('Rspec')
97
+ expect(response.success?).to eq(true)
92
98
  end
93
99
  end
94
100
 
@@ -106,8 +112,9 @@ describe ".get" do
106
112
 
107
113
  it "sets the use_ssl option on the Net::HTTP instance" do
108
114
  allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
109
- HTTP.get(uri, {}, {}, options)
115
+ response = HTTP.get(uri, {}, {}, options)
110
116
  expect(net_http_object.instance_variable_get(:@use_ssl)).to be_truthy
117
+ expect(response.success?).to eq(true)
111
118
  end
112
119
  end
113
120
 
@@ -122,7 +129,6 @@ describe ".get" do
122
129
 
123
130
  it "yields an instance of Net::HTTPResponse" do
124
131
  expect{|b| HTTP.get(uri, &b)}.to yield_with_args(Net::HTTPResponse)
125
- HTTP.get(uri){|response|}
126
132
  end
127
133
  end
128
134
 
@@ -145,8 +151,9 @@ describe ".get" do
145
151
 
146
152
  it "does a redirect" do
147
153
  expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
148
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
149
- HTTP.get(request_uri)
154
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
155
+ response = HTTP.get(request_uri)
156
+ expect(response.success?).to eq(true)
150
157
  end
151
158
  end
152
159
 
@@ -159,8 +166,9 @@ describe ".get" do
159
166
 
160
167
  it "does a redirect" do
161
168
  expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
162
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
163
- HTTP.get(request_uri)
169
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
170
+ response = HTTP.get(request_uri)
171
+ expect(response.success?).to eq(true)
164
172
  end
165
173
  end
166
174
  end
@@ -185,8 +193,9 @@ describe ".get" do
185
193
 
186
194
  it "does a redirect" do
187
195
  expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
188
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
189
- HTTP.get(request_uri)
196
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
197
+ response = HTTP.get(request_uri)
198
+ expect(response.success?).to eq(true)
190
199
  end
191
200
  end
192
201
 
@@ -199,8 +208,42 @@ describe ".get" do
199
208
 
200
209
  it "does a redirect" do
201
210
  expect(HTTP).to receive(:get).once.with(request_uri).and_call_original
202
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
203
- HTTP.get(request_uri)
211
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
212
+ response = HTTP.get(request_uri)
213
+ expect(response.success?).to eq(true)
214
+ end
215
+ end
216
+ end
217
+
218
+ context "no_redirect true" do
219
+ let(:request_uri){'http://example.com/path'}
220
+ let(:redirect_uri){'http://redirected.com'}
221
+
222
+ context "via 301" do
223
+ before do
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_uri})
227
+ end
228
+
229
+ it "doesn't redirect" do
230
+ expect(HTTP).to receive(:get).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
231
+ response = HTTP.get(request_uri, {}, {}, {no_redirect: true})
232
+ expect(response.redirection?).to eq(true)
233
+ end
234
+ end
235
+
236
+ context "via 302" do
237
+ before do
238
+ stub_request(:get, request_uri).
239
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
240
+ to_return(status: 302, body: '', headers: {'location' => redirect_uri})
241
+ end
242
+
243
+ it "doesn't redirect" do
244
+ expect(HTTP).to receive(:get).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
245
+ response = HTTP.get(request_uri, {}, {}, {no_redirect: true})
246
+ expect(response.redirection?).to eq(true)
204
247
  end
205
248
  end
206
249
  end
@@ -21,12 +21,14 @@ describe ".post" do
21
21
 
22
22
  it "creates an instance of URI" do
23
23
  expect(URI).to receive(:parse).with(uri).and_return(parsed_uri)
24
- HTTP.post(uri)
24
+ response = HTTP.post(uri)
25
+ expect(response.success?).to eq(true)
25
26
  end
26
27
 
27
28
  it "creates a new Net::HTTP object" do
28
29
  expect(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
29
- HTTP.post(uri)
30
+ response = HTTP.post(uri)
31
+ expect(response.success?).to eq(true)
30
32
  end
31
33
  end
32
34
 
@@ -37,12 +39,14 @@ describe ".post" do
37
39
 
38
40
  it "returns an instance of URI" do
39
41
  expect(uri).to eq(uri)
40
- HTTP.post(uri)
42
+ response = HTTP.post(uri)
43
+ expect(response.success?).to eq(true)
41
44
  end
42
45
 
43
46
  it "creates a new Net::HTTP object" do
44
47
  expect(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_return(net_http_object)
45
- HTTP.post(uri)
48
+ response = HTTP.post(uri)
49
+ expect(response.success?).to eq(true)
46
50
  end
47
51
  end
48
52
  end
@@ -64,13 +68,15 @@ describe ".post" do
64
68
 
65
69
  it "sets the form data" do
66
70
  allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
67
- HTTP.post(uri, args, headers)
71
+ response = HTTP.post(uri, args, headers)
68
72
  expect(request_object.body).to eq(encoded_form_data)
73
+ expect(response.success?).to eq(true)
69
74
  end
70
75
 
71
76
  it "creates a new Net::HTTP::Post object" do
72
77
  expect(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
73
- HTTP.post(uri, args, headers)
78
+ response = HTTP.post(uri, args, headers)
79
+ expect(response.success?).to eq(true)
74
80
  end
75
81
  end
76
82
 
@@ -91,13 +97,15 @@ describe ".post" do
91
97
 
92
98
  it "sets the body" do
93
99
  allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
94
- HTTP.post(uri, args, headers)
100
+ response = HTTP.post(uri, args, headers)
95
101
  expect(request_object.body).to eq(json_data)
102
+ expect(response.success?).to eq(true)
96
103
  end
97
104
 
98
105
  it "creates a new Net::HTTP::Post object" do
99
106
  expect(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
100
- HTTP.post(uri, args, headers)
107
+ response = HTTP.post(uri, args, headers)
108
+ expect(response.success?).to eq(true)
101
109
  end
102
110
  end
103
111
 
@@ -116,8 +124,9 @@ describe ".post" do
116
124
 
117
125
  it "sets the headers on the request object" do
118
126
  allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
119
- HTTP.post(uri, {}, headers)
127
+ response = HTTP.post(uri, {}, headers)
120
128
  expect(request_object['User-Agent']).to eq('Rspec')
129
+ expect(response.success?).to eq(true)
121
130
  end
122
131
  end
123
132
 
@@ -135,8 +144,9 @@ describe ".post" do
135
144
 
136
145
  it "sets the use_ssl option on the Net::HTTP instance" do
137
146
  allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
138
- HTTP.post(uri, {}, {}, options)
147
+ response = HTTP.post(uri, {}, {}, options)
139
148
  expect(net_http_object.instance_variable_get(:@use_ssl)).to be_truthy
149
+ expect(response.success?).to eq(true)
140
150
  end
141
151
  end
142
152
 
@@ -151,7 +161,6 @@ describe ".post" do
151
161
 
152
162
  it "yields an instance of Net::HTTPResponse" do
153
163
  expect{|b| HTTP.post(uri, &b)}.to yield_with_args(Net::HTTPResponse)
154
- HTTP.post(uri){|response|}
155
164
  end
156
165
  end
157
166
 
@@ -174,8 +183,9 @@ describe ".post" do
174
183
 
175
184
  it "does a redirect" do
176
185
  expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
177
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
178
- HTTP.post(request_uri)
186
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
187
+ response = HTTP.post(request_uri)
188
+ expect(response.success?).to eq(true)
179
189
  end
180
190
  end
181
191
 
@@ -188,8 +198,9 @@ describe ".post" do
188
198
 
189
199
  it "does a redirect" do
190
200
  expect(HTTP).to receive(:post).with(request_uri).and_call_original
191
- expect(HTTP).to receive(:get).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
192
- HTTP.post(request_uri)
201
+ expect(HTTP).to receive(:get).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
202
+ response = HTTP.post(request_uri)
203
+ expect(response.success?).to eq(true)
193
204
  end
194
205
  end
195
206
  end
@@ -213,9 +224,10 @@ describe ".post" do
213
224
  end
214
225
 
215
226
  it "does a redirect" do
216
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
227
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
217
228
  expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
218
- HTTP.post(request_uri)
229
+ response = HTTP.post(request_uri)
230
+ expect(response.success?).to eq(true)
219
231
  end
220
232
  end
221
233
 
@@ -227,9 +239,43 @@ describe ".post" do
227
239
  end
228
240
 
229
241
  it "does a redirect" do
230
- expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0})
242
+ expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
231
243
  expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
232
- HTTP.post(request_uri)
244
+ response = HTTP.post(request_uri)
245
+ expect(response.success?).to eq(true)
246
+ end
247
+ end
248
+ end
249
+
250
+ context "no_redirect true" do
251
+ let(:request_uri){'http://example.com/path'}
252
+ let(:redirect_uri){'http://redirected.com'}
253
+
254
+ context "via 301" do
255
+ before do
256
+ stub_request(:post, request_uri).
257
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
258
+ to_return(status: 301, body: '', headers: {'location' => redirect_uri})
259
+ end
260
+
261
+ it "doesn't redirect" do
262
+ expect(HTTP).to receive(:post).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
263
+ response = HTTP.post(request_uri, {}, {}, {no_redirect: true})
264
+ expect(response.redirection?).to eq(true)
265
+ end
266
+ end
267
+
268
+ context "via 302" do
269
+ before do
270
+ stub_request(:post, request_uri).
271
+ with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
272
+ to_return(status: 302, body: '', headers: {'location' => redirect_uri})
273
+ end
274
+
275
+ it "doesn't redirect" do
276
+ expect(HTTP).to receive(:post).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
277
+ response = HTTP.post(request_uri, {}, {}, {no_redirect: true})
278
+ expect(response.redirection?).to eq(true)
233
279
  end
234
280
  end
235
281
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-07 00:00:00.000000000 Z
10
+ date: 2025-03-04 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, some
13
13
  optional query arguments, some optional headers, and some Net::HTTP options,
@@ -27,6 +27,7 @@ files:
27
27
  - lib/Net/HTTP/Get/set_headers.rb
28
28
  - lib/Net/HTTP/Post/set_headers.rb
29
29
  - lib/Net/HTTP/set_options.rb
30
+ - lib/Net/HTTPResponse/StatusPredicates.rb
30
31
  - lib/String/url_encode.rb
31
32
  - lib/URI/Generic/use_sslQ.rb
32
33
  - spec/HTTP/get_spec.rb
@@ -49,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
50
  - !ruby/object:Gem::Version
50
51
  version: '0'
51
52
  requirements: []
52
- rubygems_version: 3.6.3
53
+ rubygems_version: 3.6.5
53
54
  specification_version: 4
54
55
  summary: HTTP made easy.
55
56
  test_files: []