http.rb 0.15.1 → 0.16.0

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: 7eeee894fa63eb3d4e2ffe9fb35f9521111adc63b05261b56dd691e0f74f2613
4
- data.tar.gz: ef36a1ad9059459da8f1941f6c7e2ca9c5150466d7944a1fd8278bf403311008
3
+ metadata.gz: c1bb42ba9827c2b10169f1b07d2069e915dec971e178b2d91f5bbb9c0fe88b95
4
+ data.tar.gz: 416d60a22b86594a059fe05d5747ea51c4728dda0f3626e8214f06e5e56304aa
5
5
  SHA512:
6
- metadata.gz: c02f7c9af8804c92de600e42bcbb161236826503b1be6e184704aa12e214b2665c195aa827610772780dfc9a3a7cf45b8f4bf13500959b4c34a88a241334a81c
7
- data.tar.gz: abbd416370db5c0b118b259e284a2d5ba1ca1ae6bda9dde3f9b20826f37fbff4a57dacfa7e90b4bf52b49c0ee8116d53f83a1dfcf5c2eed3e5d2364fc3825b13
6
+ metadata.gz: bc19d82645746f5e386b4a32e7a9fd297123c65e56ad1e45f26f4a3c88f5d383a90f477721aadc953cae11c7d97fbd2654030003b286271642a260cac133eb75
7
+ data.tar.gz: 3fc2406bd6b52e34a1da18306fa22c8f2765343b6cc5c224b9200cef9d1d29192ee7061921457877ffd0a81cb93355fadb61749a2004cddb70e32196136323e6
data/CHANGELOG.txt CHANGED
@@ -1,7 +1,19 @@
1
+ # 20250809
2
+ # 0.16.0: Allow passing of a raw payload for POST/PUT.
3
+ 1. ~ HTTP.post: Check for Content-Type and whether a string.
4
+ 2. ~ HTTP.put: Check for Content-Type and whether a string.
5
+ 3. ~ spec/HTTP/post_spec.rb: + raw form data example
6
+ 4. ~ spec/HTTP/post_spec.rb: + raw JSON example
7
+ 5. ~ spec/HTTP/put_spec.rb: + raw form data example
8
+ 6. ~ spec/HTTP/put_spec.rb: + raw JSON example
9
+ 7. ~ HTTP::VERSION: /0.15.1/0.16.0/
10
+ 8. ~ CHANGELOG.txt: + 0.16.0 entry; Small edit on 0.15.1.
11
+ 9. ~ http.rb.gemspec: Change date.
12
+
1
13
  # 20250721
2
14
  # 0.15.1: Fix PUT; require delete and put in the load file.
3
- 1. + require 'HTTP/post'
4
- 2. + require 'HTTP/put'
15
+ 1. + require 'HTTP/put'
16
+ 2. + require 'HTTP/delete'
5
17
  3. ~ HTTP/put.rb: Params in the body!
6
18
  3. ~ spec/HTTP/put_spec.rb: Remove copy-pasta rubbish.
7
19
  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-07-21'
6
+ s.date = '2025-08-09'
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.15.1'
5
+ VERSION = '0.16.0'
6
6
  end
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
- if headers['Content-Type'] == 'application/json'
26
- request_object.body = JSON.dump(data)
25
+ content_type = headers['Content-Type'].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
- request_object.form_data = data
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
- if headers['Content-Type'] == 'application/json'
26
- request_object.body = JSON.dump(data)
25
+ content_type = headers['Content-Type'].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
- request_object.form_data = data
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
@@ -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)}
@@ -77,6 +77,35 @@ describe ".put" 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::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::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
+
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 ".put" 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::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::Post object" do
161
+ expect(Net::HTTP::Put).to receive(:new).with(request_uri).and_return(request_object)
162
+ response = HTTP.put(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)}
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.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-07-21 00:00:00.000000000 Z
10
+ date: 2025-08-09 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.6.9
61
+ rubygems_version: 3.7.1
62
62
  specification_version: 4
63
63
  summary: HTTP made easy.
64
64
  test_files: []