http.rb 0.17.0 → 0.18.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: 2d9519c8ef1eb2d71220644e255d595a472ecc23248eed892a7a0bb3eee8f5e3
4
- data.tar.gz: dc4da67e9c806dd30f4b0c9cc989a6d42116f4147c0bcaef7dd7eee2430f9f4a
3
+ metadata.gz: c8f29700e5af2badc9a6207ce6c3cf5ce189c6e282da3955535139b2014c1092
4
+ data.tar.gz: 121be70186382dab28df52b69f7a2e5c9501bb5891946865621250e63e85f952
5
5
  SHA512:
6
- metadata.gz: 156c9ea7fe6f112d1987edce3557c60166c3f23c15b8fbb6c58cc8a6603bd1f2146eb073fc013778c5e40f4038c52c115a9ae6cf0d100b50e15615e19aa640a0
7
- data.tar.gz: 9e67a7ca0e436c137591757b8ca1d61497b2b6a3649f5d7c5c9fb2266abf936b16c7949538d71dc71fd9cb7a96f792af216d5d9b40d3146f6577f1fcc2d1df3e
6
+ metadata.gz: b2a0ed184928d0f3656d8d9d28bcb37098759f94cf37f708c931b020c920d2d2c8f50a5a7856dcb1827759c3d8a917e5824b7266217861f21daca202533003c3
7
+ data.tar.gz: 22525a1fa099e471895bfe8cc660c728c3fcc52067b24849079b1f0c3c0e9ed50e64359c92d46de2aed7557b72d4855b39b93ab652a3fd2da122c9e5c3704df7
@@ -1,3 +1,31 @@
1
+ # 20260507
2
+ # 0.18.0: Add all missing HTTP verbs; use meta-programming to define verb methods.
3
+ 1. + HTTP/verbs.rb; including:
4
+ + HTTP::VERBS::WITHOUT_BODY: get, delete, head, options, trace
5
+ + HTTP::VERBS::WITH_BODY: post, put, patch, propfind, proppatch, mkcol, copy, move, lock, unlock, report
6
+ 2. + lib/Net/HTTP/Report.rb: Add Net::HTTP::Report, which is missing from Ruby's standard library. See RFC 3253.
7
+ 3. - lib/HTTP/delete.rb
8
+ 4. - lib/HTTP/get.rb
9
+ 5. - lib/HTTP/post.rb
10
+ 6. - lib/HTTP/put.rb
11
+ 7. + String/to_const.rb
12
+ 8. + Thoran/Array/AllButFirst/all_but_first.rb
13
+ 9. + Thoran/Array/FirstX/firstX.rb
14
+ 10. + Thoran/String/ToConst/to_const.rb
15
+ 11. + LICENSE
16
+ 12. + Rakefile
17
+ 13. + spec/HTTP/head_spec.rb
18
+ 14. + spec/HTTP/propfind_spec.rb
19
+ 15. + spec/Net/HTTP/Report_spec.rb
20
+ 16. ~ HTTP::VERSION: /0.17.0/0.18.0/
21
+ 17. /CHANGELOG.txt/CHANGELOG/
22
+ 18. /TODO.txt/TODO/
23
+ 19. ~ CHANGELOG: + 0.18.0 entry
24
+ 20. ~ http.rb.gemspec: /s/spec/; - date; + Rakefile; + development_dependencies
25
+ 21. ~ Gemfile: /group :test/gemspec/
26
+ 22. ~ .gitignore: Using a common one with lots of entries.
27
+ 23. ~ README.md: /http.rb/http/; Trimmed the Description; Usage has more code blocks, making the comments Markdown sub-sections.
28
+
1
29
  # 20260325
2
30
  # 0.17.0: Extract HTTP.request method; consolidate set_headers.
3
31
  1. + HTTP.request: Extract common plumbing (connection, SSL, auth, redirect, response) from verb methods.
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
+ # Gemfile
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
- group :test do
4
- gem 'pry', require: true
5
- gem 'rspec', require: false
6
- gem 'webmock', require: false
7
- end
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 thoran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,89 +1,94 @@
1
- # http.rb
1
+ # http
2
2
 
3
3
  ## Description
4
4
 
5
- This has been a personal library which was begun many years ago, around the middle of 2009 from what I can ascertain, though in various guises it may have been as early as late 2007. Assuming it was the former, it was long enough ago that it actually, sadly (given the diminutive size of this perhaps), predates Faraday by about 6 months (late 2009), http.rb by well over 2 years (late 2011), although it also happens to postdate HTTParty by about a year (mid 2008).
5
+ For many years this was a personal library, from around the middle of 2009 from what I can ascertain, though in various guises it may have been as early as late 2007.
6
6
 
7
- Like many others before and after me with their respective libraries, I created it to simplify the heinous interface that is Net::HTTP. At the time of it's original creation I was doing a lot of a webscraping and didn't want a half-dozen line setup to make simple requests. It has stood the test of time, for me personally insofar as the interface remaining simpler than most other similar libraries, though it is also less full featured, but nevertheless for it's tiny size it packs in quite a bit.
7
+ Like many others before and after me with their respective libraries, I created it to simplify the heinous interface that is Net::HTTP. At the time of it's original creation I was doing a lot of a webscraping and didn't want a half-dozen line setup to make simple requests. It has stood the test of time, for me personally insofar as the interface remaining simpler than most other similar libraries, though it is also less full featured, but nevertheless for it's tiny size it packs in quite a bit.
8
8
 
9
- From inception to early 2013 this was used as a front-end for Mechanize for the purpose of being able to jump out of being a pure web client and to just 'go at' a resource I was after, but still return a Mechanize object so that I could then resume a web client session. Eventually I decided to wrap Net::HTTP and then manually use Nokogiri instead, since I would either use Mechanize largely as is, or I simply wanted to make straight requests without caring about caching or cookies. I may allow HTTP to again return Mechanize objects optionally at some point in future as that had it's benefits, but they weren't great enough for the complications it brought if I remember correctly.
10
-
11
- Even so, through its various incarnations the goal has basically remained the same: to have a simple way of making HTTP requests in Ruby.
12
-
13
- I'd never intended to publish this and had intended for it to remain a personal library, but decided to use it for a small project and so as it could be included with ease in a Gemfile it needed to be gemified and well here we are, rightly or wrongly.
14
-
15
- Perhaps someone will appreciate its relative simplicity, since it is much smaller and the usage simpler than any of the other 'wrapper' libraries mentioned above at least, such that it can be read and comprehended in full in as little as a couple of minutes. It does just enough to do most simple HTTP GET and POST requests as simply as should be.
9
+ Perhaps some will appreciate its relative simplicity, since it is much smaller and the usage simpler than any of the other 'wrapper' libraries, such that it can be read and comprehended in full in as little as a couple of minutes. It does just enough to do most simple HTTP GET and POST requests as simply as should be.
16
10
 
17
11
 
18
12
  ## Installation
19
13
 
20
14
  Add this line to your application's Gemfile:
21
15
 
22
- gem 'http.rb'
23
-
16
+ ```ruby
17
+ gem 'http.rb'
18
+ ```
24
19
 
25
20
  And then execute:
26
21
 
27
- $ bundle
28
-
29
-
30
- Or install it yourself as:
22
+ ```shell
23
+ $ bundle
24
+ ```
31
25
 
32
- $ gem install http.rb
26
+ Or install it directly:
33
27
 
28
+ ```shell
29
+ $ gem install http.rb
30
+ ```
34
31
 
35
32
  ## Usage
36
33
 
37
- ```Ruby
38
- # With just a URI
34
+ ### With just a URI
39
35
 
36
+ ```ruby
40
37
  HTTP.get('http://example.com')
41
- HTTP.post('http://example.com') # Admittedly doing a POST without providing form data probably doesn't make much sense.
38
+ ```
42
39
 
43
- # With arguments only
40
+ ### With arguments only
44
41
 
42
+ ```ruby
45
43
  HTTP.get('http://example.com', {a: 1, b: 2})
46
44
  HTTP.post('http://example.com', {a: 1, b: 2})
45
+ ```
46
+ ### With JSON data
47
47
 
48
- # With JSON data
49
-
48
+ ```ruby
50
49
  HTTP.post('http://example.com', {a: 1, b: 2}, {'Content-type' => 'application/json'})
50
+ ```
51
51
 
52
- # With custom headers only
52
+ ### With custom headers only
53
53
 
54
+ ```ruby
54
55
  HTTP.get('http://example.com', {}, {'User-Agent'=>'Custom'})
55
56
  HTTP.post('http://example.com', {}, {'User-Agent'=>'Custom'})
57
+ ```
56
58
 
57
- # With options only
59
+ ### With options only
58
60
 
61
+ ```ruby
59
62
  HTTP.get('http://example.com', {}, {}, {use_ssl: true})
60
63
  HTTP.post('http://example.com', {}, {}, {use_ssl: true})
64
+ ```
61
65
 
62
- # With a block
66
+ ### With a block
63
67
 
68
+ ```ruby
64
69
  HTTP.get('http://example.com') do |response|
65
70
  # Do stuff with a subclass of Net::HTTPResponse here...
66
71
  end
67
- HTTP.post('http://example.com') do |response|
68
- # Do stuff with a subclass of Net::HTTPResponse here...
69
- end
72
+ ```
70
73
 
71
- # With the lot
74
+ ### With the lot
72
75
 
73
- HTTP.get('http://example.com', {a: 1, b: 2}, {'User-Agent'=>'Custom'}, {use_ssl: true}) do |response|
74
- # Do stuff with a subclass of Net::HTTPResponse here...
75
- end
76
+ ```ruby
76
77
  HTTP.post('http://example.com', {a: 1, b: 2}, {'User-Agent'=>'Custom'}, {use_ssl: true}) do |response|
77
78
  # Do stuff with a subclass of Net::HTTPResponse here...
78
79
  end
80
+ ```
79
81
 
80
- # Preventing redirections
82
+ ### Preventing redirections
81
83
 
84
+ ```ruby
82
85
  HTTP.get('http://example.com', {}, {}, {no_redirect: true})
83
86
  # => #<Net::HTTPResponse @code=3xx>
87
+ ```
84
88
 
85
- # Response status predicate methods
89
+ ### Response status predicate methods
86
90
 
91
+ ```ruby
87
92
  # 1xx
88
93
  response = HTTP.get('http://example.com')
89
94
  response.informational?
@@ -126,23 +131,26 @@ response.server_error?
126
131
  # => true
127
132
  response.error?
128
133
  # => true
134
+ ```
129
135
 
130
- # Including it in a class
136
+ ### Including it in a class
131
137
 
138
+ ```ruby
132
139
  class A
133
140
  include HTTP
134
141
  def a
135
142
  get('http://example.com')
136
143
  end
137
144
  end
145
+ ```
138
146
 
139
- # Extending a class
147
+ ### Extending a class
140
148
 
149
+ ```ruby
141
150
  class A
142
151
  extend HTTP
143
152
  get('http://example.com')
144
153
  end
145
-
146
154
  ```
147
155
 
148
156
  ## Allowed values for the options hash
@@ -239,8 +247,12 @@ verify_mode
239
247
 
240
248
  ## Contributing
241
249
 
242
- 1. Fork it ( https://github.com/thoran/HTTP/fork )
250
+ 1. Fork it ( https://github.com/thoran/http/fork )
243
251
  2. Create your feature branch (`git checkout -b my-new-feature`)
244
252
  3. Commit your changes (`git commit -am 'Add some feature'`)
245
253
  4. Push to the branch (`git push origin my-new-feature`)
246
254
  5. Create a new pull request
255
+
256
+ ## Licence
257
+
258
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ # Rakefile
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.verbose = false
7
+ end
8
+
9
+ task default: :spec
data/http.rb.gemspec CHANGED
@@ -1,26 +1,43 @@
1
1
  require_relative './lib/HTTP/VERSION'
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = 'http.rb'
5
- s.version = HTTP::VERSION
6
- s.date = '2026-03-25'
3
+ class Gem::Specification
4
+ def development_dependencies=(gems)
5
+ gems.each{|gem| add_development_dependency(*gem)}
6
+ end
7
+ end
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'http.rb'
11
+ spec.version = HTTP::VERSION
7
12
 
8
- s.summary = "HTTP made easy."
9
- s.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
13
+ spec.summary = "HTTP made easy."
14
+ spec.description = "HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, \
10
15
  some optional query arguments, some optional headers, and some \
11
16
  Net::HTTP options, and that's it!"
12
- s.author = 'thoran'
13
- s.email = 'code@thoran.com'
14
- s.homepage = "http://github.com/thoran/HTTP"
15
17
 
16
- s.files = [
17
- 'CHANGELOG.txt',
18
+ spec.author = 'thoran'
19
+ spec.email = 'code@thoran.com'
20
+ spec.homepage = "http://github.com/thoran/HTTP"
21
+ spec.license = 'MIT'
22
+
23
+ spec.required_ruby_version = '>= 2.7'
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.files = [
27
+ 'http.rb.gemspec',
28
+ 'CHANGELOG',
18
29
  'Gemfile',
30
+ 'LICENSE',
31
+ 'Rakefile',
19
32
  'README.md',
20
- 'http.rb.gemspec',
21
33
  Dir['lib/**/*.rb'],
22
- Dir['spec/**/*.rb']
34
+ Dir['spec/**/*.rb'],
23
35
  ].flatten
24
36
 
25
- s.require_paths = ['lib']
37
+ spec.development_dependencies = %w{
38
+ pry
39
+ rake
40
+ rspec
41
+ webmock
42
+ }
26
43
  end
data/lib/HTTP/VERSION.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # HTTP::VERSION
3
3
 
4
4
  module HTTP
5
- VERSION = '0.17.0'
5
+ VERSION = '0.18.0'
6
6
  end
data/lib/HTTP/verbs.rb ADDED
@@ -0,0 +1,49 @@
1
+ # HTTP/verbs.rb
2
+ # HTTP.verb
3
+
4
+ require 'json'
5
+ require 'net/http'
6
+
7
+ require_relative '../Hash/x_www_form_urlencode'
8
+ require_relative '../Net/HTTP/Report'
9
+ require_relative './request'
10
+ require_relative '../String/to_const'
11
+
12
+ module HTTP
13
+ module VERBS
14
+ WITHOUT_BODY = %i{get delete head options trace}
15
+ WITH_BODY = %i{post put patch propfind proppatch mkcol copy move lock unlock report}
16
+ end
17
+
18
+ VERBS::WITHOUT_BODY.each do |verb|
19
+ define_method(verb) do |uri, args = {}, headers = {}, options = {}, &block|
20
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
21
+ request_uri = uri.request_uri
22
+ unless args.empty?
23
+ request_uri += '?' + args.x_www_form_urlencode
24
+ end
25
+ request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(request_uri)
26
+ request(uri, request_object, headers, options, &block)
27
+ end
28
+
29
+ module_function verb
30
+ end
31
+
32
+ VERBS::WITH_BODY.each do |verb|
33
+ define_method(verb) do |uri, data = {}, headers = {}, options = {}, &block|
34
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
35
+ request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(uri.request_uri)
36
+ content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
37
+ if data.is_a?(String)
38
+ request_object.body = data
39
+ elsif content_type.start_with?('application/json')
40
+ request_object.body = JSON.dump(data)
41
+ else
42
+ request_object.form_data = data
43
+ end
44
+ request(uri, request_object, headers, options, &block)
45
+ end
46
+
47
+ module_function verb
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ # Net/HTTP/Report.rb
2
+ # Net::HTTP::Report
3
+
4
+ require 'net/http'
5
+
6
+ module Net
7
+ class HTTP
8
+ class Report < Net::HTTPRequest
9
+ METHOD = 'REPORT'
10
+ REQUEST_HAS_BODY = true
11
+ RESPONSE_HAS_BODY = true
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # String/to_const.rb
2
+ # String#to_const
3
+
4
+ # 20250819
5
+ # 0.2.0
6
+
7
+ require 'Thoran/String/ToConst/to_const'
@@ -0,0 +1,28 @@
1
+ # Thoran/Array/AllButFirst/all_but_first.rb
2
+ # Thoran::Array::AllButFirst#all_but_first
3
+
4
+ # 20141223
5
+ # 0.1.0
6
+
7
+ # Description: This returns a copy of the receiving array with the first element removed.
8
+
9
+ # Changes:
10
+ # 1. + Thoran namespace.
11
+
12
+ require 'Thoran/Array/FirstX/firstX'
13
+
14
+ module Thoran
15
+ module Array
16
+ module AllButFirst
17
+
18
+ def all_but_first
19
+ d = self.dup
20
+ d.first!
21
+ d
22
+ end
23
+
24
+ end
25
+ end
26
+ end
27
+
28
+ Array.send(:include, Thoran::Array::AllButFirst)
@@ -0,0 +1,32 @@
1
+ # Thoran/Array/FirstX/firstX.rb
2
+ # Thoran::Array::FirstX#first!
3
+
4
+ # 20180804
5
+ # 0.3.3
6
+
7
+ # Description: Sometimes it makes more sense to treat arrays this way.
8
+
9
+ # Changes since 0.2:
10
+ # 1. Added the original version 0.1.0 of the implementation to the later 0.1.0!
11
+ # 0/1
12
+ # 2. Switched the tests to spec-style.
13
+ # 1/2
14
+ # 3. Added a test for the state of the array afterward, since this is meant to be an in place change.
15
+ # 2/3
16
+ # 4. Added tests for the extended functionality introduced in the first version 0.1.0.
17
+
18
+ module Thoran
19
+ module Array
20
+ module FirstX
21
+
22
+ def first!(n = 1)
23
+ return_value = []
24
+ n.times{return_value << self.shift}
25
+ return_value.size == 1 ? return_value[0] : return_value
26
+ end
27
+
28
+ end
29
+ end
30
+ end
31
+
32
+ Array.send(:include, Thoran::Array::FirstX)
@@ -0,0 +1,47 @@
1
+ # Thoran/String/ToConst/to_const.rb
2
+ # Thoran::String::ToConst#to_const
3
+
4
+ # 20141223
5
+ # 0.2.0
6
+
7
+ # Description: This takes a string and returns a constant, with unlimited namespacing.
8
+
9
+ # History: Derived from Object#to_const 0.3.0, and superceding Object#to_const.
10
+
11
+ # Changes:
12
+ # 1. + Thoran namespace.
13
+
14
+ # Todo:
15
+ # 1. This only works for two levels of constants. Three and you're stuffed. So, this needs to be recursive...
16
+ # Done iteratively as of 0.1.0.
17
+ # 2. Make this work for symbols. However, this will only work if there's no namespacing. ie. :A is OK, but :A::B is not.
18
+
19
+ # Discussion:
20
+ # 1. Should this go separately into classes for which ::const_get will work and be removed from Object? Done as of 0.1.0.
21
+
22
+ require 'Thoran/Array/AllButFirst/all_but_first'
23
+
24
+ module Thoran
25
+ module String
26
+ module ToConst
27
+
28
+ def to_const
29
+ if self =~ /::/
30
+ constants = self.split('::')
31
+ constant = Object.const_get(constants.first)
32
+ constants = constants.all_but_first
33
+ until constants.empty? do
34
+ constant = constant.const_get(constants.shift)
35
+ end
36
+ else
37
+ constant = Object.const_get(self)
38
+ end
39
+ constant
40
+ end
41
+ alias_method :to_constant, :to_const
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ String.send(:include, Thoran::String::ToConst)
@@ -4,7 +4,4 @@
4
4
  lib_dir = File.expand_path(File.join(__FILE__, '..'))
5
5
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
6
6
 
7
- require 'HTTP/get'
8
- require 'HTTP/post'
9
- require 'HTTP/put'
10
- require 'HTTP/delete'
7
+ require 'HTTP/verbs'
@@ -1,7 +1,7 @@
1
1
  # spec/HTTP/delete_spec.rb
2
2
 
3
3
  require_relative '../spec_helper'
4
- require 'HTTP/delete'
4
+ require 'http'
5
5
 
6
6
  describe ".delete" do
7
7
  context "with uri-only supplied" do
@@ -1,7 +1,7 @@
1
1
  # spec/HTTP/get_spec.rb
2
2
 
3
3
  require_relative '../spec_helper'
4
- require 'HTTP/get'
4
+ require 'http'
5
5
 
6
6
  describe ".get" do
7
7
  context "with uri-only supplied" do
@@ -0,0 +1,118 @@
1
+ # spec/HTTP/head_spec.rb
2
+
3
+ require_relative '../spec_helper'
4
+ require 'http'
5
+
6
+ describe ".head" do
7
+ context "with uri-only supplied" do
8
+ before do
9
+ stub_request(:head, 'http://example.com/path').
10
+ to_return(status: 200, body: '', headers: {'Content-Type' => 'text/html'})
11
+ end
12
+
13
+ context "uri as a string" do
14
+ let(:uri){'http://example.com/path'}
15
+
16
+ it "returns a successful response" do
17
+ response = HTTP.head(uri)
18
+ expect(response.success?).to eq(true)
19
+ end
20
+ end
21
+
22
+ context "uri as a URI" do
23
+ let(:uri){URI.parse('http://example.com/path')}
24
+
25
+ it "returns a successful response" do
26
+ response = HTTP.head(uri)
27
+ expect(response.success?).to eq(true)
28
+ end
29
+ end
30
+ end
31
+
32
+ context "with args supplied" do
33
+ let(:uri){'http://example.com/path'}
34
+
35
+ before do
36
+ stub_request(:head, 'http://example.com/path?a=1&b=2').
37
+ to_return(status: 200, body: '', headers: {})
38
+ end
39
+
40
+ it "appends query parameters" do
41
+ response = HTTP.head(uri, {a: 1, b: 2})
42
+ expect(response.success?).to eq(true)
43
+ end
44
+ end
45
+
46
+ context "with headers supplied" do
47
+ let(:uri){'http://example.com/path'}
48
+
49
+ before do
50
+ stub_request(:head, 'http://example.com/path').
51
+ with(headers: {'User-Agent' => 'Rspec'}).
52
+ to_return(status: 200, body: '', headers: {})
53
+ end
54
+
55
+ it "sets the headers on the request" do
56
+ response = HTTP.head(uri, {}, {'User-Agent' => 'Rspec'})
57
+ expect(response.success?).to eq(true)
58
+ end
59
+ end
60
+
61
+ context "with options supplied" do
62
+ let(:uri){'http://example.com/path'}
63
+
64
+ before do
65
+ stub_request(:head, 'https://example.com:80/path').
66
+ to_return(status: 200, body: '', headers: {})
67
+ end
68
+
69
+ it "sets the use_ssl option on the Net::HTTP instance" do
70
+ response = HTTP.head(uri, {}, {}, {use_ssl: true})
71
+ expect(response.success?).to eq(true)
72
+ end
73
+ end
74
+
75
+ context "with block supplied" do
76
+ let(:uri){'http://example.com/path'}
77
+
78
+ before do
79
+ stub_request(:head, 'http://example.com/path').
80
+ to_return(status: 200, body: '', headers: {})
81
+ end
82
+
83
+ it "yields an instance of Net::HTTPResponse" do
84
+ expect{|b| HTTP.head(uri, &b)}.to yield_with_args(Net::HTTPResponse)
85
+ end
86
+ end
87
+
88
+ context "with redirection" do
89
+ let(:request_uri){'http://example.com/path'}
90
+ let(:redirect_uri){'http://redirected.com'}
91
+
92
+ before do
93
+ stub_request(:head, request_uri).
94
+ to_return(status: 301, headers: {'location' => redirect_uri})
95
+ stub_request(:get, redirect_uri).
96
+ to_return(status: 200, body: '', headers: {})
97
+ end
98
+
99
+ it "follows the redirect" do
100
+ response = HTTP.head(request_uri)
101
+ expect(response.success?).to eq(true)
102
+ end
103
+ end
104
+
105
+ context "no_redirect true" do
106
+ let(:request_uri){'http://example.com/path'}
107
+
108
+ before do
109
+ stub_request(:head, request_uri).
110
+ to_return(status: 301, headers: {'location' => 'http://redirected.com'})
111
+ end
112
+
113
+ it "returns the redirect response" do
114
+ response = HTTP.head(request_uri, {}, {}, {no_redirect: true})
115
+ expect(response.redirection?).to eq(true)
116
+ end
117
+ end
118
+ end
@@ -1,7 +1,7 @@
1
1
  # spec/HTTP/post_spec.rb
2
2
 
3
3
  require_relative '../spec_helper'
4
- require 'HTTP/post'
4
+ require 'http'
5
5
 
6
6
  describe ".post" do
7
7
  context "with uri-only supplied" do
@@ -0,0 +1,122 @@
1
+ # spec/HTTP/propfind_spec.rb
2
+
3
+ require_relative '../spec_helper'
4
+ require 'http'
5
+
6
+ describe ".propfind" do
7
+ context "with uri-only supplied" do
8
+ before do
9
+ stub_request(:propfind, 'http://example.com/dav/').
10
+ to_return(status: 207, body: '<multistatus/>', headers: {})
11
+ end
12
+
13
+ context "uri as a string" do
14
+ let(:uri){'http://example.com/dav/'}
15
+
16
+ it "returns a response" do
17
+ response = HTTP.propfind(uri)
18
+ expect(response.code).to eq('207')
19
+ end
20
+ end
21
+
22
+ context "uri as a URI" do
23
+ let(:uri){URI.parse('http://example.com/dav/')}
24
+
25
+ it "returns a response" do
26
+ response = HTTP.propfind(uri)
27
+ expect(response.code).to eq('207')
28
+ end
29
+ end
30
+ end
31
+
32
+ context "with an XML body" do
33
+ let(:uri){'http://example.com/dav/'}
34
+ let(:xml) do
35
+ '<?xml version="1.0" encoding="UTF-8"?><d:propfind xmlns:d="DAV:"><d:prop><d:displayname/></d:prop></d:propfind>'
36
+ end
37
+
38
+ before do
39
+ stub_request(:propfind, 'http://example.com/dav/').
40
+ with(body: xml).
41
+ to_return(status: 207, body: '<multistatus/>', headers: {})
42
+ end
43
+
44
+ it "sends the XML body" do
45
+ response = HTTP.propfind(uri, xml, {'Content-Type' => 'application/xml'})
46
+ expect(response.code).to eq('207')
47
+ end
48
+ end
49
+
50
+ context "with headers supplied" do
51
+ let(:uri){'http://example.com/dav/'}
52
+
53
+ before do
54
+ stub_request(:propfind, 'http://example.com/dav/').
55
+ with(headers: {'Depth' => '1', 'Content-Type' => 'application/xml'}).
56
+ to_return(status: 207, body: '<multistatus/>', headers: {})
57
+ end
58
+
59
+ it "sets the headers on the request" do
60
+ response = HTTP.propfind(uri, {}, {'Depth' => '1', 'Content-Type' => 'application/xml'})
61
+ expect(response.code).to eq('207')
62
+ end
63
+ end
64
+
65
+ context "with options supplied" do
66
+ let(:uri){'http://example.com/dav/'}
67
+
68
+ before do
69
+ stub_request(:propfind, 'https://example.com:80/dav/').
70
+ to_return(status: 207, body: '<multistatus/>', headers: {})
71
+ end
72
+
73
+ it "sets the use_ssl option on the Net::HTTP instance" do
74
+ response = HTTP.propfind(uri, {}, {}, {use_ssl: true})
75
+ expect(response.code).to eq('207')
76
+ end
77
+ end
78
+
79
+ context "with block supplied" do
80
+ let(:uri){'http://example.com/dav/'}
81
+
82
+ before do
83
+ stub_request(:propfind, 'http://example.com/dav/').
84
+ to_return(status: 207, body: '<multistatus/>', headers: {})
85
+ end
86
+
87
+ it "yields an instance of Net::HTTPResponse" do
88
+ expect{|b| HTTP.propfind(uri, &b)}.to yield_with_args(Net::HTTPResponse)
89
+ end
90
+ end
91
+
92
+ context "with redirection" do
93
+ let(:request_uri){'http://example.com/dav/'}
94
+ let(:redirect_uri){'http://redirected.com/dav/'}
95
+
96
+ before do
97
+ stub_request(:propfind, request_uri).
98
+ to_return(status: 301, headers: {'location' => redirect_uri})
99
+ stub_request(:get, redirect_uri).
100
+ to_return(status: 200, body: '', headers: {})
101
+ end
102
+
103
+ it "follows the redirect" do
104
+ response = HTTP.propfind(request_uri)
105
+ expect(response.success?).to eq(true)
106
+ end
107
+ end
108
+
109
+ context "no_redirect true" do
110
+ let(:request_uri){'http://example.com/dav/'}
111
+
112
+ before do
113
+ stub_request(:propfind, request_uri).
114
+ to_return(status: 301, headers: {'location' => 'http://redirected.com/dav/'})
115
+ end
116
+
117
+ it "returns the redirect response" do
118
+ response = HTTP.propfind(request_uri, {}, {}, {no_redirect: true})
119
+ expect(response.redirection?).to eq(true)
120
+ end
121
+ end
122
+ end
@@ -1,7 +1,7 @@
1
1
  # spec/HTTP/put_spec.rb
2
2
 
3
3
  require_relative '../spec_helper'
4
- require 'HTTP/put'
4
+ require 'http'
5
5
 
6
6
  describe ".put" do
7
7
  context "with uri-only supplied" do
@@ -0,0 +1,22 @@
1
+ # spec/Net/HTTP/Report_spec.rb
2
+
3
+ require_relative '../../spec_helper'
4
+ require 'Net/HTTP/Report'
5
+
6
+ describe Net::HTTP::Report do
7
+ it "is a subclass of Net::HTTPRequest" do
8
+ expect(Net::HTTP::Report).to be <= Net::HTTPRequest
9
+ end
10
+
11
+ it "has the correct METHOD" do
12
+ expect(Net::HTTP::Report::METHOD).to eq('REPORT')
13
+ end
14
+
15
+ it "accepts a body" do
16
+ expect(Net::HTTP::Report::REQUEST_HAS_BODY).to eq(true)
17
+ end
18
+
19
+ it "expects a response body" do
20
+ expect(Net::HTTP::Report::RESPONSE_HAS_BODY).to eq(true)
21
+ end
22
+ end
metadata CHANGED
@@ -1,14 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.17.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-03-25 00:00:00.000000000 Z
11
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: pry
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rspec
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
12
68
  description: HTTP is the simplest HTTP mezzanine library for Ruby. Supply a URI, some
13
69
  optional query arguments, some optional headers, and some Net::HTTP options,
14
70
  and that's it!
@@ -17,30 +73,38 @@ executables: []
17
73
  extensions: []
18
74
  extra_rdoc_files: []
19
75
  files:
20
- - CHANGELOG.txt
76
+ - CHANGELOG
21
77
  - Gemfile
78
+ - LICENSE
22
79
  - README.md
80
+ - Rakefile
23
81
  - http.rb.gemspec
24
- - lib/HTTP.rb
25
82
  - lib/HTTP/VERSION.rb
26
- - lib/HTTP/delete.rb
27
- - lib/HTTP/get.rb
28
- - lib/HTTP/post.rb
29
- - lib/HTTP/put.rb
30
83
  - lib/HTTP/request.rb
84
+ - lib/HTTP/verbs.rb
31
85
  - lib/Hash/x_www_form_urlencode.rb
86
+ - lib/Net/HTTP/Report.rb
32
87
  - lib/Net/HTTP/set_options.rb
33
88
  - lib/Net/HTTPRequest/set_headers.rb
34
89
  - lib/Net/HTTPResponse/StatusPredicates.rb
90
+ - lib/String/to_const.rb
35
91
  - lib/String/url_encode.rb
92
+ - lib/Thoran/Array/AllButFirst/all_but_first.rb
93
+ - lib/Thoran/Array/FirstX/firstX.rb
94
+ - lib/Thoran/String/ToConst/to_const.rb
36
95
  - lib/URI/Generic/use_sslQ.rb
96
+ - lib/http.rb
37
97
  - spec/HTTP/delete_spec.rb
38
98
  - spec/HTTP/get_spec.rb
99
+ - spec/HTTP/head_spec.rb
39
100
  - spec/HTTP/post_spec.rb
101
+ - spec/HTTP/propfind_spec.rb
40
102
  - spec/HTTP/put_spec.rb
103
+ - spec/Net/HTTP/Report_spec.rb
41
104
  - spec/spec_helper.rb
42
105
  homepage: http://github.com/thoran/HTTP
43
- licenses: []
106
+ licenses:
107
+ - MIT
44
108
  metadata: {}
45
109
  rdoc_options: []
46
110
  require_paths:
@@ -49,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
113
  requirements:
50
114
  - - ">="
51
115
  - !ruby/object:Gem::Version
52
- version: '0'
116
+ version: '2.7'
53
117
  required_rubygems_version: !ruby/object:Gem::Requirement
54
118
  requirements:
55
119
  - - ">="
56
120
  - !ruby/object:Gem::Version
57
121
  version: '0'
58
122
  requirements: []
59
- rubygems_version: 4.0.8
123
+ rubygems_version: 4.0.11
60
124
  specification_version: 4
61
125
  summary: HTTP made easy.
62
126
  test_files: []
data/lib/HTTP/delete.rb DELETED
@@ -1,21 +0,0 @@
1
- # HTTP/delete.rb
2
- # HTTP.delete
3
-
4
- require 'net/http'
5
-
6
- require_relative '../Hash/x_www_form_urlencode'
7
- require_relative './request'
8
-
9
- module HTTP
10
- def delete(uri, args = {}, headers = {}, options = {}, &block)
11
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
- request_uri = uri.request_uri
13
- unless args.empty?
14
- request_uri += '?' + args.x_www_form_urlencode
15
- end
16
- request_object = Net::HTTP::Delete.new(request_uri)
17
- request(uri, request_object, headers, options, &block)
18
- end
19
-
20
- module_function :delete
21
- end
data/lib/HTTP/get.rb DELETED
@@ -1,21 +0,0 @@
1
- # HTTP/get.rb
2
- # HTTP.get
3
-
4
- require 'net/http'
5
-
6
- require_relative '../Hash/x_www_form_urlencode'
7
- require_relative './request'
8
-
9
- module HTTP
10
- def get(uri, args = {}, headers = {}, options = {}, &block)
11
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
- request_uri = uri.request_uri
13
- unless args.empty?
14
- request_uri += '?' + args.x_www_form_urlencode
15
- end
16
- request_object = Net::HTTP::Get.new(request_uri)
17
- request(uri, request_object, headers, options, &block)
18
- end
19
-
20
- module_function :get
21
- end
data/lib/HTTP/post.rb DELETED
@@ -1,25 +0,0 @@
1
- # HTTP/post.rb
2
- # HTTP.post
3
-
4
- require 'json'
5
- require 'net/http'
6
-
7
- require_relative './request'
8
-
9
- module HTTP
10
- def post(uri, data = {}, headers = {}, options = {}, &block)
11
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
- request_object = Net::HTTP::Post.new(uri.request_uri)
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)
18
- else
19
- request_object.form_data = data
20
- end
21
- request(uri, request_object, headers, options, &block)
22
- end
23
-
24
- module_function :post
25
- end
data/lib/HTTP/put.rb DELETED
@@ -1,25 +0,0 @@
1
- # HTTP/put.rb
2
- # HTTP.put
3
-
4
- require 'json'
5
- require 'net/http'
6
-
7
- require_relative './request'
8
-
9
- module HTTP
10
- def put(uri, data = {}, headers = {}, options = {}, &block)
11
- uri = uri.is_a?(URI) ? uri : URI.parse(uri)
12
- request_object = Net::HTTP::Put.new(uri.request_uri)
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)
18
- else
19
- request_object.form_data = data
20
- end
21
- request(uri, request_object, headers, options, &block)
22
- end
23
-
24
- module_function :put
25
- end