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 +1 -3
- data/lib/hatetepe/body.rb +5 -3
- data/lib/hatetepe/request.rb +0 -1
- data/lib/hatetepe/server.rb +15 -8
- data/lib/hatetepe/version.rb +1 -1
- data/spec/unit/body_spec.rb +16 -0
- data/spec/unit/server_spec.rb +3 -2
- metadata +2 -3
- data/lib/hatetepe/deferred_status_fix.rb +0 -11
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 [
|
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.
|
data/lib/hatetepe/request.rb
CHANGED
data/lib/hatetepe/server.rb
CHANGED
@@ -14,7 +14,10 @@ module Hatetepe::Server
|
|
14
14
|
|
15
15
|
attr_reader :config, :requests
|
16
16
|
|
17
|
-
CONFIG_DEFAULTS = {
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
|
57
|
+
puts [ex.message, *ex.backtrace].join("\n\t")
|
51
58
|
close_connection
|
52
59
|
end
|
53
60
|
|
data/lib/hatetepe/version.rb
CHANGED
data/spec/unit/body_spec.rb
CHANGED
@@ -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
|
data/spec/unit/server_spec.rb
CHANGED
@@ -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 =>
|
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
|
-
|
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.
|
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-
|
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
|