hatetepe 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/hatetepe.gemspec CHANGED
@@ -12,16 +12,16 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{The HTTP toolkit}
13
13
  #s.description = %q{TODO: write description}
14
14
 
15
- s.add_dependency "http_parser.rb"
15
+ s.add_dependency "http_parser.rb", "~> 0.5.3"
16
16
  s.add_dependency "eventmachine"
17
- s.add_dependency "em-synchrony"
17
+ s.add_dependency "em-synchrony", "~> 1.0"
18
18
  s.add_dependency "rack"
19
19
  s.add_dependency "async-rack"
20
20
  s.add_dependency "thor"
21
21
 
22
22
  s.add_development_dependency "rspec"
23
23
  s.add_development_dependency "fakefs"
24
- s.add_development_dependency "em-http-request"
24
+ s.add_development_dependency "em-http-request", "~> 1.0"
25
25
 
26
26
  s.files = `git ls-files`.split("\n") - [".gitignore"]
27
27
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -107,7 +107,7 @@ module Hatetepe
107
107
 
108
108
  if header[0..13] == "Content-Length"
109
109
  @chunked = false
110
- elsif header[0..16] == "Transfer-Encoding"
110
+ elsif @chunked.nil? && header[0..16] == "Transfer-Encoding"
111
111
  @chunked = true
112
112
  end
113
113
 
@@ -115,7 +115,7 @@ module Hatetepe
115
115
  end
116
116
 
117
117
  def body(chunk)
118
- if Body === chunk
118
+ if chunk.respond_to? :each
119
119
  chunk.each &method(:body)
120
120
  return
121
121
  end
@@ -142,12 +142,10 @@ module Hatetepe
142
142
  def complete
143
143
  return if ready?
144
144
 
145
- if writing_body? && chunked?
146
- write "0\r\n"
147
- write "\r\n"
148
- elsif writing_headers? || writing_trailing_headers?
149
- write "\r\n"
145
+ if writing_headers? || writing_trailing_headers?
146
+ header "Content-Length", "0"
150
147
  end
148
+ body ""
151
149
 
152
150
  on_complete.each {|blk| blk.call }
153
151
  reset
data/lib/hatetepe/cli.rb CHANGED
@@ -27,12 +27,11 @@ module Hatetepe
27
27
  $stderr.flush
28
28
  app = Rack::Builder.parse_file(rackup)[0]
29
29
 
30
+ EM.epoll
30
31
  EM.synchrony do
31
32
  trap("INT") { EM.stop }
32
33
  trap("TERM") { EM.stop }
33
34
 
34
- EM.epoll
35
-
36
35
  host = options[:bind] || "127.0.0.1"
37
36
  port = options[:port] || 3000
38
37
 
@@ -59,6 +59,7 @@ module Hatetepe
59
59
  parser.on_headers {
60
60
  requests.reverse.find {|req| !!req.response }.tap {|req|
61
61
  req.succeed req.response
62
+ parser.complete if req.verb == :head
62
63
  }
63
64
  }
64
65
 
@@ -74,8 +75,25 @@ module Hatetepe
74
75
  requests << request
75
76
  Fiber.new {
76
77
  builder.request request.verb, request.uri
78
+
79
+ if request.headers["Content-Type"] == "application/x-www-form-urlencoded"
80
+ if request.body.respond_to? :read
81
+ request.headers["Content-Length"] = request.body.read.bytesize
82
+ else
83
+ request.headers["Content-Length"] = request.body.length
84
+ end
85
+ end
77
86
  builder.headers request.headers
78
- builder.body request.body unless request.body.empty?
87
+
88
+ b = request.body
89
+ if Body === b || b.respond_to?(:each)
90
+ builder.body b
91
+ elsif b.respond_to? :read
92
+ builder.body b.read
93
+ else
94
+ builder.body [b]
95
+ end
96
+
79
97
  builder.complete
80
98
  }.resume
81
99
  end
@@ -41,11 +41,7 @@ module Hatetepe
41
41
  message.body << chunk unless message.body.closed_write?
42
42
  }
43
43
 
44
- p.on_message_complete = proc {
45
- message.body.rewind
46
- message.body.close_write unless message.body.closed_write?
47
- event! :complete
48
- }
44
+ p.on_message_complete = method(:complete)
49
45
  }
50
46
 
51
47
  reset
@@ -61,6 +57,12 @@ module Hatetepe
61
57
  @message = nil
62
58
  end
63
59
 
60
+ def complete
61
+ message.body.rewind
62
+ message.body.close_write unless message.body.closed_write?
63
+ event! :complete
64
+ end
65
+
64
66
  def <<(data)
65
67
  @parser << data
66
68
  rescue HTTP::Parser::Error => e
@@ -1,3 +1,3 @@
1
1
  module Hatetepe
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -14,9 +14,8 @@ module Rack
14
14
  Signal.trap("INT") { EM.stop }
15
15
  Signal.trap("TERM") { EM.stop }
16
16
 
17
- EM.run {
18
- EM.epoll
19
-
17
+ EM.epoll
18
+ EM.synchrony {
20
19
  server = ::Hatetepe::Server.start options
21
20
  yield server if block_given?
22
21
  }
data/spec/spec_helper.rb CHANGED
@@ -7,9 +7,8 @@ require "em-synchrony/em-http"
7
7
  require "fakefs/safe"
8
8
 
9
9
  RSpec.configure {|config|
10
- config.before {
10
+ config.before(:all) {
11
11
  EM.class_eval {
12
- @spec_hooks = []
13
12
  class << self
14
13
  attr_reader :spec_hooks
15
14
  def synchrony_with_hooks(blk = nil, tail = nil, &block)
@@ -24,9 +23,8 @@ RSpec.configure {|config|
24
23
  }
25
24
  }
26
25
 
27
- config.after {
26
+ config.after(:all) {
28
27
  EM.class_eval {
29
- @spec_hooks = nil
30
28
  class << self
31
29
  remove_method :spec_hooks
32
30
  alias_method :synchrony, :synchrony_without_hooks
@@ -34,4 +32,12 @@ RSpec.configure {|config|
34
32
  end
35
33
  }
36
34
  }
35
+
36
+ config.before(:each) {
37
+ EM.instance_variable_set :@spec_hooks, []
38
+ }
39
+
40
+ config.after(:each) {
41
+ EM.instance_variable_set :@spec_hooks, nil
42
+ }
37
43
  }
@@ -19,8 +19,8 @@ describe Rack::Handler::Hatetepe do
19
19
  }
20
20
 
21
21
  it "starts an Hatetepe server" do
22
- EM.should_receive(:run) {|&block|
23
- EM.should_receive(:epoll)
22
+ EM.should_receive :epoll
23
+ EM.should_receive(:synchrony) {|&block|
24
24
  Hatetepe::Server.should_receive(:start) {|opts|
25
25
  opts[:host].should equal(options[:Host])
26
26
  opts[:port].should equal(options[:Port])
@@ -43,7 +43,7 @@ describe Rack::Handler::Hatetepe do
43
43
  end
44
44
 
45
45
  it "can be stopped by sending SIGTERM or SIGINT" do
46
- EM.should_receive(:run) {|&block| block.call }
46
+ EM.should_receive(:synchrony) {|&block| block.call }
47
47
 
48
48
  trapped_signals = []
49
49
  Signal.should_receive(:trap).twice {|sig, &block|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatetepe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-15 00:00:00.000000000Z
12
+ date: 2011-10-02 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http_parser.rb
16
- requirement: &71760510 !ruby/object:Gem::Requirement
16
+ requirement: &75172870 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ! '>='
19
+ - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.5.3
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *71760510
24
+ version_requirements: *75172870
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: eventmachine
27
- requirement: &71757150 !ruby/object:Gem::Requirement
27
+ requirement: &75172660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,21 +32,21 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *71757150
35
+ version_requirements: *75172660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: em-synchrony
38
- requirement: &71756500 !ruby/object:Gem::Requirement
38
+ requirement: &75172390 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: '1.0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *71756500
46
+ version_requirements: *75172390
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack
49
- requirement: &71755350 !ruby/object:Gem::Requirement
49
+ requirement: &75172180 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *71755350
57
+ version_requirements: *75172180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: async-rack
60
- requirement: &71754470 !ruby/object:Gem::Requirement
60
+ requirement: &75171950 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *71754470
68
+ version_requirements: *75171950
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
- requirement: &71753440 !ruby/object:Gem::Requirement
71
+ requirement: &75171740 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *71753440
79
+ version_requirements: *75171740
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &71749920 !ruby/object:Gem::Requirement
82
+ requirement: &75171530 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *71749920
90
+ version_requirements: *75171530
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: fakefs
93
- requirement: &71749060 !ruby/object:Gem::Requirement
93
+ requirement: &75171320 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,18 +98,18 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *71749060
101
+ version_requirements: *75171320
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: em-http-request
104
- requirement: &71748040 !ruby/object:Gem::Requirement
104
+ requirement: &75171070 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: '1.0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *71748040
112
+ version_requirements: *75171070
113
113
  description:
114
114
  email:
115
115
  - lars.gierth@gmail.com