http.rb 0.16.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1bb42ba9827c2b10169f1b07d2069e915dec971e178b2d91f5bbb9c0fe88b95
4
- data.tar.gz: 416d60a22b86594a059fe05d5747ea51c4728dda0f3626e8214f06e5e56304aa
3
+ metadata.gz: 29514ef093a2f03e4936ba26f13673c8a6696058aaf555c5e0a5a0167f7c19cd
4
+ data.tar.gz: 21a5f38db7c4e93fb3cd57deba7bf17154737c341b7c25f32e206fc24e9fc37f
5
5
  SHA512:
6
- metadata.gz: bc19d82645746f5e386b4a32e7a9fd297123c65e56ad1e45f26f4a3c88f5d383a90f477721aadc953cae11c7d97fbd2654030003b286271642a260cac133eb75
7
- data.tar.gz: 3fc2406bd6b52e34a1da18306fa22c8f2765343b6cc5c224b9200cef9d1d29192ee7061921457877ffd0a81cb93355fadb61749a2004cddb70e32196136323e6
6
+ metadata.gz: 23ceeaa56c2963b88119409fa4b29cd85048cba6523f77eb7bdf47762837a83b494a5c3d7f44e011ea66649028e37e19be5e10a9fa64a468f7d9f432087d6b4e
7
+ data.tar.gz: 320c109717cf4ffdbafdce41cdd83ea96ec3c0fb79bd4a300fa58c324679c4e4f83503ffa912e376f6c3655d1bdb0facaa58989984b1d6f0fd997c558ed1f342
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,14 @@
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
+
1
12
  # 20250809
2
13
  # 0.16.0: Allow passing of a raw payload for POST/PUT.
3
14
  1. ~ HTTP.post: Check for Content-Type and whether a string.
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-08-09'
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
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '0.16.0'
5
+ VERSION = '0.16.1'
6
6
  end
data/lib/HTTP/post.rb CHANGED
@@ -22,7 +22,7 @@ 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
- content_type = headers['Content-Type'].to_s
25
+ content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
26
26
  if content_type.start_with?('application/json')
27
27
  if data.is_a?(String)
28
28
  request_object.body = data
data/lib/HTTP/put.rb CHANGED
@@ -22,7 +22,7 @@ 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
- content_type = headers['Content-Type'].to_s
25
+ content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
26
26
  if content_type.start_with?('application/json')
27
27
  if data.is_a?(String)
28
28
  request_object.body = data
@@ -185,6 +185,54 @@ describe ".post" do
185
185
  end
186
186
  end
187
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
+
188
236
  context "with options supplied" do
189
237
  let(:uri){'http://example.com/path'}
190
238
  let(:parsed_uri){URI.parse(uri)}
@@ -70,7 +70,7 @@ describe ".put" do
70
70
  expect(response.success?).to eq(true)
71
71
  end
72
72
 
73
- it "creates a new Net::HTTP::Post object" do
73
+ it "creates a new Net::HTTP::Put object" do
74
74
  expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
75
75
  response = HTTP.put(uri, args, headers)
76
76
  expect(response.success?).to eq(true)
@@ -99,7 +99,7 @@ describe ".put" do
99
99
  expect(response.success?).to eq(true)
100
100
  end
101
101
 
102
- it "creates a new Net::HTTP::Post object" do
102
+ it "creates a new Net::HTTP::Put object" do
103
103
  expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
104
104
  response = HTTP.put(uri, args, headers)
105
105
  expect(response.success?).to eq(true)
@@ -128,7 +128,7 @@ describe ".put" do
128
128
  expect(response.success?).to eq(true)
129
129
  end
130
130
 
131
- it "creates a new Net::HTTP::Post object" do
131
+ it "creates a new Net::HTTP::Put object" do
132
132
  expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
133
133
  response = HTTP.put(uri, args, headers)
134
134
  expect(response.success?).to eq(true)
@@ -157,7 +157,7 @@ describe ".put" do
157
157
  expect(response.success?).to eq(true)
158
158
  end
159
159
 
160
- it "creates a new Net::HTTP::Post object" do
160
+ it "creates a new Net::HTTP::Put object" do
161
161
  expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
162
162
  response = HTTP.put(uri, args, headers)
163
163
  expect(response.success?).to eq(true)
@@ -185,6 +185,54 @@ describe ".put" do
185
185
  end
186
186
  end
187
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
+
188
236
  context "with options supplied" do
189
237
  let(:uri){'http://example.com/path'}
190
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.16.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-08-09 00:00:00.000000000 Z
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,