http.rb 0.16.0 → 0.17.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 +4 -4
- data/CHANGELOG.txt +28 -0
- data/http.rb.gemspec +1 -1
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/delete.rb +6 -40
- data/lib/HTTP/get.rb +6 -39
- data/lib/HTTP/post.rb +8 -48
- data/lib/HTTP/put.rb +8 -48
- data/lib/HTTP/request.rb +46 -0
- data/lib/Hash/x_www_form_urlencode.rb +1 -11
- data/lib/Net/HTTP/set_options.rb +1 -4
- data/lib/Net/HTTPRequest/set_headers.rb +13 -0
- data/lib/Net/HTTPResponse/StatusPredicates.rb +3 -0
- data/lib/URI/Generic/use_sslQ.rb +1 -7
- data/spec/HTTP/post_spec.rb +48 -0
- data/spec/HTTP/put_spec.rb +52 -4
- metadata +5 -7
- data/lib/Net/HTTP/Delete/set_headers.rb +0 -14
- data/lib/Net/HTTP/Get/set_headers.rb +0 -17
- data/lib/Net/HTTP/Post/set_headers.rb +0 -17
- data/lib/Net/HTTP/Put/set_headers.rb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2d9519c8ef1eb2d71220644e255d595a472ecc23248eed892a7a0bb3eee8f5e3
|
|
4
|
+
data.tar.gz: dc4da67e9c806dd30f4b0c9cc989a6d42116f4147c0bcaef7dd7eee2430f9f4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 156c9ea7fe6f112d1987edce3557c60166c3f23c15b8fbb6c58cc8a6603bd1f2146eb073fc013778c5e40f4038c52c115a9ae6cf0d100b50e15615e19aa640a0
|
|
7
|
+
data.tar.gz: 9e67a7ca0e436c137591757b8ca1d61497b2b6a3649f5d7c5c9fb2266abf936b16c7949538d71dc71fd9cb7a96f792af216d5d9b40d3146f6577f1fcc2d1df3e
|
data/CHANGELOG.txt
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
# 20260325
|
|
2
|
+
# 0.17.0: Extract HTTP.request method; consolidate set_headers.
|
|
3
|
+
1. + HTTP.request: Extract common plumbing (connection, SSL, auth, redirect, response) from verb methods.
|
|
4
|
+
2. ~ HTTP.get: Delegate to HTTP.request.
|
|
5
|
+
3. ~ HTTP.delete: Delegate to HTTP.request.
|
|
6
|
+
4. ~ HTTP.post: Delegate to HTTP.request.
|
|
7
|
+
5. ~ HTTP.put: Delegate to HTTP.request.
|
|
8
|
+
6. + Net::HTTPRequest#set_headers: Consolidate per-verb set_headers into single method on superclass.
|
|
9
|
+
7. - Net::HTTP::Get#set_headers
|
|
10
|
+
8. - Net::HTTP::Post#set_headers
|
|
11
|
+
9. - Net::HTTP::Put#set_headers
|
|
12
|
+
10. - Net::HTTP::Delete#set_headers
|
|
13
|
+
11. + TODO.txt
|
|
14
|
+
12. ~ HTTP::VERSION: /0.16.1/0.17.0/
|
|
15
|
+
13. ~ CHANGELOG.txt: + 0.17.0 entry
|
|
16
|
+
14. ~ http.rb.gemspec: Change date.
|
|
17
|
+
|
|
18
|
+
# 20250908
|
|
19
|
+
# 0.16.1: Allow any case for the content-type key.
|
|
20
|
+
1. ~ HTTP.post: Check for any case for content-type key.
|
|
21
|
+
2. ~ HTTP.put: Check for any case for content-type key.
|
|
22
|
+
3. ~ spec/HTTP/post_spec.rb: + specs for different content-type key cases.
|
|
23
|
+
4. ~ spec/HTTP/put_spec.rb: + specs for different content-type key cases.
|
|
24
|
+
5. ~ spec/HTTP/put_spec.rb: Fix some erroneous references to (P|p)ost.
|
|
25
|
+
6. ~ HTTP::VERSION: /0.16.0/0.16.1/
|
|
26
|
+
7. ~ CHANGELOG.txt: + 0.16.1 entry
|
|
27
|
+
8. ~ http.rb.gemspec: Change date.
|
|
28
|
+
|
|
1
29
|
# 20250809
|
|
2
30
|
# 0.16.0: Allow passing of a raw payload for POST/PUT.
|
|
3
31
|
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 = '
|
|
6
|
+
s.date = '2026-03-25'
|
|
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
|
@@ -2,54 +2,20 @@
|
|
|
2
2
|
# HTTP.delete
|
|
3
3
|
|
|
4
4
|
require 'net/http'
|
|
5
|
-
require 'openssl'
|
|
6
|
-
require 'uri'
|
|
7
5
|
|
|
8
6
|
require_relative '../Hash/x_www_form_urlencode'
|
|
9
|
-
require_relative '
|
|
10
|
-
require_relative '../Net/HTTP/set_options'
|
|
11
|
-
require_relative '../Net/HTTP/Delete/set_headers'
|
|
12
|
-
require_relative '../Net/HTTPResponse/StatusPredicates'
|
|
13
|
-
require_relative '../URI/Generic/use_sslQ'
|
|
7
|
+
require_relative './request'
|
|
14
8
|
|
|
15
9
|
module HTTP
|
|
16
|
-
|
|
17
10
|
def delete(uri, args = {}, headers = {}, options = {}, &block)
|
|
18
11
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
|
23
|
-
http.options = options
|
|
24
|
-
if args.empty?
|
|
25
|
-
request_object = Net::HTTP::Delete.new(uri.request_uri)
|
|
26
|
-
else
|
|
27
|
-
request_object = Net::HTTP::Delete.new(uri.request_uri + '?' + args.x_www_form_urlencode)
|
|
28
|
-
end
|
|
29
|
-
request_object.headers = headers
|
|
30
|
-
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
31
|
-
response = http.request(request_object)
|
|
32
|
-
if response.code =~ /^3/
|
|
33
|
-
if block_given? && no_redirect
|
|
34
|
-
yield response
|
|
35
|
-
elsif no_redirect
|
|
36
|
-
return response
|
|
37
|
-
end
|
|
38
|
-
redirect_uri = URI.parse(response.header['location'])
|
|
39
|
-
if redirect_uri.scheme
|
|
40
|
-
response = get(response.header['location'], {}, {}, options, &block)
|
|
41
|
-
else
|
|
42
|
-
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
|
43
|
-
response = get(new_location, {}, {}, options, &block)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
if block_given?
|
|
47
|
-
yield response
|
|
48
|
-
else
|
|
49
|
-
response
|
|
12
|
+
request_uri = uri.request_uri
|
|
13
|
+
unless args.empty?
|
|
14
|
+
request_uri += '?' + args.x_www_form_urlencode
|
|
50
15
|
end
|
|
16
|
+
request_object = Net::HTTP::Delete.new(request_uri)
|
|
17
|
+
request(uri, request_object, headers, options, &block)
|
|
51
18
|
end
|
|
52
19
|
|
|
53
20
|
module_function :delete
|
|
54
|
-
|
|
55
21
|
end
|
data/lib/HTTP/get.rb
CHANGED
|
@@ -2,53 +2,20 @@
|
|
|
2
2
|
# HTTP.get
|
|
3
3
|
|
|
4
4
|
require 'net/http'
|
|
5
|
-
require 'openssl'
|
|
6
|
-
require 'uri'
|
|
7
5
|
|
|
8
6
|
require_relative '../Hash/x_www_form_urlencode'
|
|
9
|
-
require_relative '
|
|
10
|
-
require_relative '../Net/HTTP/Get/set_headers'
|
|
11
|
-
require_relative '../Net/HTTPResponse/StatusPredicates'
|
|
12
|
-
require_relative '../URI/Generic/use_sslQ'
|
|
7
|
+
require_relative './request'
|
|
13
8
|
|
|
14
9
|
module HTTP
|
|
15
|
-
|
|
16
10
|
def get(uri, args = {}, headers = {}, options = {}, &block)
|
|
17
11
|
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
|
22
|
-
http.options = options
|
|
23
|
-
if args.empty?
|
|
24
|
-
request_object = Net::HTTP::Get.new(uri.request_uri)
|
|
25
|
-
else
|
|
26
|
-
request_object = Net::HTTP::Get.new(uri.request_uri + '?' + args.x_www_form_urlencode)
|
|
27
|
-
end
|
|
28
|
-
request_object.headers = headers
|
|
29
|
-
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
30
|
-
response = http.request(request_object)
|
|
31
|
-
if response.code =~ /^3/
|
|
32
|
-
if block_given? && no_redirect
|
|
33
|
-
yield response
|
|
34
|
-
elsif no_redirect
|
|
35
|
-
return response
|
|
36
|
-
end
|
|
37
|
-
redirect_uri = URI.parse(response.header['location'])
|
|
38
|
-
if redirect_uri.scheme
|
|
39
|
-
response = get(response.header['location'], {}, {}, options, &block)
|
|
40
|
-
else
|
|
41
|
-
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
|
42
|
-
response = get(new_location, {}, {}, options, &block)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
if block_given?
|
|
46
|
-
yield response
|
|
47
|
-
else
|
|
48
|
-
response
|
|
12
|
+
request_uri = uri.request_uri
|
|
13
|
+
unless args.empty?
|
|
14
|
+
request_uri += '?' + args.x_www_form_urlencode
|
|
49
15
|
end
|
|
16
|
+
request_object = Net::HTTP::Get.new(request_uri)
|
|
17
|
+
request(uri, request_object, headers, options, &block)
|
|
50
18
|
end
|
|
51
19
|
|
|
52
20
|
module_function :get
|
|
53
|
-
|
|
54
21
|
end
|
data/lib/HTTP/post.rb
CHANGED
|
@@ -3,63 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'net/http'
|
|
6
|
-
require 'openssl'
|
|
7
|
-
require 'uri'
|
|
8
6
|
|
|
9
|
-
require_relative '
|
|
10
|
-
require_relative '../Net/HTTP/set_options'
|
|
11
|
-
require_relative '../Net/HTTP/Post/set_headers'
|
|
12
|
-
require_relative '../Net/HTTPResponse/StatusPredicates'
|
|
13
|
-
require_relative '../URI/Generic/use_sslQ'
|
|
7
|
+
require_relative './request'
|
|
14
8
|
|
|
15
9
|
module HTTP
|
|
16
|
-
|
|
17
10
|
def post(uri, data = {}, headers = {}, options = {}, &block)
|
|
18
11
|
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
12
|
request_object = Net::HTTP::Post.new(uri.request_uri)
|
|
25
|
-
content_type = headers
|
|
26
|
-
if
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
request_object.body = JSON.dump(data)
|
|
31
|
-
end
|
|
13
|
+
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
|
14
|
+
if data.is_a?(String)
|
|
15
|
+
request_object.body = data
|
|
16
|
+
elsif content_type.start_with?('application/json')
|
|
17
|
+
request_object.body = JSON.dump(data)
|
|
32
18
|
else
|
|
33
|
-
|
|
34
|
-
request_object.body = data
|
|
35
|
-
else
|
|
36
|
-
request_object.form_data = data
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
request_object.headers = headers
|
|
40
|
-
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
41
|
-
response = http.request(request_object)
|
|
42
|
-
if response.code =~ /^3/
|
|
43
|
-
if block_given? && no_redirect
|
|
44
|
-
yield response
|
|
45
|
-
elsif no_redirect
|
|
46
|
-
return response
|
|
47
|
-
end
|
|
48
|
-
redirect_uri = URI.parse(response.header['location'])
|
|
49
|
-
if redirect_uri.scheme
|
|
50
|
-
response = get(response.header['location'], {}, {}, options, &block)
|
|
51
|
-
else
|
|
52
|
-
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
|
53
|
-
response = get(new_location, {}, {}, options, &block)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
if block_given?
|
|
57
|
-
yield response
|
|
58
|
-
else
|
|
59
|
-
response
|
|
19
|
+
request_object.form_data = data
|
|
60
20
|
end
|
|
21
|
+
request(uri, request_object, headers, options, &block)
|
|
61
22
|
end
|
|
62
23
|
|
|
63
24
|
module_function :post
|
|
64
|
-
|
|
65
25
|
end
|
data/lib/HTTP/put.rb
CHANGED
|
@@ -3,63 +3,23 @@
|
|
|
3
3
|
|
|
4
4
|
require 'json'
|
|
5
5
|
require 'net/http'
|
|
6
|
-
require 'openssl'
|
|
7
|
-
require 'uri'
|
|
8
6
|
|
|
9
|
-
require_relative '
|
|
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'
|
|
7
|
+
require_relative './request'
|
|
14
8
|
|
|
15
9
|
module HTTP
|
|
16
|
-
|
|
17
10
|
def put(uri, data = {}, headers = {}, options = {}, &block)
|
|
18
11
|
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
12
|
request_object = Net::HTTP::Put.new(uri.request_uri)
|
|
25
|
-
content_type = headers
|
|
26
|
-
if
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
request_object.body = JSON.dump(data)
|
|
31
|
-
end
|
|
13
|
+
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
|
|
14
|
+
if data.is_a?(String)
|
|
15
|
+
request_object.body = data
|
|
16
|
+
elsif content_type.start_with?('application/json')
|
|
17
|
+
request_object.body = JSON.dump(data)
|
|
32
18
|
else
|
|
33
|
-
|
|
34
|
-
request_object.body = data
|
|
35
|
-
else
|
|
36
|
-
request_object.form_data = data
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
request_object.headers = headers
|
|
40
|
-
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
41
|
-
response = http.request(request_object)
|
|
42
|
-
if response.code =~ /^3/
|
|
43
|
-
if block_given? && no_redirect
|
|
44
|
-
yield response
|
|
45
|
-
elsif no_redirect
|
|
46
|
-
return response
|
|
47
|
-
end
|
|
48
|
-
redirect_uri = URI.parse(response.header['location'])
|
|
49
|
-
if redirect_uri.scheme
|
|
50
|
-
response = get(response.header['location'], {}, {}, options, &block)
|
|
51
|
-
else
|
|
52
|
-
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
|
53
|
-
response = get(new_location, {}, {}, options, &block)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
if block_given?
|
|
57
|
-
yield response
|
|
58
|
-
else
|
|
59
|
-
response
|
|
19
|
+
request_object.form_data = data
|
|
60
20
|
end
|
|
21
|
+
request(uri, request_object, headers, options, &block)
|
|
61
22
|
end
|
|
62
23
|
|
|
63
24
|
module_function :put
|
|
64
|
-
|
|
65
25
|
end
|
data/lib/HTTP/request.rb
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# HTTP/request.rb
|
|
2
|
+
# HTTP.request
|
|
3
|
+
|
|
4
|
+
require 'net/http'
|
|
5
|
+
require 'openssl'
|
|
6
|
+
require 'uri'
|
|
7
|
+
|
|
8
|
+
require_relative '../Net/HTTP/set_options'
|
|
9
|
+
require_relative '../Net/HTTPRequest/set_headers'
|
|
10
|
+
require_relative '../Net/HTTPResponse/StatusPredicates'
|
|
11
|
+
require_relative '../URI/Generic/use_sslQ'
|
|
12
|
+
|
|
13
|
+
module HTTP
|
|
14
|
+
def request(uri, request_object, headers = {}, options = {}, &block)
|
|
15
|
+
uri = uri.is_a?(URI) ? uri : URI.parse(uri)
|
|
16
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
17
|
+
no_redirect = options.delete(:no_redirect)
|
|
18
|
+
options[:use_ssl] ||= uri.use_ssl?
|
|
19
|
+
options[:verify_mode] ||= OpenSSL::SSL::VERIFY_NONE
|
|
20
|
+
http.options = options
|
|
21
|
+
request_object.headers = headers
|
|
22
|
+
request_object.basic_auth(uri.user, uri.password) if uri.user
|
|
23
|
+
response = http.request(request_object)
|
|
24
|
+
if response.code =~ /^3/
|
|
25
|
+
if block_given? && no_redirect
|
|
26
|
+
yield response
|
|
27
|
+
elsif no_redirect
|
|
28
|
+
return response
|
|
29
|
+
end
|
|
30
|
+
redirect_uri = URI.parse(response.header['location'])
|
|
31
|
+
if redirect_uri.scheme
|
|
32
|
+
response = get(response.header['location'], {}, {}, options, &block)
|
|
33
|
+
else
|
|
34
|
+
new_location = "http://#{uri.host}:#{uri.port}#{response.header['location']}"
|
|
35
|
+
response = get(new_location, {}, {}, options, &block)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
if block_given?
|
|
39
|
+
yield response
|
|
40
|
+
else
|
|
41
|
+
response
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
module_function :request
|
|
46
|
+
end
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
# Hash/x_www_form_urlencode.rb
|
|
2
2
|
# Hash#x_www_form_urlencode
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes: Extracted from MtGox library.
|
|
8
|
-
|
|
9
|
-
# Todo:
|
|
10
|
-
# 1. I should separate out the functionality for adding '+' characters so as it can do both styles of encoding. That way I could reuse the existing Hash/to_parameter_string method as well...
|
|
11
|
-
|
|
12
|
-
require 'String/url_encode'
|
|
4
|
+
require_relative '../String/url_encode'
|
|
13
5
|
|
|
14
6
|
class Hash
|
|
15
|
-
|
|
16
7
|
def x_www_form_urlencode(joiner = '&')
|
|
17
8
|
inject([]){|a,e| a << "#{e.first.to_s.url_encode.gsub(/ /, '+')}=#{e.last.to_s.url_encode.gsub(/ /, '+')}" unless e.last.nil?; a}.join(joiner)
|
|
18
9
|
end
|
|
19
|
-
|
|
20
10
|
end
|
data/lib/Net/HTTP/set_options.rb
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
# Net/HTTP/set_options.rb
|
|
2
2
|
# Net::HTTP#set_options
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
4
|
+
require 'net/http'
|
|
6
5
|
|
|
7
6
|
module Net
|
|
8
7
|
class HTTP
|
|
9
|
-
|
|
10
8
|
def set_options(options = {})
|
|
11
9
|
options.each{|k,v| self.send("#{k}=", v)}
|
|
12
10
|
end
|
|
13
11
|
alias_method :options=, :set_options
|
|
14
|
-
|
|
15
12
|
end
|
|
16
13
|
end
|
data/lib/URI/Generic/use_sslQ.rb
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
# URI/Generic/use_sslQ.rb
|
|
2
2
|
# URI::Generic#use_ssl?
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes:
|
|
8
|
-
# 1. Using the date from when first created in HTTP.get/post as the creation date.
|
|
4
|
+
require 'uri'
|
|
9
5
|
|
|
10
6
|
module URI
|
|
11
7
|
class Generic
|
|
12
|
-
|
|
13
8
|
def use_ssl?
|
|
14
9
|
scheme == 'https' ? true : false
|
|
15
10
|
end
|
|
16
|
-
|
|
17
11
|
end
|
|
18
12
|
end
|
data/spec/HTTP/post_spec.rb
CHANGED
|
@@ -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)}
|
data/spec/HTTP/put_spec.rb
CHANGED
|
@@ -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::
|
|
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::
|
|
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::
|
|
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::
|
|
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.
|
|
4
|
+
version: 0.17.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thoran
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 2026-03-25 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,12 +27,10 @@ files:
|
|
|
27
27
|
- lib/HTTP/get.rb
|
|
28
28
|
- lib/HTTP/post.rb
|
|
29
29
|
- lib/HTTP/put.rb
|
|
30
|
+
- lib/HTTP/request.rb
|
|
30
31
|
- lib/Hash/x_www_form_urlencode.rb
|
|
31
|
-
- lib/Net/HTTP/Delete/set_headers.rb
|
|
32
|
-
- lib/Net/HTTP/Get/set_headers.rb
|
|
33
|
-
- lib/Net/HTTP/Post/set_headers.rb
|
|
34
|
-
- lib/Net/HTTP/Put/set_headers.rb
|
|
35
32
|
- lib/Net/HTTP/set_options.rb
|
|
33
|
+
- lib/Net/HTTPRequest/set_headers.rb
|
|
36
34
|
- lib/Net/HTTPResponse/StatusPredicates.rb
|
|
37
35
|
- lib/String/url_encode.rb
|
|
38
36
|
- lib/URI/Generic/use_sslQ.rb
|
|
@@ -58,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
58
56
|
- !ruby/object:Gem::Version
|
|
59
57
|
version: '0'
|
|
60
58
|
requirements: []
|
|
61
|
-
rubygems_version:
|
|
59
|
+
rubygems_version: 4.0.8
|
|
62
60
|
specification_version: 4
|
|
63
61
|
summary: HTTP made easy.
|
|
64
62
|
test_files: []
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Net/HTTP/Get/set_headers.rb
|
|
2
|
-
# Net::HTTP::Get#set_headers
|
|
3
|
-
|
|
4
|
-
# 20130310
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes:
|
|
8
|
-
# 1. Using the date from when first created in HTTP.get/post as the creation date.
|
|
9
|
-
|
|
10
|
-
class Net::HTTP::Get
|
|
11
|
-
|
|
12
|
-
def set_headers(headers = {})
|
|
13
|
-
headers.each{|k,v| self[k] = v}
|
|
14
|
-
end
|
|
15
|
-
alias_method :headers=, :set_headers
|
|
16
|
-
|
|
17
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Net/HTTP/Post/set_headers.rb
|
|
2
|
-
# Net::HTTP::Post#set_headers
|
|
3
|
-
|
|
4
|
-
# 20130309
|
|
5
|
-
# 0.0.0
|
|
6
|
-
|
|
7
|
-
# Notes:
|
|
8
|
-
# 1. Using the date from when first created in HTTP.get/post as the creation date.
|
|
9
|
-
|
|
10
|
-
class Net::HTTP::Post
|
|
11
|
-
|
|
12
|
-
def set_headers(headers = {})
|
|
13
|
-
headers.each{|k,v| self[k] = v}
|
|
14
|
-
end
|
|
15
|
-
alias_method :headers=, :set_headers
|
|
16
|
-
|
|
17
|
-
end
|