http2 0.0.27 → 0.0.28

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70a2017c40ca44407bdd25e3ace7cd467b8db68a
4
- data.tar.gz: f9247267fc42c9750762de30d5c72b3c41707ce3
3
+ metadata.gz: a28eaa08bb929414333c763236db9b220a499eb8
4
+ data.tar.gz: 8cb38c1995fc84a1562b3c8a117ed702fff75db1
5
5
  SHA512:
6
- metadata.gz: 9b17165fe2bdab74cdda084bf3257f2ec3e652516824ca0f021239ce9fc62cbdfe2392b6c3b773b6d6081f21bdf54e8815f36512795b25f535a53fe93f3e62da
7
- data.tar.gz: 27e9de354dc34e2c574476423b0c76cfec048c2b1e8f6f1a6c54309ab0658ec168b8c3b432c70af01416223aa94a236c53aac1806757c80ec3f7904debaf57dd
6
+ metadata.gz: 63c24b5f90f05a1e8f67a59cbe7765475bd087ae384b873c47ee90794f52e1ea5c88386769e30bdc51234fde4f32ae2454d16e990acf13fc97ba5e7a81e4bcce
7
+ data.tar.gz: 0f42d6609f0520b481723dd5c0d648371cd8b2b0f050c6608f45e81b9a511c87d4a651942d168c21f92d30fbb08f826c40450666ec8da657ba5f27ef5b493242
data/README.md CHANGED
@@ -16,14 +16,14 @@ Http2.new(:host => "www.google.dk") do |http|
16
16
  puts res.body
17
17
  puts "All response-headers: #{res.headers}"
18
18
  puts "Specific header: #{res.header("HeaderName")}"
19
-
19
+
20
20
  #Post-request.
21
21
  res = http.post(:url => "path/to/something", :post => {
22
22
  "some_post_val" => "some_value"
23
23
  })
24
-
24
+
25
25
  res.content_type #=> "text/html"
26
-
26
+
27
27
  #Post-multipart (upload).
28
28
  res = http.post_multipart(:url => "path/to/something", :post => {
29
29
  "test_file1" => {
@@ -31,13 +31,22 @@ Http2.new(:host => "www.google.dk") do |http|
31
31
  :filename => "specfile"
32
32
  }
33
33
  })
34
-
34
+
35
35
  puts "Cookies until now: #{http.cookies}"
36
36
  end
37
37
  ```
38
38
 
39
+
40
+ ## Reconnect
41
+
42
+ Handy when doing retries.
43
+
44
+ ```ruby
45
+ http.reconnect
46
+ ```
47
+
39
48
  ## Contributing to http2
40
-
49
+
41
50
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
42
51
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
43
52
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.27
1
+ 0.0.28
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: http2 0.0.27 ruby lib
5
+ # stub: http2 0.0.28 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "http2"
9
- s.version = "0.0.27"
9
+ s.version = "0.0.28"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Kasper Johansen"]
14
- s.date = "2014-11-28"
14
+ s.date = "2014-12-03"
15
15
  s.description = "A lightweight framework for doing http-connections in Ruby. Supports cookies, keep-alive, compressing and much more."
16
16
  s.email = "k@spernj.org"
17
17
  s.extra_rdoc_files = [
@@ -50,6 +50,10 @@ class Http2
50
50
  end
51
51
  end
52
52
 
53
+ def reconnect
54
+ @connection.reconnect
55
+ end
56
+
53
57
  def new_url
54
58
  builder = Http2::UrlBuilder.new
55
59
  builder.host = @args[:host]
@@ -5,11 +5,11 @@ describe "Http2" do
5
5
  require "json"
6
6
 
7
7
  #Test posting keep-alive and advanced post-data.
8
- Http2.new(:host => "www.partyworm.dk", :debug => false) do |http|
8
+ Http2.new(host: "www.partyworm.dk", debug: false) do |http|
9
9
  0.upto(5) do
10
10
  resp = http.get("multipart_test.php")
11
11
 
12
- resp = http.post(:url => "multipart_test.php?choice=post-test", :post => {
12
+ resp = http.post(url: "multipart_test.php?choice=post-test", post: {
13
13
  "val1" => "test1",
14
14
  "val2" => "test2",
15
15
  "val3" => [
@@ -29,40 +29,52 @@ describe "Http2" do
29
29
  })
30
30
  res = JSON.parse(resp.body)
31
31
 
32
- raise "Expected 'res' to be a hash." if !res.is_a?(Hash)
33
- raise "Error 1" if res["val1"] != "test1"
34
- raise "Error 2" if res["val2"] != "test2"
35
- raise "Error 3" if !res["val3"] or res["val3"][0] != "test3"
36
- raise "Error 4" if res["val4"]["val5"] != "test5"
37
- raise "Error 5" if res["val6"]["val7"][0]["val8"] != "test8"
38
- raise "Array error: '#{res["val9"]}'." if res["val9"][0] != "a" or res["val9"][1] != "b" or res["val9"][2] != "d"
32
+ res.is_a?(Hash).should eq true
33
+ res["val1"].should eq "test1"
34
+ res["val2"].should eq "test2"
35
+ res["val3"][0].should eq "test3"
36
+ res["val4"]["val5"].should eq "test5"
37
+ res["val6"]["val7"][0]["val8"].should eq "test8"
38
+ res["val9"][0].should eq "a"
39
+ res["val9"][1].should eq "b"
40
+ res["val9"][2].should eq "d"
39
41
  end
40
42
  end
41
43
  end
42
44
 
45
+ it "#reconnect" do
46
+ Http2.new(host: "www.partyworm.dk", follow_redirects: false, encoding_gzip: false, debug: false) do |http|
47
+ resp1 = http.get("multipart_test.php")
48
+ http.reconnect
49
+ resp2 = http.get("multipart_test.php")
50
+
51
+ resp1.body.should eq resp2.body
52
+ end
53
+ end
54
+
43
55
  it "should be able to do multipart-requests and keep-alive when using multipart." do
44
- Http2.new(:host => "www.partyworm.dk", :follow_redirects => false, :encoding_gzip => false, :debug => false) do |http|
56
+ Http2.new(host: "www.partyworm.dk", follow_redirects: false, encoding_gzip: false, debug: false) do |http|
45
57
  0.upto(5) do
46
58
  fpath = File.realpath(__FILE__)
47
59
  fpath2 = "#{File.realpath(File.dirname(__FILE__))}/../lib/http2.rb"
48
60
 
49
- resp = http.post_multipart(:url => "multipart_test.php", :post => {
61
+ resp = http.post_multipart(url: "multipart_test.php", post: {
50
62
  "test_var" => "true",
51
63
  "test_file1" => {
52
- :fpath => fpath,
53
- :filename => "specfile"
64
+ fpath: fpath,
65
+ filename: "specfile"
54
66
  },
55
67
  "test_file2" => {
56
- :fpath => fpath2,
57
- :filename => "http2.rb"
68
+ fpath: fpath2,
69
+ filename: "http2.rb"
58
70
  }
59
71
  })
60
72
 
61
73
  data = JSON.parse(resp.body)
62
74
 
63
- raise "Expected 'test_var' post to be 'true' but it wasnt: '#{data["post"]["test_var"]}'." if data["post"]["test_var"] != "true"
64
- raise "Expected 'test_file1' to be the same as file but it wasnt:\n#{data["files_data"]["test_file1"]}\n\n#{File.read(fpath)}" if data["files_data"]["test_file1"] != File.read(fpath)
65
- raise "Expected 'test_file2' to be the same as file but it wasnt:\n#{data["files_data"]["test_file2"]}\n\n#{File.read(fpath)}" if data["files_data"]["test_file2"] != File.read(fpath2)
75
+ data["post"]["test_var"].should eq "true"
76
+ data["files_data"]["test_file1"].should eq File.read(fpath)
77
+ data["files_data"]["test_file2"].should eq File.read(fpath2)
66
78
  end
67
79
  end
68
80
  end
@@ -76,12 +88,12 @@ describe "Http2" do
76
88
  ]
77
89
  urls = ["robots.txt"]
78
90
 
79
- Http2.new(:host => "www.partyworm.dk", :debug => false) do |http|
91
+ Http2.new(host: "www.partyworm.dk", debug: false) do |http|
80
92
  0.upto(105) do |count|
81
93
  url = urls[rand(urls.size)]
82
94
  #print "Doing request #{count} of 200 (#{url}).\n"
83
95
  res = http.get(url)
84
- raise "Body was empty." if res.body.to_s.length <= 0
96
+ res.body.to_s.length.should > 0
85
97
  end
86
98
  end
87
99
  end
@@ -93,17 +105,17 @@ describe "Http2" do
93
105
 
94
106
  it "should raise exception when something is not found" do
95
107
  expect{
96
- Http2.new(:host => "www.partyworm.dk") do |http|
108
+ Http2.new(host: "www.partyworm.dk") do |http|
97
109
  http.get("something_that_does_not_exist.php")
98
110
  end
99
111
  }.to raise_error(::Http2::Errors::Notfound)
100
112
  end
101
113
 
102
114
  it "should be able to post json" do
103
- Http2.new(:host => "http2test.kaspernj.org") do |http|
115
+ Http2.new(host: "http2test.kaspernj.org") do |http|
104
116
  res = http.post(
105
- :url => "/jsontest.php",
106
- :json => {:testkey => "testvalue"}
117
+ url: "/jsontest.php",
118
+ json: {testkey: "testvalue"}
107
119
  )
108
120
 
109
121
  data = JSON.parse(res.body)
@@ -115,7 +127,7 @@ describe "Http2" do
115
127
  it "should be able to post custom content types" do
116
128
  require "json"
117
129
 
118
- Http2.new(:host => "http2test.kaspernj.org") do |http|
130
+ Http2.new(host: "http2test.kaspernj.org") do |http|
119
131
  res = http.post(
120
132
  url: "content_type_test.php",
121
133
  content_type: "plain/text",
@@ -129,7 +141,7 @@ describe "Http2" do
129
141
  end
130
142
 
131
143
  it "should set various timeouts" do
132
- Http2.new(:host => "http2test.kaspernj.org") do |http|
144
+ Http2.new(host: "http2test.kaspernj.org") do |http|
133
145
  res = http.get("content_type_test.php")
134
146
  http.keepalive_timeout.should eq 5
135
147
  http.keepalive_max.should eq 100
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.27
4
+ version: 0.0.28
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-11-28 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: string-cases