http.rb 0.17.0 → 0.18.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: 2d9519c8ef1eb2d71220644e255d595a472ecc23248eed892a7a0bb3eee8f5e3
4
- data.tar.gz: dc4da67e9c806dd30f4b0c9cc989a6d42116f4147c0bcaef7dd7eee2430f9f4a
3
+ metadata.gz: 3cf46d2fcd2e4e18c1bd5fb1245da1156b14d694871970fb6d827d5a79f2a533
4
+ data.tar.gz: 786e1c2b4fc5314e2626f466bfd249d7a24ea80b607ed0f3c67333c6220147e2
5
5
  SHA512:
6
- metadata.gz: 156c9ea7fe6f112d1987edce3557c60166c3f23c15b8fbb6c58cc8a6603bd1f2146eb073fc013778c5e40f4038c52c115a9ae6cf0d100b50e15615e19aa640a0
7
- data.tar.gz: 9e67a7ca0e436c137591757b8ca1d61497b2b6a3649f5d7c5c9fb2266abf936b16c7949538d71dc71fd9cb7a96f792af216d5d9b40d3146f6577f1fcc2d1df3e
6
+ metadata.gz: 86963812021231537e441627cbe6e617920409c465010296e4f513f838c40df51005edfc25083ad03348566de02c94a80ae9a3ccfa26c956abe00274425857aa
7
+ data.tar.gz: d5b6e217124fffa5ee8a23e78c316e9d8bbce7cfe8523613923ac18b34bfa74e003a21294b793ddca56785261ea8f765e158adae3b83663d732aa19c12c38fcc
@@ -1,3 +1,43 @@
1
+ # CHANGELOG
2
+
3
+ # 20260508
4
+ # 0.18.1: Remove incorrectly added WebDAV verbs.
5
+ 1. - lib/Net/HTTP/Report.rb
6
+ 2. ~ HTTP::VERBS: - require_relative '../Net/HTTP/Report'
7
+ 3. ~ HTTP::VERBS::WITH_BODY: - propfind, proppatch, mkcol, copy, move, lock, unlock, report
8
+ 4. - spec/HTTP/propfind_spec.rb
9
+ 5. - spec/Net/HTTP/Report_spec.rb
10
+ 6. ~ HTTP::VERSION: /0.18.0/0.18.1/
11
+ 7. ~ CHANGELOG: + 0.18.1 entry
12
+
13
+ # 20260507
14
+ # 0.18.0: Add all missing HTTP verbs; use meta-programming to define verb methods.
15
+ 1. + HTTP/verbs.rb; including:
16
+ + HTTP::VERBS::WITHOUT_BODY: get, delete, head, options, trace
17
+ + HTTP::VERBS::WITH_BODY: post, put, patch, propfind, proppatch, mkcol, copy, move, lock, unlock, report
18
+ 2. + lib/Net/HTTP/Report.rb: Add Net::HTTP::Report, which is missing from Ruby's standard library. See RFC 3253.
19
+ 3. - lib/HTTP/delete.rb
20
+ 4. - lib/HTTP/get.rb
21
+ 5. - lib/HTTP/post.rb
22
+ 6. - lib/HTTP/put.rb
23
+ 7. + String/to_const.rb
24
+ 8. + Thoran/Array/AllButFirst/all_but_first.rb
25
+ 9. + Thoran/Array/FirstX/firstX.rb
26
+ 10. + Thoran/String/ToConst/to_const.rb
27
+ 11. + LICENSE
28
+ 12. + Rakefile
29
+ 13. + spec/HTTP/head_spec.rb
30
+ 14. + spec/HTTP/propfind_spec.rb
31
+ 15. + spec/Net/HTTP/Report_spec.rb
32
+ 16. ~ HTTP::VERSION: /0.17.0/0.18.0/
33
+ 17. /CHANGELOG.txt/CHANGELOG/
34
+ 18. /TODO.txt/TODO/
35
+ 19. ~ CHANGELOG: + 0.18.0 entry
36
+ 20. ~ http.rb.gemspec: /s/spec/; - date; + Rakefile; + development_dependencies
37
+ 21. ~ Gemfile: /group :test/gemspec/
38
+ 22. ~ .gitignore: Using a common one with lots of entries.
39
+ 23. ~ README.md: /http.rb/http/; Trimmed the Description; Usage has more code blocks, making the comments Markdown sub-sections.
40
+
1
41
  # 20260325
2
42
  # 0.17.0: Extract HTTP.request method; consolidate set_headers.
3
43
  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,92 @@
1
- # http.rb
1
+ # http
2
2
 
3
- ## Description
3
+ 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.
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
+ 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.
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.
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.
7
+ 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
8
 
17
9
 
18
10
  ## Installation
19
11
 
20
12
  Add this line to your application's Gemfile:
21
13
 
22
- gem 'http.rb'
23
-
14
+ ```ruby
15
+ gem 'http.rb'
16
+ ```
24
17
 
25
18
  And then execute:
26
19
 
27
- $ bundle
28
-
29
-
30
- Or install it yourself as:
20
+ ```shell
21
+ $ bundle
22
+ ```
31
23
 
32
- $ gem install http.rb
24
+ Or install it directly:
33
25
 
26
+ ```shell
27
+ $ gem install http.rb
28
+ ```
34
29
 
35
30
  ## Usage
36
31
 
37
- ```Ruby
38
- # With just a URI
32
+ ### With just a URI
39
33
 
34
+ ```ruby
40
35
  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.
36
+ ```
42
37
 
43
- # With arguments only
38
+ ### With arguments only
44
39
 
40
+ ```ruby
45
41
  HTTP.get('http://example.com', {a: 1, b: 2})
46
42
  HTTP.post('http://example.com', {a: 1, b: 2})
43
+ ```
44
+ ### With JSON data
47
45
 
48
- # With JSON data
49
-
46
+ ```ruby
50
47
  HTTP.post('http://example.com', {a: 1, b: 2}, {'Content-type' => 'application/json'})
48
+ ```
51
49
 
52
- # With custom headers only
50
+ ### With custom headers only
53
51
 
52
+ ```ruby
54
53
  HTTP.get('http://example.com', {}, {'User-Agent'=>'Custom'})
55
54
  HTTP.post('http://example.com', {}, {'User-Agent'=>'Custom'})
55
+ ```
56
56
 
57
- # With options only
57
+ ### With options only
58
58
 
59
+ ```ruby
59
60
  HTTP.get('http://example.com', {}, {}, {use_ssl: true})
60
61
  HTTP.post('http://example.com', {}, {}, {use_ssl: true})
62
+ ```
61
63
 
62
- # With a block
64
+ ### With a block
63
65
 
66
+ ```ruby
64
67
  HTTP.get('http://example.com') do |response|
65
68
  # Do stuff with a subclass of Net::HTTPResponse here...
66
69
  end
67
- HTTP.post('http://example.com') do |response|
68
- # Do stuff with a subclass of Net::HTTPResponse here...
69
- end
70
+ ```
70
71
 
71
- # With the lot
72
+ ### With the lot
72
73
 
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
74
+ ```ruby
76
75
  HTTP.post('http://example.com', {a: 1, b: 2}, {'User-Agent'=>'Custom'}, {use_ssl: true}) do |response|
77
76
  # Do stuff with a subclass of Net::HTTPResponse here...
78
77
  end
78
+ ```
79
79
 
80
- # Preventing redirections
80
+ ### Preventing redirections
81
81
 
82
+ ```ruby
82
83
  HTTP.get('http://example.com', {}, {}, {no_redirect: true})
83
84
  # => #<Net::HTTPResponse @code=3xx>
85
+ ```
84
86
 
85
- # Response status predicate methods
87
+ ### Response status predicate methods
86
88
 
89
+ ```ruby
87
90
  # 1xx
88
91
  response = HTTP.get('http://example.com')
89
92
  response.informational?
@@ -126,23 +129,26 @@ response.server_error?
126
129
  # => true
127
130
  response.error?
128
131
  # => true
132
+ ```
129
133
 
130
- # Including it in a class
134
+ ### Including it in a class
131
135
 
136
+ ```ruby
132
137
  class A
133
138
  include HTTP
134
139
  def a
135
140
  get('http://example.com')
136
141
  end
137
142
  end
143
+ ```
138
144
 
139
- # Extending a class
145
+ ### Extending a class
140
146
 
147
+ ```ruby
141
148
  class A
142
149
  extend HTTP
143
150
  get('http://example.com')
144
151
  end
145
-
146
152
  ```
147
153
 
148
154
  ## Allowed values for the options hash
@@ -239,8 +245,12 @@ verify_mode
239
245
 
240
246
  ## Contributing
241
247
 
242
- 1. Fork it ( https://github.com/thoran/HTTP/fork )
248
+ 1. Fork it [https://github.com/thoran/http/fork](https://github.com/thoran/http/fork)
243
249
  2. Create your feature branch (`git checkout -b my-new-feature`)
244
250
  3. Commit your changes (`git commit -am 'Add some feature'`)
245
251
  4. Push to the branch (`git push origin my-new-feature`)
246
252
  5. Create a new pull request
253
+
254
+ ## Licence
255
+
256
+ 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.1'
6
6
  end
data/lib/HTTP/verbs.rb ADDED
@@ -0,0 +1,48 @@
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 './request'
9
+ require_relative '../String/to_const'
10
+
11
+ module HTTP
12
+ module VERBS
13
+ WITHOUT_BODY = %i{get delete head options trace}
14
+ WITH_BODY = %i{post put patch}
15
+ end
16
+
17
+ VERBS::WITHOUT_BODY.each do |verb|
18
+ define_method(verb) do |uri, args = {}, headers = {}, options = {}, &block|
19
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
20
+ request_uri = uri.request_uri
21
+ unless args.empty?
22
+ request_uri += '?' + args.x_www_form_urlencode
23
+ end
24
+ request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(request_uri)
25
+ request(uri, request_object, headers, options, &block)
26
+ end
27
+
28
+ module_function verb
29
+ end
30
+
31
+ VERBS::WITH_BODY.each do |verb|
32
+ define_method(verb) do |uri, data = {}, headers = {}, options = {}, &block|
33
+ uri = uri.is_a?(URI) ? uri : URI.parse(uri)
34
+ request_object = "Net::HTTP::#{verb.to_s.capitalize}".to_const.new(uri.request_uri)
35
+ content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.to_s
36
+ if data.is_a?(String)
37
+ request_object.body = data
38
+ elsif content_type.start_with?('application/json')
39
+ request_object.body = JSON.dump(data)
40
+ else
41
+ request_object.form_data = data
42
+ end
43
+ request(uri, request_object, headers, options, &block)
44
+ end
45
+
46
+ module_function verb
47
+ end
48
+ 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
@@ -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
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.1
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,35 @@ 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
32
86
  - lib/Net/HTTP/set_options.rb
33
87
  - lib/Net/HTTPRequest/set_headers.rb
34
88
  - lib/Net/HTTPResponse/StatusPredicates.rb
89
+ - lib/String/to_const.rb
35
90
  - lib/String/url_encode.rb
91
+ - lib/Thoran/Array/AllButFirst/all_but_first.rb
92
+ - lib/Thoran/Array/FirstX/firstX.rb
93
+ - lib/Thoran/String/ToConst/to_const.rb
36
94
  - lib/URI/Generic/use_sslQ.rb
95
+ - lib/http.rb
37
96
  - spec/HTTP/delete_spec.rb
38
97
  - spec/HTTP/get_spec.rb
98
+ - spec/HTTP/head_spec.rb
39
99
  - spec/HTTP/post_spec.rb
40
100
  - spec/HTTP/put_spec.rb
41
101
  - spec/spec_helper.rb
42
102
  homepage: http://github.com/thoran/HTTP
43
- licenses: []
103
+ licenses:
104
+ - MIT
44
105
  metadata: {}
45
106
  rdoc_options: []
46
107
  require_paths:
@@ -49,14 +110,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
110
  requirements:
50
111
  - - ">="
51
112
  - !ruby/object:Gem::Version
52
- version: '0'
113
+ version: '2.7'
53
114
  required_rubygems_version: !ruby/object:Gem::Requirement
54
115
  requirements:
55
116
  - - ">="
56
117
  - !ruby/object:Gem::Version
57
118
  version: '0'
58
119
  requirements: []
59
- rubygems_version: 4.0.8
120
+ rubygems_version: 4.0.11
60
121
  specification_version: 4
61
122
  summary: HTTP made easy.
62
123
  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