http2 0.0.31 → 0.0.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -1
- data/Rakefile +16 -13
- data/lib/http2.rb +25 -22
- data/lib/http2/base_request.rb +22 -0
- data/{include → lib/http2}/connection.rb +10 -9
- data/{include → lib/http2}/cookie.rb +4 -1
- data/{include → lib/http2}/errors.rb +1 -1
- data/lib/http2/get_request.rb +33 -0
- data/{include → lib/http2}/post_data_generator.rb +5 -4
- data/{include → lib/http2}/post_multipart_request.rb +19 -15
- data/{include → lib/http2}/post_request.rb +13 -25
- data/{include → lib/http2}/response.rb +40 -15
- data/{include → lib/http2}/response_reader.rb +21 -13
- data/{include → lib/http2}/url_builder.rb +4 -4
- data/{include → lib/http2}/utils.rb +9 -9
- data/spec/http2/cookies_spec.rb +6 -6
- data/spec/http2/get_request_spec.rb +11 -0
- data/spec/http2/post_multipart_request_spec.rb +11 -0
- data/spec/http2/post_request_spec.rb +11 -0
- data/spec/http2/response_reader_spec.rb +12 -0
- data/spec/http2/response_spec.rb +60 -4
- data/spec/http2/url_builder_spec.rb +1 -1
- data/spec/http2_spec.rb +66 -62
- data/spec/spec_helper.rb +6 -6
- data/spec/spec_root/redirect_test.rhtml +1 -1
- metadata +61 -24
- data/include/get_request.rb +0 -34
@@ -11,7 +11,7 @@ describe Http2::UrlBuilder do
|
|
11
11
|
ub.params["test"] = "true"
|
12
12
|
ub.params["test2"] = "false"
|
13
13
|
|
14
|
-
ub.build.
|
14
|
+
expect(ub.build).to eq "https://www.github.com:443/index.php?test=true&test2=false"
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/spec/http2_spec.rb
CHANGED
@@ -3,40 +3,43 @@ require "json"
|
|
3
3
|
|
4
4
|
describe "Http2" do
|
5
5
|
it "should be able to do normal post-requests." do
|
6
|
-
#Test posting keep-alive and advanced post-data.
|
6
|
+
# Test posting keep-alive and advanced post-data.
|
7
7
|
with_http do |http|
|
8
8
|
0.upto(5) do
|
9
|
-
|
10
|
-
|
11
|
-
resp = http.post(
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
9
|
+
http.get("multipart_test.rhtml")
|
10
|
+
|
11
|
+
resp = http.post(
|
12
|
+
url: "multipart_test.rhtml?choice=post-test",
|
13
|
+
post: {
|
14
|
+
"val1" => "test1",
|
15
|
+
"val2" => "test2",
|
16
|
+
"val3" => [
|
17
|
+
"test3"
|
18
|
+
],
|
19
|
+
"val4" => {
|
20
|
+
"val5" => "test5"
|
21
|
+
},
|
22
|
+
"val6" => {
|
23
|
+
"val7" => [
|
24
|
+
{
|
25
|
+
"val8" => "test8"
|
26
|
+
}
|
27
|
+
]
|
28
|
+
},
|
29
|
+
"val9" => ["a", "b", "d"]
|
30
|
+
}
|
31
|
+
)
|
29
32
|
res = JSON.parse(resp.body)
|
30
33
|
|
31
|
-
res.is_a?(Hash).
|
32
|
-
res["val1"].
|
33
|
-
res["val2"].
|
34
|
-
res["val3"]["0"].
|
35
|
-
res["val4"]["val5"].
|
36
|
-
res["val6"]["val7"]["0"]["val8"].
|
37
|
-
res["val9"]["0"].
|
38
|
-
res["val9"]["1"].
|
39
|
-
res["val9"]["2"].
|
34
|
+
expect(res.is_a?(Hash)).to eq true
|
35
|
+
expect(res["val1"]).to eq "test1"
|
36
|
+
expect(res["val2"]).to eq "test2"
|
37
|
+
expect(res["val3"]["0"]).to eq "test3"
|
38
|
+
expect(res["val4"]["val5"]).to eq "test5"
|
39
|
+
expect(res["val6"]["val7"]["0"]["val8"]).to eq "test8"
|
40
|
+
expect(res["val9"]["0"]).to eq "a"
|
41
|
+
expect(res["val9"]["1"]).to eq "b"
|
42
|
+
expect(res["val9"]["2"]).to eq "d"
|
40
43
|
end
|
41
44
|
end
|
42
45
|
end
|
@@ -47,7 +50,7 @@ describe "Http2" do
|
|
47
50
|
http.reconnect
|
48
51
|
resp2 = http.get("multipart_test.rhtml")
|
49
52
|
|
50
|
-
resp1.body.
|
53
|
+
expect(resp1.body).to eq resp2.body
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
@@ -57,23 +60,26 @@ describe "Http2" do
|
|
57
60
|
fpath = File.realpath(__FILE__)
|
58
61
|
fpath2 = "#{File.realpath(File.dirname(__FILE__))}/../lib/http2.rb"
|
59
62
|
|
60
|
-
resp = http.post_multipart(
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
63
|
+
resp = http.post_multipart(
|
64
|
+
url: "multipart_test.rhtml",
|
65
|
+
post: {
|
66
|
+
"test_var" => "true",
|
67
|
+
"test_file1" => {
|
68
|
+
fpath: fpath,
|
69
|
+
filename: "specfile"
|
70
|
+
},
|
71
|
+
"test_file2" => {
|
72
|
+
fpath: fpath2,
|
73
|
+
filename: "http2.rb"
|
74
|
+
}
|
69
75
|
}
|
70
|
-
|
76
|
+
)
|
71
77
|
|
72
78
|
data = JSON.parse(resp.body)
|
73
79
|
|
74
|
-
data["post"]["test_var"].
|
75
|
-
data["files_data"]["test_file1"].
|
76
|
-
data["files_data"]["test_file2"].
|
80
|
+
expect(data["post"]["test_var"]).to eq "true"
|
81
|
+
expect(data["files_data"]["test_file1"]).to eq File.read(fpath)
|
82
|
+
expect(data["files_data"]["test_file2"]).to eq File.read(fpath2)
|
77
83
|
end
|
78
84
|
end
|
79
85
|
end
|
@@ -85,25 +91,23 @@ describe "Http2" do
|
|
85
91
|
]
|
86
92
|
|
87
93
|
with_http do |http|
|
88
|
-
0.upto(105) do |
|
94
|
+
0.upto(105) do |_count|
|
89
95
|
url = urls[rand(urls.size)]
|
90
|
-
#
|
96
|
+
# puts "Doing request #{count} of 200 (#{url})."
|
91
97
|
res = http.get(url)
|
92
|
-
res.body.to_s.length.
|
98
|
+
expect(res.body.to_s.length).to be > 0
|
93
99
|
end
|
94
100
|
end
|
95
101
|
end
|
96
102
|
|
97
103
|
it "should be able to convert URL's to 'is.gd'-short-urls" do
|
98
104
|
isgd = Http2.isgdlink("https://github.com/kaspernj/http2")
|
99
|
-
raise "Expected isgd-var to be valid but it wasnt: '#{isgd}'."
|
105
|
+
raise "Expected isgd-var to be valid but it wasnt: '#{isgd}'." unless isgd.match(/^http:\/\/is\.gd\/([A-z\d]+)$/)
|
100
106
|
end
|
101
107
|
|
102
108
|
it "should raise exception when something is not found" do
|
103
109
|
with_http do |http|
|
104
|
-
expect{
|
105
|
-
http.get("something_that_does_not_exist.rhtml")
|
106
|
-
}.to raise_error(::Http2::Errors::Notfound)
|
110
|
+
expect { http.get("something_that_does_not_exist.rhtml") }.to raise_error(::Http2::Errors::Notfound)
|
107
111
|
end
|
108
112
|
end
|
109
113
|
|
@@ -115,15 +119,15 @@ describe "Http2" do
|
|
115
119
|
)
|
116
120
|
|
117
121
|
data = JSON.parse(res.body)
|
118
|
-
data["_SERVER"]["HTTP_CONTENT_TYPE"].
|
122
|
+
expect(data["_SERVER"]["HTTP_CONTENT_TYPE"]).to eq "application/json"
|
119
123
|
|
120
124
|
# Hack JSON data from Hayabusa.
|
121
125
|
json_data = JSON.parse(data["_POST"].keys.first)
|
122
|
-
json_data["testkey"].
|
126
|
+
expect(json_data["testkey"]).to eq "testvalue"
|
123
127
|
|
124
|
-
res.content_type.
|
125
|
-
res.json
|
126
|
-
res.json["_SERVER"]["REQUEST_METHOD"].
|
128
|
+
expect(res.content_type).to eq "application/json"
|
129
|
+
expect(res.json?).to eq true
|
130
|
+
expect(res.json["_SERVER"]["REQUEST_METHOD"]).to eq "POST"
|
127
131
|
end
|
128
132
|
end
|
129
133
|
|
@@ -136,25 +140,25 @@ describe "Http2" do
|
|
136
140
|
)
|
137
141
|
|
138
142
|
data = JSON.parse(res.body)
|
139
|
-
data["_SERVER"]["HTTP_CONTENT_TYPE"].
|
143
|
+
expect(data["_SERVER"]["HTTP_CONTENT_TYPE"]).to eq "plain/text"
|
140
144
|
|
141
145
|
raw_data = data["_POST"].keys.first
|
142
|
-
raw_data.
|
146
|
+
expect(raw_data).to eq "test1_test2_test3"
|
143
147
|
end
|
144
148
|
end
|
145
149
|
|
146
150
|
it "should set various timeouts" do
|
147
151
|
with_http do |http|
|
148
|
-
|
149
|
-
http.keepalive_timeout.
|
150
|
-
http.keepalive_max.
|
152
|
+
http.get("content_type_test.rhtml")
|
153
|
+
expect(http.keepalive_timeout).to eq 15
|
154
|
+
expect(http.keepalive_max).to eq 30
|
151
155
|
end
|
152
156
|
end
|
153
157
|
|
154
158
|
it "should follow redirects" do
|
155
159
|
with_http(follow_redirects: true) do |http|
|
156
160
|
resp = http.get("redirect_test.rhtml")
|
157
|
-
resp.code.
|
161
|
+
expect(resp.code).to eq "200"
|
158
162
|
end
|
159
163
|
end
|
160
164
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
require "codeclimate-test-reporter"
|
2
2
|
CodeClimate::TestReporter.start
|
3
3
|
|
4
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
5
5
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
6
|
+
require "rspec"
|
7
|
+
require "http2"
|
8
|
+
require "helpers"
|
9
9
|
|
10
10
|
# Requires supporting files with custom matchers and macros, etc,
|
11
11
|
# in ./support/ and its subdirectories.
|
12
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
12
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
13
13
|
|
14
14
|
RSpec.configure do |config|
|
15
15
|
config.expect_with :rspec do |c|
|
16
|
-
c.syntax = [:expect
|
16
|
+
c.syntax = [:expect]
|
17
17
|
end
|
18
18
|
|
19
19
|
config.include Helpers
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kasper Johansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: string-cases
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.4.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.4.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +122,34 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: best_practice_project
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.0.4
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.0.4
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.35.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.35.0
|
125
153
|
description: A lightweight framework for doing http-connections in Ruby. Supports
|
126
154
|
cookies, keep-alive, compressing and much more.
|
127
155
|
email: k@spernj.org
|
@@ -134,21 +162,26 @@ files:
|
|
134
162
|
- LICENSE.txt
|
135
163
|
- README.md
|
136
164
|
- Rakefile
|
137
|
-
- include/connection.rb
|
138
|
-
- include/cookie.rb
|
139
|
-
- include/errors.rb
|
140
|
-
- include/get_request.rb
|
141
|
-
- include/post_data_generator.rb
|
142
|
-
- include/post_multipart_request.rb
|
143
|
-
- include/post_request.rb
|
144
|
-
- include/response.rb
|
145
|
-
- include/response_reader.rb
|
146
|
-
- include/url_builder.rb
|
147
|
-
- include/utils.rb
|
148
165
|
- lib/http2.rb
|
166
|
+
- lib/http2/base_request.rb
|
167
|
+
- lib/http2/connection.rb
|
168
|
+
- lib/http2/cookie.rb
|
169
|
+
- lib/http2/errors.rb
|
170
|
+
- lib/http2/get_request.rb
|
171
|
+
- lib/http2/post_data_generator.rb
|
172
|
+
- lib/http2/post_multipart_request.rb
|
173
|
+
- lib/http2/post_request.rb
|
174
|
+
- lib/http2/response.rb
|
175
|
+
- lib/http2/response_reader.rb
|
176
|
+
- lib/http2/url_builder.rb
|
177
|
+
- lib/http2/utils.rb
|
149
178
|
- spec/helpers.rb
|
150
179
|
- spec/http2/cookies_spec.rb
|
180
|
+
- spec/http2/get_request_spec.rb
|
151
181
|
- spec/http2/post_data_generator_spec.rb
|
182
|
+
- spec/http2/post_multipart_request_spec.rb
|
183
|
+
- spec/http2/post_request_spec.rb
|
184
|
+
- spec/http2/response_reader_spec.rb
|
152
185
|
- spec/http2/response_spec.rb
|
153
186
|
- spec/http2/url_builder_spec.rb
|
154
187
|
- spec/http2_spec.rb
|
@@ -178,21 +211,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
211
|
version: '0'
|
179
212
|
requirements: []
|
180
213
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
214
|
+
rubygems_version: 2.4.0
|
182
215
|
signing_key:
|
183
216
|
specification_version: 4
|
184
217
|
summary: A lightweight framework for doing http-connections in Ruby. Supports cookies,
|
185
218
|
keep-alive, compressing and much more.
|
186
219
|
test_files:
|
187
|
-
- spec/
|
188
|
-
- spec/http2/
|
220
|
+
- spec/http2_spec.rb
|
221
|
+
- spec/http2/get_request_spec.rb
|
222
|
+
- spec/http2/post_request_spec.rb
|
189
223
|
- spec/http2/post_data_generator_spec.rb
|
190
|
-
- spec/http2/
|
224
|
+
- spec/http2/cookies_spec.rb
|
191
225
|
- spec/http2/url_builder_spec.rb
|
192
|
-
- spec/
|
193
|
-
- spec/
|
194
|
-
- spec/
|
195
|
-
- spec/spec_root/
|
226
|
+
- spec/http2/response_reader_spec.rb
|
227
|
+
- spec/http2/post_multipart_request_spec.rb
|
228
|
+
- spec/http2/response_spec.rb
|
229
|
+
- spec/spec_root/redirect_test.rhtml
|
196
230
|
- spec/spec_root/json_test.rhtml
|
197
231
|
- spec/spec_root/multipart_test.rhtml
|
198
|
-
- spec/spec_root/
|
232
|
+
- spec/spec_root/content_type_test.rhtml
|
233
|
+
- spec/spec_root/cookie_test.rhtml
|
234
|
+
- spec/helpers.rb
|
235
|
+
- spec/spec_helper.rb
|
data/include/get_request.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
class Http2::GetRequest
|
2
|
-
def initialize(http2, args)
|
3
|
-
@http2, @args, @debug, @nl = http2, http2.parse_args(args), http2.debug, http2.nl
|
4
|
-
end
|
5
|
-
|
6
|
-
def execute
|
7
|
-
@http2.mutex.synchronize do
|
8
|
-
puts "Http2: Writing headers: #{header_string}" if @debug
|
9
|
-
@http2.connection.write(header_string)
|
10
|
-
|
11
|
-
puts "Http2: Reading response." if @debug
|
12
|
-
resp = @http2.read_response(@args)
|
13
|
-
|
14
|
-
puts "Http2: Done with get request." if @debug
|
15
|
-
return resp
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def method
|
22
|
-
if @args[:method]
|
23
|
-
@args[:method].to_s.upcase
|
24
|
-
else
|
25
|
-
"GET"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def header_string
|
30
|
-
header_str = "#{method} /#{@args[:url]} HTTP/1.1#{@nl}"
|
31
|
-
header_str << @http2.header_str(@http2.default_headers(@args), @args)
|
32
|
-
header_str << @nl
|
33
|
-
end
|
34
|
-
end
|