hatetepe 0.5.0.pre.2 → 0.5.0.pre.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- The HTTP Toolkit
1
+ The HTTP Toolkit [![Build Status](https://secure.travis-ci.org/lgierth/hatetepe.png?branch=master)](http://travis-ci.org/lgierth/hatetepe) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/lgierth/hatetepe)
2
2
  ================
3
3
 
4
4
  Hatetepe is a framework for building HTTP servers, clients and proxies using the
@@ -14,8 +14,6 @@ automatic JSON or form-data encoding, have a look at
14
14
  [Hatetepe adapter](https://github.com/technoweenie/faraday/pull/108)
15
15
  for it being worked on.
16
16
 
17
- [![Build status](https://secure.travis-ci.org/lgierth/hatetepe.png?branch=master)](http://travis-ci.org/lgierth/hatetepe)
18
-
19
17
 
20
18
  Getting Started (Server)
21
19
  ------------------------
data/lib/hatetepe/body.rb CHANGED
@@ -2,8 +2,6 @@ require "em-synchrony"
2
2
  require "eventmachine"
3
3
  require "stringio"
4
4
 
5
- require "hatetepe/deferred_status_fix"
6
-
7
5
  module Hatetepe
8
6
  # Thin wrapper around StringIO for asynchronous body processing.
9
7
  class Body
@@ -113,11 +111,15 @@ module Hatetepe
113
111
  #
114
112
  # @yield [String] Block to execute for each incoming data chunk.
115
113
  #
116
- # @return [undefined]
114
+ # @return [Enumerator,self]
117
115
  def each(&block)
116
+ return to_enum(__method__) unless block
117
+
118
118
  @receivers << block
119
119
  block.call io.string.dup unless io.string.empty?
120
120
  sync
121
+
122
+ self
121
123
  end
122
124
 
123
125
  # Forwards to StringIO#read.
@@ -1,4 +1,3 @@
1
- require "hatetepe/deferred_status_fix"
2
1
  require "hatetepe/message"
3
2
 
4
3
  module Hatetepe
@@ -14,7 +14,10 @@ module Hatetepe::Server
14
14
 
15
15
  attr_reader :config, :requests
16
16
 
17
- CONFIG_DEFAULTS = { :timeout => 5.0 }
17
+ CONFIG_DEFAULTS = {
18
+ :timeout => 5.0,
19
+ :app => [ Pipeline, KeepAlive, RackApp ]
20
+ }
18
21
 
19
22
  # @api public
20
23
  def self.start(config)
@@ -23,7 +26,7 @@ module Hatetepe::Server
23
26
 
24
27
  # @api semipublic
25
28
  def initialize(config)
26
- @config = CONFIG_DEFAULTS.merge(config)
29
+ @config = CONFIG_DEFAULTS.merge(config).freeze
27
30
  end
28
31
 
29
32
  # @api semipublic
@@ -33,11 +36,15 @@ module Hatetepe::Server
33
36
  @builder.on_write &method(:send_data)
34
37
  # @builder.on_write {|data| p "<--| #{data}" }
35
38
 
36
- @app = [
37
- Pipeline,
38
- KeepAlive,
39
- RackApp
40
- ].reverse.inject(config[:app]) {|inner, outer| outer.new(inner, self) }
39
+ app =
40
+ if config[:app].respond_to?(:call)
41
+ [ *CONFIG_DEFAULTS[:app], config[:app] ]
42
+ else
43
+ config[:app].dup
44
+ end
45
+ @app = app.inject(app.pop) do |inner, outer|
46
+ outer.new(inner, self)
47
+ end
41
48
 
42
49
  self.comm_inactivity_timeout = config[:timeout]
43
50
  end
@@ -47,7 +54,7 @@ module Hatetepe::Server
47
54
  # p "-->| #{data}"
48
55
  @parser << data
49
56
  rescue Object => ex
50
- p ex
57
+ puts [ex.message, *ex.backtrace].join("\n\t")
51
58
  close_connection
52
59
  end
53
60
 
@@ -1,3 +1,3 @@
1
1
  module Hatetepe
2
- VERSION = "0.5.0.pre.2"
2
+ VERSION = "0.5.0.pre.3"
3
3
  end
@@ -136,6 +136,22 @@ describe Hatetepe::Body do
136
136
  body.succeed
137
137
  succeeded.should be_true
138
138
  end
139
+
140
+ it "returns self" do
141
+ Fiber.new { body.each {}.should == body }.resume
142
+ body.succeed
143
+ end
144
+
145
+ describe "without a block" do
146
+ let(:enumerator) { stub }
147
+
148
+ before { body.stub(:to_enum).with(:each) { enumerator } }
149
+
150
+ it "immediately returns an Enumerator" do
151
+ Fiber.new { body.each.should == enumerator }.resume
152
+ body.succeed
153
+ end
154
+ end
139
155
  end
140
156
 
141
157
  context "#read(length, buffer)" do
@@ -28,17 +28,18 @@ describe Hatetepe::Server, "(public API)" do
28
28
  :config => {
29
29
  :host => "127.0.5.1",
30
30
  :port => 3000,
31
- :app => stub("app")
31
+ :app => app
32
32
  },
33
33
  :send_data => nil
34
34
  })
35
35
  s.stub(:comm_inactivity_timeout=)
36
+ s.stub(:close_connection)
36
37
  s.post_init
37
38
  end
38
39
  end
39
40
 
40
41
  let :app do
41
- subject.config[:app]
42
+ stub("app", :call => nil)
42
43
  end
43
44
 
44
45
  let :http_request do
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.5.0.pre.2
4
+ version: 0.5.0.pre.3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-02 00:00:00.000000000 Z
12
+ date: 2012-08-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: http_parser.rb
@@ -160,7 +160,6 @@ files:
160
160
  - lib/hatetepe/cli.rb
161
161
  - lib/hatetepe/client.rb
162
162
  - lib/hatetepe/connection.rb
163
- - lib/hatetepe/deferred_status_fix.rb
164
163
  - lib/hatetepe/events.rb
165
164
  - lib/hatetepe/message.rb
166
165
  - lib/hatetepe/parser.rb
@@ -1,11 +0,0 @@
1
- require "eventmachine"
2
-
3
- module EM::Deferrable
4
- def set_deferred_status_with_status_fix(status, *args)
5
- return if defined?(@deferred_status) && ![:unknown, status].include?(@deferred_status)
6
- set_deferred_status_without_status_fix status, *args
7
- end
8
-
9
- alias_method :set_deferred_status_without_status_fix, :set_deferred_status
10
- alias_method :set_deferred_status, :set_deferred_status_with_status_fix
11
- end