cool.io-http 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # CHANGES
2
2
 
3
+ ## cool.io-http 0.3.1 -- 2012-02-18
4
+
5
+ * Make sure Response#status is an integer
6
+ * Fixed a few bugs
7
+ * Return the response object in HttpFiber
8
+
3
9
  ## cool.io-http 0.3.0 -- 2012-01-09
4
10
 
5
11
  * Introduced `Coolio::Http::Response`. So now instead of passing
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "cool.io-http"
5
- s.version = "0.3.0"
5
+ s.version = "0.3.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Lin Jen-Shin (godfat)"]
9
- s.date = "2012-01-09"
9
+ s.date = "2012-02-18"
10
10
  s.description = "Simpler HTTP for [cool.io][]\n\n[cool.io]: https://github.com/tarcieri/cool.io"
11
11
  s.email = ["godfat (XD) godfat.org"]
12
12
  s.files = [
@@ -30,7 +30,7 @@ Gem::Specification.new do |s|
30
30
  "test/test_http.rb"]
31
31
  s.homepage = "https://github.com/godfat/cool.io-http"
32
32
  s.require_paths = ["lib"]
33
- s.rubygems_version = "1.8.15"
33
+ s.rubygems_version = "1.8.16"
34
34
  s.summary = "Simpler HTTP for [cool.io][]"
35
35
  s.test_files = ["test/test_http.rb"]
36
36
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module CoolioHttp
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
@@ -34,7 +34,7 @@ class Coolio::Http < Coolio::HttpClient
34
34
  :body => p.read, &block)
35
35
  end
36
36
 
37
- def self.connect host, port, ssl
37
+ def self.connect host, port, ssl=false
38
38
  http = super(host, port)
39
39
  http.extend(Coolio::SSL) if ssl
40
40
  http
@@ -66,7 +66,7 @@ class Coolio::Http < Coolio::HttpClient
66
66
  super
67
67
  @http_callback.call(Response.new(@http_data.join,
68
68
  @http_response_header,
69
- @http_response_header.http_status))
69
+ @http_response_header.http_status.to_i))
70
70
  end
71
71
 
72
72
  def on_connect
@@ -4,9 +4,9 @@ require 'fiber'
4
4
  class Coolio::HttpFiber < Coolio::Http
5
5
  def self.request opts={}
6
6
  f = Fiber.current
7
- super(opts){ |response, headers|
8
- yield(response, headers)
9
- f.resume
7
+ super(opts){ |response|
8
+ yield(response) if block_given?
9
+ f.resume(response)
10
10
  }
11
11
  Fiber.yield
12
12
  end
@@ -1,33 +1,53 @@
1
1
 
2
+ require 'bacon'
2
3
  require 'cool.io/http'
4
+ require 'rack'
3
5
 
4
- def request klass, url
5
- klass.request(:url => url){ |response|
6
- puts "Response: #{response.body}"
7
- puts
8
- puts " Headers: #{response.headers}"
9
- puts " Status: #{response.status}"
10
- }
6
+ Bacon.summary_on_exit
7
+ port = rand(30000) + 1024
8
+
9
+ pid = Process.fork do
10
+ $stdout.reopen(IO::NULL)
11
+ $stderr.reopen(IO::NULL)
12
+ Rack::Handler::WEBrick.run(
13
+ lambda{ |env| [200, {'Content-Type' => 'test/ok'}, ['ok']] },
14
+ :Port => port)
15
+ end
16
+ sleep(0.5)
17
+ at_exit{ Process.kill 2, pid }
18
+
19
+ module Kernel
20
+ def eq? rhs
21
+ self == rhs
22
+ end
11
23
  end
12
24
 
13
- request(Coolio::Http, 'http://google.com')
14
- Coolio::Loop.default.run
15
- puts
16
-
17
- Fiber.new{
18
- request(Coolio::HttpFiber, 'https://google.com')
19
- puts "DONE"
20
- }.resume
21
- puts "GO"
22
- Coolio::Loop.default.run
23
-
24
- describe 'ssl' do
25
- should 'respect ssl?' do
26
- port = rand(30000) + 1024
27
- serv = TCPServer.new('localhost', port)
25
+ describe Coolio::Http do
26
+ def request klass, url
27
+ klass.request(:url => url){ |response| assert(response) }
28
+ end
29
+
30
+ def assert response
31
+ response.body .should.eq 'ok'
32
+ response.headers['CONTENT_TYPE'].should.eq 'test/ok'
33
+ response.status .should.eq 200
34
+ end
35
+
36
+ should 'asynchrony' do
37
+ request(Coolio::Http, "http://localhost:#{port}")
38
+ Coolio::Loop.default.run
39
+ end
40
+
41
+ should 'synchrony' do
42
+ Fiber.new{
43
+ assert(request(Coolio::HttpFiber, "http://localhost:#{port}"))
44
+ }.resume
45
+ Coolio::Loop.default.run
46
+ end
47
+
48
+ should 'ssl' do
28
49
  sock = TCPSocket.new('localhost', port)
29
50
  Coolio::Http.new(sock) .ssl?.should == false
30
51
  Coolio::Http.new(sock).extend(Coolio::SSL).ssl?.should == true
31
- serv.close
32
52
  end
33
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cool.io-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-09 00:00:00.000000000 Z
12
+ date: 2012-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cool.io
16
- requirement: &2152924280 !ruby/object:Gem::Requirement
16
+ requirement: &2153122400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152924280
24
+ version_requirements: *2153122400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mime-types
27
- requirement: &2152939800 !ruby/object:Gem::Requirement
27
+ requirement: &2153121580 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152939800
35
+ version_requirements: *2153121580
36
36
  description: ! 'Simpler HTTP for [cool.io][]
37
37
 
38
38
 
@@ -81,9 +81,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  version: '0'
82
82
  requirements: []
83
83
  rubyforge_project:
84
- rubygems_version: 1.8.15
84
+ rubygems_version: 1.8.16
85
85
  signing_key:
86
86
  specification_version: 3
87
87
  summary: Simpler HTTP for [cool.io][]
88
88
  test_files:
89
89
  - test/test_http.rb
90
+ has_rdoc: