http.rb 0.16.1 → 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 +4 -4
- data/{CHANGELOG.txt → CHANGELOG} +45 -0
- data/Gemfile +3 -5
- data/LICENSE +21 -0
- data/README.md +51 -39
- data/Rakefile +9 -0
- data/http.rb.gemspec +31 -14
- data/lib/HTTP/VERSION.rb +1 -1
- data/lib/HTTP/{get.rb → request.rb} +5 -13
- data/lib/HTTP/verbs.rb +49 -0
- data/lib/Hash/x_www_form_urlencode.rb +1 -11
- data/lib/Net/HTTP/Report.rb +14 -0
- 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/String/to_const.rb +7 -0
- data/lib/Thoran/Array/AllButFirst/all_but_first.rb +28 -0
- data/lib/Thoran/Array/FirstX/firstX.rb +32 -0
- data/lib/Thoran/String/ToConst/to_const.rb +47 -0
- data/lib/URI/Generic/use_sslQ.rb +1 -7
- data/lib/{HTTP.rb → http.rb} +1 -4
- data/spec/HTTP/delete_spec.rb +1 -1
- data/spec/HTTP/get_spec.rb +1 -1
- data/spec/HTTP/head_spec.rb +118 -0
- data/spec/HTTP/post_spec.rb +1 -1
- data/spec/HTTP/propfind_spec.rb +122 -0
- data/spec/HTTP/put_spec.rb +1 -1
- data/spec/Net/HTTP/Report_spec.rb +22 -0
- metadata +78 -16
- data/lib/HTTP/delete.rb +0 -55
- data/lib/HTTP/post.rb +0 -65
- data/lib/HTTP/put.rb +0 -65
- 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
data/spec/HTTP/delete_spec.rb
CHANGED
data/spec/HTTP/get_spec.rb
CHANGED
|
@@ -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
|
data/spec/HTTP/post_spec.rb
CHANGED
|
@@ -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
|
data/spec/HTTP/put_spec.rb
CHANGED
|
@@ -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.
|
|
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:
|
|
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,32 +73,38 @@ executables: []
|
|
|
17
73
|
extensions: []
|
|
18
74
|
extra_rdoc_files: []
|
|
19
75
|
files:
|
|
20
|
-
- CHANGELOG
|
|
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/
|
|
27
|
-
- lib/HTTP/
|
|
28
|
-
- lib/HTTP/post.rb
|
|
29
|
-
- lib/HTTP/put.rb
|
|
83
|
+
- lib/HTTP/request.rb
|
|
84
|
+
- lib/HTTP/verbs.rb
|
|
30
85
|
- lib/Hash/x_www_form_urlencode.rb
|
|
31
|
-
- lib/Net/HTTP/
|
|
32
|
-
- lib/Net/HTTP/Get/set_headers.rb
|
|
33
|
-
- lib/Net/HTTP/Post/set_headers.rb
|
|
34
|
-
- lib/Net/HTTP/Put/set_headers.rb
|
|
86
|
+
- lib/Net/HTTP/Report.rb
|
|
35
87
|
- lib/Net/HTTP/set_options.rb
|
|
88
|
+
- lib/Net/HTTPRequest/set_headers.rb
|
|
36
89
|
- lib/Net/HTTPResponse/StatusPredicates.rb
|
|
90
|
+
- lib/String/to_const.rb
|
|
37
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
|
|
38
95
|
- lib/URI/Generic/use_sslQ.rb
|
|
96
|
+
- lib/http.rb
|
|
39
97
|
- spec/HTTP/delete_spec.rb
|
|
40
98
|
- spec/HTTP/get_spec.rb
|
|
99
|
+
- spec/HTTP/head_spec.rb
|
|
41
100
|
- spec/HTTP/post_spec.rb
|
|
101
|
+
- spec/HTTP/propfind_spec.rb
|
|
42
102
|
- spec/HTTP/put_spec.rb
|
|
103
|
+
- spec/Net/HTTP/Report_spec.rb
|
|
43
104
|
- spec/spec_helper.rb
|
|
44
105
|
homepage: http://github.com/thoran/HTTP
|
|
45
|
-
licenses:
|
|
106
|
+
licenses:
|
|
107
|
+
- MIT
|
|
46
108
|
metadata: {}
|
|
47
109
|
rdoc_options: []
|
|
48
110
|
require_paths:
|
|
@@ -51,14 +113,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
51
113
|
requirements:
|
|
52
114
|
- - ">="
|
|
53
115
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
116
|
+
version: '2.7'
|
|
55
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
118
|
requirements:
|
|
57
119
|
- - ">="
|
|
58
120
|
- !ruby/object:Gem::Version
|
|
59
121
|
version: '0'
|
|
60
122
|
requirements: []
|
|
61
|
-
rubygems_version:
|
|
123
|
+
rubygems_version: 4.0.11
|
|
62
124
|
specification_version: 4
|
|
63
125
|
summary: HTTP made easy.
|
|
64
126
|
test_files: []
|
data/lib/HTTP/delete.rb
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# HTTP/delete.rb
|
|
2
|
-
# HTTP.delete
|
|
3
|
-
|
|
4
|
-
require 'net/http'
|
|
5
|
-
require 'openssl'
|
|
6
|
-
require 'uri'
|
|
7
|
-
|
|
8
|
-
require_relative '../Hash/x_www_form_urlencode'
|
|
9
|
-
require_relative '../HTTP/get'
|
|
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'
|
|
14
|
-
|
|
15
|
-
module HTTP
|
|
16
|
-
|
|
17
|
-
def delete(uri, args = {}, headers = {}, options = {}, &block)
|
|
18
|
-
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
|
-
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
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
module_function :delete
|
|
54
|
-
|
|
55
|
-
end
|
data/lib/HTTP/post.rb
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# HTTP/post.rb
|
|
2
|
-
# HTTP.post
|
|
3
|
-
|
|
4
|
-
require 'json'
|
|
5
|
-
require 'net/http'
|
|
6
|
-
require 'openssl'
|
|
7
|
-
require 'uri'
|
|
8
|
-
|
|
9
|
-
require_relative '../HTTP/get'
|
|
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'
|
|
14
|
-
|
|
15
|
-
module HTTP
|
|
16
|
-
|
|
17
|
-
def post(uri, data = {}, headers = {}, options = {}, &block)
|
|
18
|
-
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
|
-
request_object = Net::HTTP::Post.new(uri.request_uri)
|
|
25
|
-
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.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
|
|
32
|
-
else
|
|
33
|
-
if data.is_a?(String)
|
|
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
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
module_function :post
|
|
64
|
-
|
|
65
|
-
end
|
data/lib/HTTP/put.rb
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
# HTTP/put.rb
|
|
2
|
-
# HTTP.put
|
|
3
|
-
|
|
4
|
-
require 'json'
|
|
5
|
-
require 'net/http'
|
|
6
|
-
require 'openssl'
|
|
7
|
-
require 'uri'
|
|
8
|
-
|
|
9
|
-
require_relative '../HTTP/get'
|
|
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'
|
|
14
|
-
|
|
15
|
-
module HTTP
|
|
16
|
-
|
|
17
|
-
def put(uri, data = {}, headers = {}, options = {}, &block)
|
|
18
|
-
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
|
-
request_object = Net::HTTP::Put.new(uri.request_uri)
|
|
25
|
-
content_type = headers.find{|k, v| k.downcase == 'content-type'}&.last.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
|
|
32
|
-
else
|
|
33
|
-
if data.is_a?(String)
|
|
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
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
module_function :put
|
|
64
|
-
|
|
65
|
-
end
|
|
@@ -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
|