http.rb 0.14.0 → 0.15.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 +4 -4
- data/CHANGELOG.txt +22 -2
- data/http.rb.gemspec +1 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/delete.rb +1 -0
- data/lib/HTTP/put.rb +56 -0
- data/lib/HTTP.rb +2 -0
- data/lib/Net/HTTP/Put/set_headers.rb +14 -0
- data/spec/HTTP/post_spec.rb +4 -4
- data/spec/HTTP/put_spec.rb +279 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eeee894fa63eb3d4e2ffe9fb35f9521111adc63b05261b56dd691e0f74f2613
|
4
|
+
data.tar.gz: ef36a1ad9059459da8f1941f6c7e2ca9c5150466d7944a1fd8278bf403311008
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c02f7c9af8804c92de600e42bcbb161236826503b1be6e184704aa12e214b2665c195aa827610772780dfc9a3a7cf45b8f4bf13500959b4c34a88a241334a81c
|
7
|
+
data.tar.gz: abbd416370db5c0b118b259e284a2d5ba1ca1ae6bda9dde3f9b20826f37fbff4a57dacfa7e90b4bf52b49c0ee8116d53f83a1dfcf5c2eed3e5d2364fc3825b13
|
data/CHANGELOG.txt
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
+
# 20250721
|
2
|
+
# 0.15.1: Fix PUT; require delete and put in the load file.
|
3
|
+
1. + require 'HTTP/post'
|
4
|
+
2. + require 'HTTP/put'
|
5
|
+
3. ~ HTTP/put.rb: Params in the body!
|
6
|
+
3. ~ spec/HTTP/put_spec.rb: Remove copy-pasta rubbish.
|
7
|
+
4. ~ spec/HTTP/post_spec.rb: Mostly formatting.
|
8
|
+
4. ~ HTTP::VERSION: /0.15.0/0.15.1/
|
9
|
+
5. ~ CHANGELOG.txt
|
10
|
+
6. ~ http.rb.gemspec: Change date.
|
11
|
+
|
12
|
+
# 20250716
|
13
|
+
# 0.15.0: + PUT
|
14
|
+
1. + HTTP.put
|
15
|
+
2. + Net::HTTP::Put#set_headers
|
16
|
+
3. + spec/HTTP/put_spec.rb
|
17
|
+
4. ~ HTTP::VERSION: /0.14.3/0.15.0/
|
18
|
+
5. ~ CHANGELOG.txt
|
19
|
+
6. ~ http.rb.gemspec: Change date.
|
20
|
+
|
1
21
|
# 20250711
|
2
22
|
# 0.14.0: + DELETE
|
3
23
|
1. + HTTP.delete
|
4
24
|
2. + Net::HTTP::Delete#set_headers
|
5
25
|
3. + spec/HTTP/delete_spec.rb
|
6
|
-
4. ~ HTTP.
|
7
|
-
5. ~ HTTP.
|
26
|
+
4. ~ spec/HTTP/get_spec.rb: /require/require_relative/
|
27
|
+
5. ~ spec/HTTP/post_spec.rb: /require/require_relative/
|
8
28
|
6. ~ HTTP::VERSION: /0.13.3/0.14.0/
|
9
29
|
7. ~ CHANGELOG.txt
|
10
30
|
8. ~ http.rb.gemspec: Change date.
|
data/http.rb.gemspec
CHANGED
@@ -3,7 +3,7 @@ require_relative './lib/HTTP/VERSION'
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'http.rb'
|
5
5
|
s.version = HTTP::VERSION
|
6
|
-
s.date = '2025-07-
|
6
|
+
s.date = '2025-07-21'
|
7
7
|
|
8
8
|
s.summary = "HTTP made easy."
|
9
9
|
s.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
|
data/lib/HTTP/VERSION.rb
CHANGED
data/lib/HTTP/delete.rb
CHANGED
@@ -6,6 +6,7 @@ require 'openssl'
|
|
6
6
|
require 'uri'
|
7
7
|
|
8
8
|
require_relative '../Hash/x_www_form_urlencode'
|
9
|
+
require_relative '../HTTP/get'
|
9
10
|
require_relative '../Net/HTTP/set_options'
|
10
11
|
require_relative '../Net/HTTP/Delete/set_headers'
|
11
12
|
require_relative '../Net/HTTPResponse/StatusPredicates'
|
data/lib/HTTP/put.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# HTTP/put.rb
|
2
|
+
# HTTP.put
|
3
|
+
|
4
|
+
require 'json'
|
5
|
+
require 'net/http'
|
6
|
+
require 'openssl'
|
7
|
+
require 'uri'
|
8
|
+
|
9
|
+
require_relative '../HTTP/get'
|
10
|
+
require_relative '../Net/HTTP/set_options'
|
11
|
+
require_relative '../Net/HTTP/Put/set_headers'
|
12
|
+
require_relative '../Net/HTTPResponse/StatusPredicates'
|
13
|
+
require_relative '../URI/Generic/use_sslQ'
|
14
|
+
|
15
|
+
module HTTP
|
16
|
+
|
17
|
+
def put(uri, data = {}, headers = {}, options = {}, &block)
|
18
|
+
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
19
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
20
|
+
no_redirect = options.delete(:no_redirect)
|
21
|
+
options[:use_ssl] ||= uri.use_ssl?
|
22
|
+
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
23
|
+
http.options = options
|
24
|
+
request_object = Net::HTTP::Put.new(uri.request_uri)
|
25
|
+
if headers['Content-Type'] == 'application/json'
|
26
|
+
request_object.body = JSON.dump(data)
|
27
|
+
else
|
28
|
+
request_object.form_data = data
|
29
|
+
end
|
30
|
+
request_object.headers = headers
|
31
|
+
request_object.basic_auth(uri.user, uri.password) if uri.user
|
32
|
+
response = http.request(request_object)
|
33
|
+
if response.code =~ /^3/
|
34
|
+
if block_given? && no_redirect
|
35
|
+
yield response
|
36
|
+
elsif no_redirect
|
37
|
+
return response
|
38
|
+
end
|
39
|
+
redirect_uri = URI.parse(response.header['location'])
|
40
|
+
if redirect_uri.scheme
|
41
|
+
response = get(response.header['location'], {}, {}, options, &block)
|
42
|
+
else
|
43
|
+
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
44
|
+
response = get(new_location, {}, {}, options, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
if block_given?
|
48
|
+
yield response
|
49
|
+
else
|
50
|
+
response
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
module_function :put
|
55
|
+
|
56
|
+
end
|
data/lib/HTTP.rb
CHANGED
data/spec/HTTP/post_spec.rb
CHANGED
@@ -194,8 +194,8 @@ describe ".post" do
|
|
194
194
|
end
|
195
195
|
|
196
196
|
it "does a redirect" do
|
197
|
-
expect(HTTP).to receive(:post).with(request_uri).and_call_original
|
198
|
-
expect(HTTP).to receive(:get).with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
197
|
+
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
198
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
199
199
|
response = HTTP.post(request_uri)
|
200
200
|
expect(response.success?).to eq(true)
|
201
201
|
end
|
@@ -221,8 +221,8 @@ describe ".post" do
|
|
221
221
|
end
|
222
222
|
|
223
223
|
it "does a redirect" do
|
224
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
225
224
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
225
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
226
226
|
response = HTTP.post(request_uri)
|
227
227
|
expect(response.success?).to eq(true)
|
228
228
|
end
|
@@ -236,8 +236,8 @@ describe ".post" do
|
|
236
236
|
end
|
237
237
|
|
238
238
|
it "does a redirect" do
|
239
|
-
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
240
239
|
expect(HTTP).to receive(:post).once.with(request_uri).and_call_original
|
240
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
241
241
|
response = HTTP.post(request_uri)
|
242
242
|
expect(response.success?).to eq(true)
|
243
243
|
end
|
@@ -0,0 +1,279 @@
|
|
1
|
+
# spec/HTTP/put_spec.rb
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
require 'HTTP/put'
|
5
|
+
|
6
|
+
describe ".put" do
|
7
|
+
context "with uri-only supplied" do
|
8
|
+
before do
|
9
|
+
stub_request(:put, 'http://example.com/path').
|
10
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
11
|
+
to_return(status: 200, body: '', headers: {})
|
12
|
+
end
|
13
|
+
|
14
|
+
context "uri as a string" do
|
15
|
+
let(:uri){'http://example.com/path'}
|
16
|
+
let(:parsed_uri){URI.parse(uri)}
|
17
|
+
let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
|
18
|
+
|
19
|
+
it "creates an instance of URI" do
|
20
|
+
expect(URI).to receive(:parse).with(uri).and_return(parsed_uri)
|
21
|
+
response = HTTP.put(uri)
|
22
|
+
expect(response.success?).to eq(true)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates a new Net::HTTP object" do
|
26
|
+
expect(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
|
27
|
+
response = HTTP.put(uri)
|
28
|
+
expect(response.success?).to eq(true)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "uri as a URI" do
|
33
|
+
let(:uri_string){'http://example.com/path'}
|
34
|
+
let(:uri){URI.parse(uri_string)}
|
35
|
+
let(:net_http_object){Net::HTTP.new(uri.host, uri.port)}
|
36
|
+
|
37
|
+
it "returns an instance of URI" do
|
38
|
+
expect(uri).to eq(uri)
|
39
|
+
response = HTTP.put(uri)
|
40
|
+
expect(response.success?).to eq(true)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "creates a new Net::HTTP object" do
|
44
|
+
expect(Net::HTTP).to receive(:new).with(uri.host, uri.port).and_return(net_http_object)
|
45
|
+
response = HTTP.put(uri)
|
46
|
+
expect(response.success?).to eq(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with form data supplied" do
|
52
|
+
let(:uri){'http://example.com/path'}
|
53
|
+
let(:parsed_uri){URI.parse(uri)}
|
54
|
+
let(:args) do; {a: 1, b: 2}; end
|
55
|
+
let(:headers) do; {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}; end
|
56
|
+
let(:encoded_form_data){args.x_www_form_urlencode}
|
57
|
+
let(:request_uri){parsed_uri.request_uri}
|
58
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
59
|
+
|
60
|
+
before do
|
61
|
+
stub_request(:put, "http://example.com/path").
|
62
|
+
with(body: encoded_form_data, headers: headers).
|
63
|
+
to_return(status: 200, body: '', headers: {})
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets the form data" do
|
67
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
68
|
+
response = HTTP.put(uri, args, headers)
|
69
|
+
expect(request_object.body).to eq(encoded_form_data)
|
70
|
+
expect(response.success?).to eq(true)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "creates a new Net::HTTP::Post object" do
|
74
|
+
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
75
|
+
response = HTTP.put(uri, args, headers)
|
76
|
+
expect(response.success?).to eq(true)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with JSON data supplied" do
|
81
|
+
let(:uri){'http://example.com/path'}
|
82
|
+
let(:parsed_uri){URI.parse(uri)}
|
83
|
+
let(:args) do; {a: 1, b: 2}; end
|
84
|
+
let(:headers) do; {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}; end
|
85
|
+
let(:json_data){JSON.dump(args)}
|
86
|
+
let(:request_uri){parsed_uri.request_uri}
|
87
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
88
|
+
|
89
|
+
before do
|
90
|
+
stub_request(:put, "http://example.com/path").
|
91
|
+
with(body: json_data, headers: headers).
|
92
|
+
to_return(status: 200, body: '', headers: {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets the body" do
|
96
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
97
|
+
response = HTTP.put(uri, args, headers)
|
98
|
+
expect(request_object.body).to eq(json_data)
|
99
|
+
expect(response.success?).to eq(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates a new Net::HTTP::Post object" do
|
103
|
+
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
104
|
+
response = HTTP.put(uri, args, headers)
|
105
|
+
expect(response.success?).to eq(true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "with headers supplied" do
|
110
|
+
let(:uri){'http://example.com/path'}
|
111
|
+
let(:parsed_uri){URI.parse(uri)}
|
112
|
+
let(:headers) do; {'User-Agent' => 'Rspec'}; end
|
113
|
+
let(:request_uri){parsed_uri.request_uri}
|
114
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
115
|
+
|
116
|
+
before do
|
117
|
+
stub_request(:put, 'http://example.com/path').
|
118
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Rspec'}).
|
119
|
+
to_return(status: 200, body: '', headers: {})
|
120
|
+
end
|
121
|
+
|
122
|
+
it "sets the headers on the request object" do
|
123
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
124
|
+
response = HTTP.put(uri, {}, headers)
|
125
|
+
expect(request_object['User-Agent']).to eq('Rspec')
|
126
|
+
expect(response.success?).to eq(true)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
context "with options supplied" do
|
131
|
+
let(:uri){'http://example.com/path'}
|
132
|
+
let(:parsed_uri){URI.parse(uri)}
|
133
|
+
let(:net_http_object){Net::HTTP.new(parsed_uri.host, parsed_uri.port)}
|
134
|
+
let(:options) do; {use_ssl: true}; end
|
135
|
+
|
136
|
+
before do
|
137
|
+
stub_request(:put, 'https://example.com:80/path').
|
138
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
139
|
+
to_return(status: 200, body: '', headers: {})
|
140
|
+
end
|
141
|
+
|
142
|
+
it "sets the use_ssl option on the Net::HTTP instance" do
|
143
|
+
allow(Net::HTTP).to receive(:new).with(parsed_uri.host, parsed_uri.port).and_return(net_http_object)
|
144
|
+
response = HTTP.put(uri, {}, {}, options)
|
145
|
+
expect(net_http_object.instance_variable_get(:@use_ssl)).to be_truthy
|
146
|
+
expect(response.success?).to eq(true)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "with block supplied" do
|
151
|
+
let(:uri){'http://example.com/path'}
|
152
|
+
|
153
|
+
before do
|
154
|
+
stub_request(:put, 'http://example.com/path').
|
155
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
|
156
|
+
to_return(status: 200, body: '', headers: {})
|
157
|
+
end
|
158
|
+
|
159
|
+
it "yields an instance of Net::HTTPResponse" do
|
160
|
+
expect{|b| HTTP.put(uri, &b)}.to yield_with_args(Net::HTTPResponse)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "with redirection" do
|
165
|
+
let(:request_uri){'http://example.com/path'}
|
166
|
+
let(:redirect_uri){'http://redirected.com'}
|
167
|
+
|
168
|
+
before do
|
169
|
+
stub_request(:get, redirect_uri).
|
170
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
171
|
+
to_return(status: 200, body: '', headers: {})
|
172
|
+
end
|
173
|
+
|
174
|
+
context "via 301" do
|
175
|
+
before do
|
176
|
+
stub_request(:put, request_uri).
|
177
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
178
|
+
to_return(status: 301, body: '', headers: {'location' => redirect_uri})
|
179
|
+
end
|
180
|
+
|
181
|
+
it "does a redirect" do
|
182
|
+
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
183
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
184
|
+
response = HTTP.put(request_uri)
|
185
|
+
expect(response.success?).to eq(true)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
context "via 302" do
|
190
|
+
before do
|
191
|
+
stub_request(:put, request_uri).
|
192
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
193
|
+
to_return(status: 302, body: '', headers: {'location' => redirect_uri})
|
194
|
+
end
|
195
|
+
|
196
|
+
it "does a redirect" do
|
197
|
+
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
198
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
199
|
+
response = HTTP.put(request_uri)
|
200
|
+
expect(response.success?).to eq(true)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "with path only redirection" do
|
206
|
+
let(:request_uri){'http://example.com/path'}
|
207
|
+
let(:redirect_path){'/new_path'}
|
208
|
+
let(:redirect_uri){"http://example.com:80#{redirect_path}"}
|
209
|
+
|
210
|
+
before do
|
211
|
+
stub_request(:get, redirect_uri).
|
212
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
213
|
+
to_return(status: 200, body: '', headers: {})
|
214
|
+
end
|
215
|
+
|
216
|
+
context "via 301" do
|
217
|
+
before do
|
218
|
+
stub_request(:put, request_uri).
|
219
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
220
|
+
to_return(status: 301, body: '', headers: {'location' => redirect_path})
|
221
|
+
end
|
222
|
+
|
223
|
+
it "does a redirect" do
|
224
|
+
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
225
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
226
|
+
response = HTTP.put(request_uri)
|
227
|
+
expect(response.success?).to eq(true)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "via 302" do
|
232
|
+
before do
|
233
|
+
stub_request(:put, request_uri).
|
234
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
235
|
+
to_return(status: 302, body: '', headers: {'location' => redirect_path})
|
236
|
+
end
|
237
|
+
|
238
|
+
it "does a redirect" do
|
239
|
+
expect(HTTP).to receive(:put).once.with(request_uri).and_call_original
|
240
|
+
expect(HTTP).to receive(:get).once.with(redirect_uri, {}, {}, {use_ssl: false, verify_mode: 0}).and_call_original
|
241
|
+
response = HTTP.put(request_uri)
|
242
|
+
expect(response.success?).to eq(true)
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
context "no_redirect true" do
|
248
|
+
let(:request_uri){'http://example.com/path'}
|
249
|
+
let(:redirect_uri){'http://redirected.com'}
|
250
|
+
|
251
|
+
context "via 301" do
|
252
|
+
before do
|
253
|
+
stub_request(:put, request_uri).
|
254
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
255
|
+
to_return(status: 301, body: '', headers: {'location' => redirect_uri})
|
256
|
+
end
|
257
|
+
|
258
|
+
it "doesn't redirect" do
|
259
|
+
expect(HTTP).to receive(:put).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
|
260
|
+
response = HTTP.put(request_uri, {}, {}, {no_redirect: true})
|
261
|
+
expect(response.redirection?).to eq(true)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
context "via 302" do
|
266
|
+
before do
|
267
|
+
stub_request(:put, request_uri).
|
268
|
+
with(headers: {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'}).
|
269
|
+
to_return(status: 302, body: '', headers: {'location' => redirect_uri})
|
270
|
+
end
|
271
|
+
|
272
|
+
it "doesn't redirect" do
|
273
|
+
expect(HTTP).to receive(:put).once.with(request_uri, {}, {}, {no_redirect: true}).and_call_original
|
274
|
+
response = HTTP.put(request_uri, {}, {}, {no_redirect: true})
|
275
|
+
expect(response.redirection?).to eq(true)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
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.
|
4
|
+
version: 0.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoran
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-07-
|
10
|
+
date: 2025-07-21 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,
|
@@ -26,10 +26,12 @@ files:
|
|
26
26
|
- lib/HTTP/delete.rb
|
27
27
|
- lib/HTTP/get.rb
|
28
28
|
- lib/HTTP/post.rb
|
29
|
+
- lib/HTTP/put.rb
|
29
30
|
- lib/Hash/x_www_form_urlencode.rb
|
30
31
|
- lib/Net/HTTP/Delete/set_headers.rb
|
31
32
|
- lib/Net/HTTP/Get/set_headers.rb
|
32
33
|
- lib/Net/HTTP/Post/set_headers.rb
|
34
|
+
- lib/Net/HTTP/Put/set_headers.rb
|
33
35
|
- lib/Net/HTTP/set_options.rb
|
34
36
|
- lib/Net/HTTPResponse/StatusPredicates.rb
|
35
37
|
- lib/String/url_encode.rb
|
@@ -37,6 +39,7 @@ files:
|
|
37
39
|
- spec/HTTP/delete_spec.rb
|
38
40
|
- spec/HTTP/get_spec.rb
|
39
41
|
- spec/HTTP/post_spec.rb
|
42
|
+
- spec/HTTP/put_spec.rb
|
40
43
|
- spec/spec_helper.rb
|
41
44
|
homepage: http://github.com/thoran/HTTP
|
42
45
|
licenses: []
|