http2 0.0.24 → 0.0.25

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.
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ describe Http2::PostDataGenerator do
4
+ it "should be able to recursively parse post-data-hashes." do
5
+ res = Http2::PostDataGenerator.new(
6
+ "test1" => "test2"
7
+ ).generate
8
+ raise "Expected 'test1=test2' but got: '#{res}'." if res != "test1=test2"
9
+
10
+ res = Http2::PostDataGenerator.new(
11
+ "test1" => [1, 2, 3]
12
+ ).generate
13
+ raise "Expected 'test1%5B0%5D=1&test1%5B1%5D=2&test1%5B2%5D=3' but got: '#{res}'." if res != "test1%5B0%5D=1&test1%5B1%5D=2&test1%5B2%5D=3"
14
+
15
+ res = Http2::PostDataGenerator.new(
16
+ "test1" => {
17
+ "order" => {
18
+ [:Bnet_profile, "profile_id"] => 5
19
+ }
20
+ }
21
+ ).generate
22
+ raise "Expected 'test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5' but got: '#{res}'." if res != "test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5"
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require "spec_helper"
2
+
3
+ describe Http2::UrlBuilder do
4
+ context "#build" do
5
+ it "builds correctly" do
6
+ ub = Http2::UrlBuilder.new
7
+ ub.protocol = "https"
8
+ ub.host = "www.github.com"
9
+ ub.port = "443"
10
+ ub.path = "index.php"
11
+ ub.params["test"] = "true"
12
+ ub.params["test2"] = "false"
13
+
14
+ ub.build.should eq "https://www.github.com:443/index.php?test=true&test2=false"
15
+ end
16
+ end
17
+ end
data/spec/http2_spec.rb CHANGED
@@ -1,27 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "Http2" do
4
- it "should be able to recursively parse post-data-hashes." do
5
- res = Http2.post_convert_data(
6
- "test1" => "test2"
7
- )
8
- raise "Expected 'test1=test2' but got: '#{res}'." if res != "test1=test2"
9
-
10
- res = Http2.post_convert_data(
11
- "test1" => [1, 2, 3]
12
- )
13
- raise "Expected 'test1%5B0%5D=1&test1%5B1%5D=2&test1%5B2%5D=3' but got: '#{res}'." if res != "test1%5B0%5D=1&test1%5B1%5D=2&test1%5B2%5D=3"
14
-
15
- res = Http2.post_convert_data(
16
- "test1" => {
17
- "order" => {
18
- [:Bnet_profile, "profile_id"] => 5
19
- }
20
- }
21
- )
22
- raise "Expected 'test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5' but got: '#{res}'." if res != "test1%5Border%5D%5B%5B%3ABnet_profile%2C+%22profile_id%22%5D%5D=5"
23
- end
24
-
25
4
  it "should be able to do normal post-requests." do
26
5
  require "json"
27
6
 
@@ -138,9 +117,9 @@ describe "Http2" do
138
117
 
139
118
  Http2.new(:host => "http2test.kaspernj.org") do |http|
140
119
  res = http.post(
141
- :url => "/content_type_test.php",
142
- :content_type => "plain/text",
143
- :post => "test1_test2_test3"
120
+ url: "content_type_test.php",
121
+ content_type: "plain/text",
122
+ post: "test1_test2_test3"
144
123
  )
145
124
 
146
125
  data = JSON.parse(res.body)
@@ -148,4 +127,19 @@ describe "Http2" do
148
127
  data["PHP_INPUT"].should eql("test1_test2_test3")
149
128
  end
150
129
  end
130
+
131
+ it "should set various timeouts" do
132
+ Http2.new(:host => "http2test.kaspernj.org") do |http|
133
+ res = http.get("content_type_test.php")
134
+ http.keepalive_timeout.should eq 5
135
+ http.keepalive_max.should eq 100
136
+ end
137
+ end
138
+
139
+ it "should follow redirects" do
140
+ Http2.new(host: "http2test.kaspernj.org", follow_redirects: true) do |http|
141
+ resp = http.get("redirect_test.php")
142
+ resp.code.should eq "200"
143
+ end
144
+ end
151
145
  end
data/spec/spec_helper.rb CHANGED
@@ -11,5 +11,7 @@ require 'http2'
11
11
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
12
 
13
13
  RSpec.configure do |config|
14
-
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = [:expect, :should]
16
+ end
15
17
  end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kasper Johansen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-09 00:00:00.000000000 Z
11
+ date: 2014-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-cases
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 2.8.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 2.8.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.12'
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
54
  version: '3.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 1.0.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 1.0.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 1.8.4
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 1.8.4
83
83
  description: A lightweight framework for doing http-connections in Ruby. Supports
@@ -89,8 +89,8 @@ extra_rdoc_files:
89
89
  - LICENSE.txt
90
90
  - README.md
91
91
  files:
92
- - .document
93
- - .rspec
92
+ - ".document"
93
+ - ".rspec"
94
94
  - Gemfile
95
95
  - Gemfile.lock
96
96
  - LICENSE.txt
@@ -98,13 +98,20 @@ files:
98
98
  - Rakefile
99
99
  - VERSION
100
100
  - http2.gemspec
101
+ - include/connection.rb
101
102
  - include/errors.rb
102
- - include/post_multipart_helper.rb
103
+ - include/get_request.rb
104
+ - include/post_data_generator.rb
105
+ - include/post_multipart_request.rb
106
+ - include/post_request.rb
103
107
  - include/response.rb
104
108
  - include/response_reader.rb
109
+ - include/url_builder.rb
105
110
  - include/utils.rb
106
111
  - lib/http2.rb
107
112
  - shippable.yml
113
+ - spec/http2/post_data_generator_spec.rb
114
+ - spec/http2/url_builder_spec.rb
108
115
  - spec/http2_spec.rb
109
116
  - spec/spec_helper.rb
110
117
  homepage: http://github.com/kaspernj/http2
@@ -117,17 +124,17 @@ require_paths:
117
124
  - lib
118
125
  required_ruby_version: !ruby/object:Gem::Requirement
119
126
  requirements:
120
- - - '>='
127
+ - - ">="
121
128
  - !ruby/object:Gem::Version
122
129
  version: '0'
123
130
  required_rubygems_version: !ruby/object:Gem::Requirement
124
131
  requirements:
125
- - - '>='
132
+ - - ">="
126
133
  - !ruby/object:Gem::Version
127
134
  version: '0'
128
135
  requirements: []
129
136
  rubyforge_project:
130
- rubygems_version: 2.0.14
137
+ rubygems_version: 2.4.0
131
138
  signing_key:
132
139
  specification_version: 4
133
140
  summary: A lightweight framework for doing http-connections in Ruby. Supports cookies,
@@ -1,77 +0,0 @@
1
- require "tempfile"
2
-
3
- class Http2::PostMultipartHelper
4
- attr_reader :boundary
5
-
6
- def initialize(http2)
7
- @nl = http2.nl
8
-
9
- #Generate random string.
10
- @boundary = rand(36**50).to_s(36)
11
- end
12
-
13
- def generate_raw(phash)
14
- Tempfile.open("http2_post_multipart_tmp_#{@boundary}") do |praw|
15
- phash.each do |key, val|
16
- praw << "--#{@boundary}#{@nl}"
17
-
18
- if val.is_a?(Tempfile) && val.respond_to?(:original_filename)
19
- parse_temp_file(key, val, praw)
20
- elsif val.is_a?(Hash) && val[:filename]
21
- parse_file(key, val, praw)
22
- else
23
- praw << "Content-Disposition: form-data; name=\"#{key}\";#{@nl}"
24
- praw << "Content-Length: #{val.to_s.bytesize}#{@nl}"
25
- end
26
-
27
- praw << "Content-Type: text/plain#{@nl}"
28
- praw << @nl
29
-
30
- if val.class.name.to_s == "StringIO"
31
- praw << val.read
32
- elsif val.is_a?(Hash) && val[:content]
33
- praw << val[:content].to_s
34
- elsif val.is_a?(Hash) && val[:fpath]
35
- read_file(val[:fpath], praw)
36
- else
37
- praw << val.to_s
38
- end
39
-
40
- praw << @nl
41
- end
42
-
43
- praw << "--#{@boundary}--"
44
-
45
- yield self, praw
46
- end
47
- end
48
-
49
- def read_file(path, praw)
50
- File.open(path, "r") do |fp|
51
- begin
52
- while data = fp.sysread(4096)
53
- praw << data
54
- end
55
- rescue EOFError
56
- # Happens when done.
57
- end
58
- end
59
- end
60
-
61
- def parse_temp_file(key, val, praw)
62
- praw << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{val.original_filename}\";#{@nl}"
63
- praw << "Content-Length: #{val.to_s.bytesize}#{@nl}"
64
- end
65
-
66
- def parse_file(key, val, praw)
67
- praw << "Content-Disposition: form-data; name=\"#{key}\"; filename=\"#{val[:filename]}\";#{@nl}"
68
-
69
- if val[:content]
70
- praw << "Content-Length: #{val[:content].to_s.bytesize}#{@nl}"
71
- elsif val[:fpath]
72
- praw << "Content-Length: #{File.size(val[:fpath])}#{@nl}"
73
- else
74
- raise "Could not figure out where to get content from."
75
- end
76
- end
77
- end