http2 0.0.31 → 0.0.35

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.
@@ -1,17 +1,93 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Http2::Response do
4
- it "should register content type" do
4
+ it "#content_type" do
5
5
  with_http do |http|
6
6
  res = http.get("content_type_test.rhtml")
7
- res.content_type.should eq "text/html"
7
+ expect(res.content_type).to eq "text/html"
8
8
  end
9
9
  end
10
10
 
11
- it "should register content length" do
11
+ it "#content_length" do
12
12
  with_http do |http|
13
13
  res = http.get("content_type_test.rhtml")
14
- res.content_length.should > 50
14
+ expect(res.content_length).to be > 50
15
+ end
16
+ end
17
+
18
+ describe "#json?" do
19
+ it "returns true for 'application/json'" do
20
+ with_http do |http|
21
+ res = http.get("json_test.rhtml")
22
+
23
+ expect(res).to receive(:content_type).and_return("application/json")
24
+ expect(res.json?).to eq true
25
+ end
26
+ end
27
+
28
+ it "returns true for 'application/json'" do
29
+ with_http do |http|
30
+ res = http.get("json_test.rhtml")
31
+ expect(res.json?).to eq true
32
+ end
33
+ end
34
+
35
+ it "returns true for 'application/json'" do
36
+ with_http do |http|
37
+ res = http.post(url: "json_test.rhtml", post: {test: "test2"})
38
+
39
+ expect(res).to receive(:content_type).and_return("application/json; charset=utf-8")
40
+ expect(res.json?).to eq true
41
+ end
42
+ end
43
+ end
44
+
45
+ it "#host" do
46
+ with_http do |http|
47
+ res = http.get("json_test.rhtml")
48
+ expect(res.host).to eq "localhost"
49
+ end
50
+ end
51
+
52
+ it "#port" do
53
+ with_http do |http|
54
+ res = http.get("json_test.rhtml")
55
+ expect(res.port).to eq http.port
56
+ end
57
+ end
58
+
59
+ it "#ssl?" do
60
+ with_http do |http|
61
+ res = http.get("json_test.rhtml")
62
+ expect(res.ssl?).to eq false
63
+ end
64
+ end
65
+
66
+ it "#path" do
67
+ with_http do |http|
68
+ res = http.get("json_test.rhtml")
69
+ expect(res.path).to eq "json_test.rhtml"
70
+ end
71
+ end
72
+
73
+ it "#header" do
74
+ with_http do |http|
75
+ res = http.get("json_test.rhtml")
76
+ expect(res.header("connection")).to eq "Keep-Alive"
77
+ end
78
+ end
79
+
80
+ it "#header?" do
81
+ with_http do |http|
82
+ res = http.get("json_test.rhtml")
83
+ expect(res.header?("connection")).to eq true
84
+ end
85
+ end
86
+
87
+ it "#json" do
88
+ with_http do |http|
89
+ res = http.post(url: "json_test.rhtml", post: {test: "test2"})
90
+ expect(res.json["_POST"]).to eq("test" => "test2")
15
91
  end
16
92
  end
17
93
  end
@@ -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.should eq "https://www.github.com:443/index.php?test=true&test2=false"
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
- resp = http.get("multipart_test.rhtml")
10
-
11
- resp = http.post(url: "multipart_test.rhtml?choice=post-test", post: {
12
- "val1" => "test1",
13
- "val2" => "test2",
14
- "val3" => [
15
- "test3"
16
- ],
17
- "val4" => {
18
- "val5" => "test5"
19
- },
20
- "val6" => {
21
- "val7" => [
22
- {
23
- "val8" => "test8"
24
- }
25
- ]
26
- },
27
- "val9" => ["a", "b", "d"]
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" => %w[a b d]
30
+ }
31
+ )
29
32
  res = JSON.parse(resp.body)
30
33
 
31
- res.is_a?(Hash).should eq true
32
- res["val1"].should eq "test1"
33
- res["val2"].should eq "test2"
34
- res["val3"]["0"].should eq "test3"
35
- res["val4"]["val5"].should eq "test5"
36
- res["val6"]["val7"]["0"]["val8"].should eq "test8"
37
- res["val9"]["0"].should eq "a"
38
- res["val9"]["1"].should eq "b"
39
- res["val9"]["2"].should eq "d"
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.should eq resp2.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(url: "multipart_test.rhtml", post: {
61
- "test_var" => "true",
62
- "test_file1" => {
63
- fpath: fpath,
64
- filename: "specfile"
65
- },
66
- "test_file2" => {
67
- fpath: fpath2,
68
- filename: "http2.rb"
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"].should eq "true"
75
- data["files_data"]["test_file1"].should eq File.read(fpath)
76
- data["files_data"]["test_file2"].should eq File.read(fpath2)
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,18 @@ describe "Http2" do
85
91
  ]
86
92
 
87
93
  with_http do |http|
88
- 0.upto(105) do |count|
94
+ 0.upto(105) do |_count|
89
95
  url = urls[rand(urls.size)]
90
- #print "Doing request #{count} of 200 (#{url}).\n"
96
+ # puts "Doing request #{count} of 200 (#{url})."
91
97
  res = http.get(url)
92
- res.body.to_s.length.should > 0
98
+ expect(res.body.to_s.length).to be > 0
93
99
  end
94
100
  end
95
101
  end
96
102
 
97
- it "should be able to convert URL's to 'is.gd'-short-urls" do
98
- isgd = Http2.isgdlink("https://github.com/kaspernj/http2")
99
- raise "Expected isgd-var to be valid but it wasnt: '#{isgd}'." if !isgd.match(/^http:\/\/is\.gd\/([A-z\d]+)$/)
100
- end
101
-
102
103
  it "should raise exception when something is not found" do
103
104
  with_http do |http|
104
- expect{
105
- http.get("something_that_does_not_exist.rhtml")
106
- }.to raise_error(::Http2::Errors::Notfound)
105
+ expect { http.get("something_that_does_not_exist.rhtml") }.to raise_error(::Http2::Errors::Notfound)
107
106
  end
108
107
  end
109
108
 
@@ -115,15 +114,15 @@ describe "Http2" do
115
114
  )
116
115
 
117
116
  data = JSON.parse(res.body)
118
- data["_SERVER"]["HTTP_CONTENT_TYPE"].should eq "application/json"
117
+ expect(data["_SERVER"]["HTTP_CONTENT_TYPE"]).to eq "application/json"
119
118
 
120
119
  # Hack JSON data from Hayabusa.
121
120
  json_data = JSON.parse(data["_POST"].keys.first)
122
- json_data["testkey"].should eq "testvalue"
121
+ expect(json_data["testkey"]).to eq "testvalue"
123
122
 
124
- res.content_type.should eq "application/json"
125
- res.json?.should eq true
126
- res.json["_SERVER"]["REQUEST_METHOD"].should eq "POST"
123
+ expect(res.content_type).to eq "application/json"
124
+ expect(res.json?).to eq true
125
+ expect(res.json["_SERVER"]["REQUEST_METHOD"]).to eq "POST"
127
126
  end
128
127
  end
129
128
 
@@ -136,25 +135,41 @@ describe "Http2" do
136
135
  )
137
136
 
138
137
  data = JSON.parse(res.body)
139
- data["_SERVER"]["HTTP_CONTENT_TYPE"].should eq "plain/text"
138
+ expect(data["_SERVER"]["HTTP_CONTENT_TYPE"]).to eq "plain/text"
140
139
 
141
140
  raw_data = data["_POST"].keys.first
142
- raw_data.should eq "test1_test2_test3"
141
+ expect(raw_data).to eq "test1_test2_test3"
143
142
  end
144
143
  end
145
144
 
146
145
  it "should set various timeouts" do
147
146
  with_http do |http|
148
- res = http.get("content_type_test.rhtml")
149
- http.keepalive_timeout.should eq 15
150
- http.keepalive_max.should eq 30
147
+ http.get("content_type_test.rhtml")
148
+ expect(http.keepalive_timeout).to eq 15
149
+ expect(http.keepalive_max).to eq 30
151
150
  end
152
151
  end
153
152
 
154
153
  it "should follow redirects" do
155
154
  with_http(follow_redirects: true) do |http|
156
155
  resp = http.get("redirect_test.rhtml")
157
- resp.code.should eq "200"
156
+ expect(resp.code).to eq "200"
157
+ end
158
+ end
159
+
160
+ it "throws errors on unauhtorized" do
161
+ with_http do |http|
162
+ expect do
163
+ http.get("unauthorized.rhtml")
164
+ end.to raise_error(Http2::Errors::Unauthorized)
165
+ end
166
+ end
167
+
168
+ it "throws errors on unsupported media type" do
169
+ with_http do |http|
170
+ expect do
171
+ http.get("unsupported_media_type.rhtml")
172
+ end.to raise_error(Http2::Errors::UnsupportedMediaType)
158
173
  end
159
174
  end
160
175
  end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,17 @@
1
- require "codeclimate-test-reporter"
2
- CodeClimate::TestReporter.start
3
-
4
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
5
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
6
- require 'rspec'
7
- require 'http2'
8
- require 'helpers'
3
+ require "rspec"
4
+ require "http2"
5
+ require "helpers"
6
+ require "json"
9
7
 
10
8
  # Requires supporting files with custom matchers and macros, etc,
11
9
  # in ./support/ and its subdirectories.
12
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
13
11
 
14
12
  RSpec.configure do |config|
15
13
  config.expect_with :rspec do |c|
16
- c.syntax = [:expect, :should]
14
+ c.syntax = [:expect]
17
15
  end
18
16
 
19
17
  config.include Helpers
@@ -1,3 +1,3 @@
1
1
  <%
2
- Knj::Web.redirect("/content_type_test.rhtml")
2
+ Knj::Web.redirect(_get["redirect_to"] || "/content_type_test.rhtml")
3
3
  %>
@@ -0,0 +1,3 @@
1
+ <%
2
+ _httpsession.resp.status = 401
3
+ %>
@@ -0,0 +1,3 @@
1
+ <%
2
+ _httpsession.resp.status = 415
3
+ %>
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.31
4
+ version: 0.0.35
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-05-13 00:00:00.000000000 Z
11
+ date: 2021-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-cases
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: best_practice_project
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,63 +39,91 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2.8.0
47
+ version: 1.0.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: 2.8.0
54
+ version: 1.0.0
55
55
  - !ruby/object:Gem::Dependency
56
- name: rdoc
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hayabusa
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.12'
75
+ version: 0.0.28
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '3.12'
82
+ version: 0.0.28
69
83
  - !ruby/object:Gem::Dependency
70
- name: bundler
84
+ name: rake
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: 1.0.0
89
+ version: '0'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: 1.0.0
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
- name: hayabusa
98
+ name: rdoc
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
- version: 0.0.25
117
+ version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - "~>"
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
- version: 0.0.25
124
+ version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: sqlite3
126
+ name: rubocop
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -109,7 +137,7 @@ dependencies:
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
- name: codeclimate-test-reporter
140
+ name: sqlite3
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
143
  - - ">="
@@ -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
@@ -158,6 +191,8 @@ files:
158
191
  - spec/spec_root/json_test.rhtml
159
192
  - spec/spec_root/multipart_test.rhtml
160
193
  - spec/spec_root/redirect_test.rhtml
194
+ - spec/spec_root/unauthorized.rhtml
195
+ - spec/spec_root/unsupported_media_type.rhtml
161
196
  homepage: http://github.com/kaspernj/http2
162
197
  licenses:
163
198
  - MIT
@@ -177,22 +212,27 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
212
  - !ruby/object:Gem::Version
178
213
  version: '0'
179
214
  requirements: []
180
- rubyforge_project:
181
- rubygems_version: 2.2.2
215
+ rubygems_version: 3.1.6
182
216
  signing_key:
183
217
  specification_version: 4
184
218
  summary: A lightweight framework for doing http-connections in Ruby. Supports cookies,
185
219
  keep-alive, compressing and much more.
186
220
  test_files:
187
221
  - spec/helpers.rb
188
- - spec/http2/cookies_spec.rb
189
- - spec/http2/post_data_generator_spec.rb
190
- - spec/http2/response_spec.rb
191
- - spec/http2/url_builder_spec.rb
192
222
  - spec/http2_spec.rb
193
- - spec/spec_helper.rb
194
- - spec/spec_root/content_type_test.rhtml
195
- - spec/spec_root/cookie_test.rhtml
223
+ - spec/spec_root/unauthorized.rhtml
196
224
  - spec/spec_root/json_test.rhtml
197
- - spec/spec_root/multipart_test.rhtml
225
+ - spec/spec_root/content_type_test.rhtml
198
226
  - spec/spec_root/redirect_test.rhtml
227
+ - spec/spec_root/multipart_test.rhtml
228
+ - spec/spec_root/cookie_test.rhtml
229
+ - spec/spec_root/unsupported_media_type.rhtml
230
+ - spec/spec_helper.rb
231
+ - spec/http2/cookies_spec.rb
232
+ - spec/http2/get_request_spec.rb
233
+ - spec/http2/url_builder_spec.rb
234
+ - spec/http2/post_multipart_request_spec.rb
235
+ - spec/http2/post_data_generator_spec.rb
236
+ - spec/http2/post_request_spec.rb
237
+ - spec/http2/response_reader_spec.rb
238
+ - spec/http2/response_spec.rb
data/include/errors.rb DELETED
@@ -1,11 +0,0 @@
1
- #This class holds various classes for error-handeling.
2
- class Http2::Errors
3
- class Http2error < RuntimeError
4
- attr_accessor :response
5
- end
6
-
7
- class Noaccess < Http2error; end
8
- class Internalserver < Http2error; end
9
- class Notfound < Http2error; end
10
- class Badrequest < Http2error; end
11
- end
@@ -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