http.rb 0.15.1 → 0.16.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 +25 -2
- data/http.rb.gemspec +1 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/post.rb +12 -3
- data/lib/HTTP/put.rb +12 -3
- data/spec/HTTP/post_spec.rb +106 -0
- data/spec/HTTP/put_spec.rb +108 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29514ef093a2f03e4936ba26f13673c8a6696058aaf555c5e0a5a0167f7c19cd
|
4
|
+
data.tar.gz: 21a5f38db7c4e93fb3cd57deba7bf17154737c341b7c25f32e206fc24e9fc37f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23ceeaa56c2963b88119409fa4b29cd85048cba6523f77eb7bdf47762837a83b494a5c3d7f44e011ea66649028e37e19be5e10a9fa64a468f7d9f432087d6b4e
|
7
|
+
data.tar.gz: 320c109717cf4ffdbafdce41cdd83ea96ec3c0fb79bd4a300fa58c324679c4e4f83503ffa912e376f6c3655d1bdb0facaa58989984b1d6f0fd997c558ed1f342
|
data/CHANGELOG.txt
CHANGED
@@ -1,7 +1,30 @@
|
|
1
|
+
# 20250908
|
2
|
+
# 0.16.1: Allow any case for the content-type key.
|
3
|
+
1. ~ HTTP.post: Check for any case for content-type key.
|
4
|
+
2. ~ HTTP.put: Check for any case for content-type key.
|
5
|
+
3. ~ spec/HTTP/post_spec.rb: + specs for different content-type key cases.
|
6
|
+
4. ~ spec/HTTP/put_spec.rb: + specs for different content-type key cases.
|
7
|
+
5. ~ spec/HTTP/put_spec.rb: Fix some erroneous references to (P|p)ost.
|
8
|
+
6. ~ HTTP::VERSION: /0.16.0/0.16.1/
|
9
|
+
7. ~ CHANGELOG.txt: + 0.16.1 entry
|
10
|
+
8. ~ http.rb.gemspec: Change date.
|
11
|
+
|
12
|
+
# 20250809
|
13
|
+
# 0.16.0: Allow passing of a raw payload for POST/PUT.
|
14
|
+
1. ~ HTTP.post: Check for Content-Type and whether a string.
|
15
|
+
2. ~ HTTP.put: Check for Content-Type and whether a string.
|
16
|
+
3. ~ spec/HTTP/post_spec.rb: + raw form data example
|
17
|
+
4. ~ spec/HTTP/post_spec.rb: + raw JSON example
|
18
|
+
5. ~ spec/HTTP/put_spec.rb: + raw form data example
|
19
|
+
6. ~ spec/HTTP/put_spec.rb: + raw JSON example
|
20
|
+
7. ~ HTTP::VERSION: /0.15.1/0.16.0/
|
21
|
+
8. ~ CHANGELOG.txt: + 0.16.0 entry; Small edit on 0.15.1.
|
22
|
+
9. ~ http.rb.gemspec: Change date.
|
23
|
+
|
1
24
|
# 20250721
|
2
25
|
# 0.15.1: Fix PUT; require delete and put in the load file.
|
3
|
-
1. + require 'HTTP/
|
4
|
-
2. + require 'HTTP/
|
26
|
+
1. + require 'HTTP/put'
|
27
|
+
2. + require 'HTTP/delete'
|
5
28
|
3. ~ HTTP/put.rb: Params in the body!
|
6
29
|
3. ~ spec/HTTP/put_spec.rb: Remove copy-pasta rubbish.
|
7
30
|
4. ~ spec/HTTP/post_spec.rb: Mostly formatting.
|
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-
|
6
|
+
s.date = '2025-09-08'
|
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/post.rb
CHANGED
@@ -22,10 +22,19 @@ module HTTP
|
|
22
22
|
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
23
23
|
http.options = options
|
24
24
|
request_object = Net::HTTP::Post.new(uri.request_uri)
|
25
|
-
|
26
|
-
|
25
|
+
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
26
|
+
if content_type.start_with?('application/json')
|
27
|
+
if data.is_a?(String)
|
28
|
+
request_object.body = data
|
29
|
+
else
|
30
|
+
request_object.body = JSON.dump(data)
|
31
|
+
end
|
27
32
|
else
|
28
|
-
|
33
|
+
if data.is_a?(String)
|
34
|
+
request_object.body = data
|
35
|
+
else
|
36
|
+
request_object.form_data = data
|
37
|
+
end
|
29
38
|
end
|
30
39
|
request_object.headers = headers
|
31
40
|
request_object.basic_auth(uri.user, uri.password) if uri.user
|
data/lib/HTTP/put.rb
CHANGED
@@ -22,10 +22,19 @@ module HTTP
|
|
22
22
|
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
23
23
|
http.options = options
|
24
24
|
request_object = Net::HTTP::Put.new(uri.request_uri)
|
25
|
-
|
26
|
-
|
25
|
+
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
26
|
+
if content_type.start_with?('application/json')
|
27
|
+
if data.is_a?(String)
|
28
|
+
request_object.body = data
|
29
|
+
else
|
30
|
+
request_object.body = JSON.dump(data)
|
31
|
+
end
|
27
32
|
else
|
28
|
-
|
33
|
+
if data.is_a?(String)
|
34
|
+
request_object.body = data
|
35
|
+
else
|
36
|
+
request_object.form_data = data
|
37
|
+
end
|
29
38
|
end
|
30
39
|
request_object.headers = headers
|
31
40
|
request_object.basic_auth(uri.user, uri.password) if uri.user
|
data/spec/HTTP/post_spec.rb
CHANGED
@@ -77,6 +77,35 @@ describe ".post" do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
+
context "with raw form 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}.x_www_form_urlencode; end
|
84
|
+
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
|
85
|
+
let(:encoded_form_data){args}
|
86
|
+
let(:request_uri){parsed_uri.request_uri}
|
87
|
+
let(:request_object){Net::HTTP::Post.new(request_uri)}
|
88
|
+
|
89
|
+
before do
|
90
|
+
stub_request(:post, "http://example.com/path").
|
91
|
+
with(body: encoded_form_data, headers: headers).
|
92
|
+
to_return(status: 200, body: '', headers: {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets the form data" do
|
96
|
+
allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
97
|
+
response = HTTP.post(uri, args, headers)
|
98
|
+
expect(request_object.body).to eq(encoded_form_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::Post).to receive(:new).with(request_uri).and_return(request_object)
|
104
|
+
response = HTTP.post(uri, args, headers)
|
105
|
+
expect(response.success?).to eq(true)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
80
109
|
context "with JSON data supplied" do
|
81
110
|
let(:uri){'http://example.com/path'}
|
82
111
|
let(:parsed_uri){URI.parse(uri)}
|
@@ -106,6 +135,35 @@ describe ".post" do
|
|
106
135
|
end
|
107
136
|
end
|
108
137
|
|
138
|
+
context "with raw JSON data supplied" do
|
139
|
+
let(:uri){'http://example.com/path'}
|
140
|
+
let(:parsed_uri){URI.parse(uri)}
|
141
|
+
let(:args) do; JSON.dump({a: 1, b: 2}); end
|
142
|
+
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
|
143
|
+
let(:json_data){args}
|
144
|
+
let(:request_uri){parsed_uri.request_uri}
|
145
|
+
let(:request_object){Net::HTTP::Post.new(request_uri)}
|
146
|
+
|
147
|
+
before do
|
148
|
+
stub_request(:post, "http://example.com/path").
|
149
|
+
with(body: json_data, headers: headers).
|
150
|
+
to_return(status: 200, body: '', headers: {})
|
151
|
+
end
|
152
|
+
|
153
|
+
it "sets the body" do
|
154
|
+
allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
155
|
+
response = HTTP.post(uri, args, headers)
|
156
|
+
expect(request_object.body).to eq(json_data)
|
157
|
+
expect(response.success?).to eq(true)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "creates a new Net::HTTP::Post object" do
|
161
|
+
expect(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
162
|
+
response = HTTP.post(uri, args, headers)
|
163
|
+
expect(response.success?).to eq(true)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
109
167
|
context "with headers supplied" do
|
110
168
|
let(:uri){'http://example.com/path'}
|
111
169
|
let(:parsed_uri){URI.parse(uri)}
|
@@ -127,6 +185,54 @@ describe ".post" do
|
|
127
185
|
end
|
128
186
|
end
|
129
187
|
|
188
|
+
context "when different content-type header key cases are supplied" do
|
189
|
+
let(:uri){'http://example.com/path'}
|
190
|
+
let(:parsed_uri){URI.parse(uri)}
|
191
|
+
let(:headers) do; {content_type_key => 'application/json'}; end
|
192
|
+
let(:request_uri){parsed_uri.request_uri}
|
193
|
+
let(:request_object){Net::HTTP::Post.new(request_uri)}
|
194
|
+
let(:args)do; {a: 1, b: 2}; end
|
195
|
+
|
196
|
+
before do
|
197
|
+
stub_request(:post, 'http://example.com/path').
|
198
|
+
with(headers: {'Content-Type'=>'application/json'}).
|
199
|
+
to_return(status: 200, body: '', headers: {})
|
200
|
+
end
|
201
|
+
|
202
|
+
context "title-cased" do
|
203
|
+
let(:content_type_key){'Content-Type'}
|
204
|
+
|
205
|
+
it "detects the content type" do
|
206
|
+
allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
207
|
+
response = HTTP.post(uri, args, headers)
|
208
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
209
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "title-case only at the start" do
|
214
|
+
let(:content_type_key){'Content-type'}
|
215
|
+
|
216
|
+
it "detects the content type" do
|
217
|
+
allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
218
|
+
response = HTTP.post(uri, args, headers)
|
219
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
220
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "lowercase" do
|
225
|
+
let(:content_type_key){'content-type'}
|
226
|
+
|
227
|
+
it "detects the content type" do
|
228
|
+
allow(Net::HTTP::Post).to receive(:new).with(request_uri).and_return(request_object)
|
229
|
+
response = HTTP.post(uri, args, headers)
|
230
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
231
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
130
236
|
context "with options supplied" do
|
131
237
|
let(:uri){'http://example.com/path'}
|
132
238
|
let(:parsed_uri){URI.parse(uri)}
|
data/spec/HTTP/put_spec.rb
CHANGED
@@ -70,7 +70,36 @@ describe ".put" do
|
|
70
70
|
expect(response.success?).to eq(true)
|
71
71
|
end
|
72
72
|
|
73
|
-
it "creates a new Net::HTTP::
|
73
|
+
it "creates a new Net::HTTP::Put 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 raw form 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}.x_www_form_urlencode; end
|
84
|
+
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
|
85
|
+
let(:encoded_form_data){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: encoded_form_data, headers: headers).
|
92
|
+
to_return(status: 200, body: '', headers: {})
|
93
|
+
end
|
94
|
+
|
95
|
+
it "sets the form data" 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(encoded_form_data)
|
99
|
+
expect(response.success?).to eq(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates a new Net::HTTP::Put object" do
|
74
103
|
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
75
104
|
response = HTTP.put(uri, args, headers)
|
76
105
|
expect(response.success?).to eq(true)
|
@@ -99,7 +128,36 @@ describe ".put" do
|
|
99
128
|
expect(response.success?).to eq(true)
|
100
129
|
end
|
101
130
|
|
102
|
-
it "creates a new Net::HTTP::
|
131
|
+
it "creates a new Net::HTTP::Put object" do
|
132
|
+
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
133
|
+
response = HTTP.put(uri, args, headers)
|
134
|
+
expect(response.success?).to eq(true)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
context "with raw JSON data supplied" do
|
139
|
+
let(:uri){'http://example.com/path'}
|
140
|
+
let(:parsed_uri){URI.parse(uri)}
|
141
|
+
let(:args) do; JSON.dump({a: 1, b: 2}); end
|
142
|
+
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
|
143
|
+
let(:json_data){args}
|
144
|
+
let(:request_uri){parsed_uri.request_uri}
|
145
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
146
|
+
|
147
|
+
before do
|
148
|
+
stub_request(:put, "http://example.com/path").
|
149
|
+
with(body: json_data, headers: headers).
|
150
|
+
to_return(status: 200, body: '', headers: {})
|
151
|
+
end
|
152
|
+
|
153
|
+
it "sets the body" do
|
154
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
155
|
+
response = HTTP.put(uri, args, headers)
|
156
|
+
expect(request_object.body).to eq(json_data)
|
157
|
+
expect(response.success?).to eq(true)
|
158
|
+
end
|
159
|
+
|
160
|
+
it "creates a new Net::HTTP::Put object" do
|
103
161
|
expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
104
162
|
response = HTTP.put(uri, args, headers)
|
105
163
|
expect(response.success?).to eq(true)
|
@@ -127,6 +185,54 @@ describe ".put" do
|
|
127
185
|
end
|
128
186
|
end
|
129
187
|
|
188
|
+
context "when different content-type header key cases are supplied" do
|
189
|
+
let(:uri){'http://example.com/path'}
|
190
|
+
let(:parsed_uri){URI.parse(uri)}
|
191
|
+
let(:headers) do; {content_type_key => 'application/json'}; end
|
192
|
+
let(:request_uri){parsed_uri.request_uri}
|
193
|
+
let(:request_object){Net::HTTP::Put.new(request_uri)}
|
194
|
+
let(:args)do; {a: 1, b: 2}; end
|
195
|
+
|
196
|
+
before do
|
197
|
+
stub_request(:put, 'http://example.com/path').
|
198
|
+
with(headers: {'Content-Type'=>'application/json'}).
|
199
|
+
to_return(status: 200, body: '', headers: {})
|
200
|
+
end
|
201
|
+
|
202
|
+
context "title-cased" do
|
203
|
+
let(:content_type_key){'Content-Type'}
|
204
|
+
|
205
|
+
it "detects the content type" do
|
206
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
207
|
+
response = HTTP.put(uri, args, headers)
|
208
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
209
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "title-case only at the start" do
|
214
|
+
let(:content_type_key){'Content-type'}
|
215
|
+
|
216
|
+
it "detects the content type" do
|
217
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
218
|
+
response = HTTP.put(uri, args, headers)
|
219
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
220
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "lowercase" do
|
225
|
+
let(:content_type_key){'content-type'}
|
226
|
+
|
227
|
+
it "detects the content type" do
|
228
|
+
allow(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
|
229
|
+
response = HTTP.put(uri, args, headers)
|
230
|
+
expect(request_object['Content-Type']).to eq('application/json') # The request object doesn't care about the case of the content-type key.
|
231
|
+
expect(request_object.body).to eq(JSON.dump(args))
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
130
236
|
context "with options supplied" do
|
131
237
|
let(:uri){'http://example.com/path'}
|
132
238
|
let(:parsed_uri){URI.parse(uri)}
|
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.16.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thoran
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-
|
10
|
+
date: 2025-09-08 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,
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.7.1
|
62
62
|
specification_version: 4
|
63
63
|
summary: HTTP made easy.
|
64
64
|
test_files: []
|