emmy-http 0.1.0 → 0.1.1

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: db44189442e0a565ce17f51583a2bd6c9e590bab
4
- data.tar.gz: 3d4d37199263fa3acc5e7192061077cb5bc5fd60
3
+ metadata.gz: 39764e025c6870fb136cc4a884e6d64431c88095
4
+ data.tar.gz: 9562f899182119fcd519d6165e5357078e31a784
5
5
  SHA512:
6
- metadata.gz: 51ebd83234a5928d4bf406feab270487c34c38a39c79e0640ea0bb89c05fca91ab24e0869a3842e15c7735da58db0ef2ee1b0c953b38fc2c2b451da5903de285
7
- data.tar.gz: 5c7f1b066fb51714cc5ba4f7a5f24b7e96b23d3ffdc283120421a9e20434d5ed3e5cf9d8feac3111ca62b4cb6992185833236a5344c600d821ead166a063c509
6
+ metadata.gz: e9fe0b8a5b137b27d568d2b88d49b1627ff71cd4e70723fe78087ea50e8838ba960c1b9b5c3f7fd990e261a4bbbe116f3d4306af81f0972497d711e915cd5c85
7
+ data.tar.gz: 1c76bdc834cd662247b736b3c1d4001931c1a1e44f287840a9689226b717d2aee5b6bef59a421be8b77c2ba1edf8e46657a425a899a874a10d167a239c9c7ba8
data/emmy-http.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "emmy-machine", "~> 0.1"
22
- spec.add_dependency "fibre", "~> 0.9.1"
22
+ spec.add_dependency "fibre", "~> 0.9.3"
23
23
  spec.add_dependency "model_pack", "~> 0.9"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.6"
@@ -0,0 +1,15 @@
1
+ module EmmyHttp
2
+ class Backend
3
+ SUPPORTED_COMMANDS = %w(start stop restart)
4
+
5
+ def supported_commands
6
+ const_get(:SUPPORTED_COMMANDS)
7
+ end
8
+
9
+ SUPPORTED_COMMANDS.each do |method|
10
+ define_method method do
11
+ raise 'method not implemented'
12
+ end
13
+ end
14
+ end
15
+ end
@@ -26,8 +26,8 @@ module EmmyHttp
26
26
  # create connection
27
27
  connect
28
28
 
29
- on :success do |operation, conn|
30
- fiber.resume operation.response
29
+ on :success do |response, operation, conn|
30
+ fiber.resume response
31
31
  end
32
32
 
33
33
  on :error do |error, operation, conn|
@@ -60,7 +60,7 @@ module EmmyHttp
60
60
  response.headers = operation.adapter.headers
61
61
  end
62
62
 
63
- on :success do |operation, conn|
63
+ on :success do |response, operation, conn|
64
64
  response.status = operation.adapter.status
65
65
  response.body = operation.adapter.body
66
66
  end
@@ -3,11 +3,24 @@ module EmmyHttp
3
3
  include ModelPack::Document
4
4
 
5
5
  attribute :status
6
- dictionary :headers
6
+ dictionary :headers, writer: -> (head) { convert_headers(head) }
7
7
  attribute :body
8
8
 
9
9
  def to_a
10
10
  [status, headers, body]
11
11
  end
12
+
13
+ # CONTENT_TYPE becomes Content-Type
14
+ def convert_headers(headers)
15
+ {}.tap do |result|
16
+ headers.each do |k, v|
17
+ words = k.split("_")
18
+ key = words.map { |w| w.downcase.capitalize }.join("-")
19
+ result[key] = v
20
+ end
21
+ end
22
+ end
23
+
24
+ #<<<
12
25
  end
13
26
  end
@@ -0,0 +1,19 @@
1
+ module EmmyHttp
2
+ class Server::Options
3
+ include ModelPack::Document
4
+
5
+ attribute :chdir, default: Dir.pwd
6
+ attribute :environment, default: 'development'
7
+ atrribute :address, default: '0.0.0.0'
8
+ attribute :port, default: 3434
9
+ attribute :timeout, default: 30
10
+ attribute :pid, default: File.join(Dir.pwd, "tmp/pids/server.log")
11
+ attribute :log, default: File.join(Dir.pwd, "log/server.log")
12
+ attribute :max_conns, default: 1024
13
+ attribute :max_persistent_conns, default: 100
14
+ attribute :require default: []
15
+ attribute :wait default: 30
16
+ attribute :fiberpool_size, default: 20
17
+ attribute :daemonize, default: false
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module EmmyHttp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/emmy_http.rb CHANGED
@@ -3,6 +3,7 @@ require "emmy_http/version"
3
3
 
4
4
  module EmmyHttp
5
5
  class ConnectionError < StandardError; end
6
+ class TimeoutError < ConnectionError; end
6
7
 
7
8
  autoload :Adapter, "emmy_http/adapter"
8
9
  autoload :Timeouts, "emmy_http/request/timeouts"
@@ -25,7 +25,7 @@ describe EmmyHttp do
25
25
  end
26
26
 
27
27
  def headers
28
- {'Content-Type' => 'text/html'}
28
+ {'CONTENT_TYPE' => 'text/html'}
29
29
  end
30
30
 
31
31
  def body
@@ -43,7 +43,7 @@ describe EmmyHttp do
43
43
  # replace request with timer
44
44
  EventMachine.add_timer(0) do
45
45
  self.delegate.head!(delegate, conn)
46
- self.delegate.success!(delegate, conn)
46
+ self.delegate.success!(delegate.response, delegate, conn)
47
47
  end
48
48
  end
49
49
 
@@ -63,13 +63,16 @@ describe EmmyHttp do
63
63
  end
64
64
 
65
65
  it "should do http request with fake adapter" do
66
- request = EmmyHttp::Request.new(
67
- method: 'get',
68
- url: 'http://google.com'
69
- )
70
- operation = EmmyHttp::Operation.new(request, FakeAdapter.new)
71
- response = operation.sync
72
- EventMachine.stop
66
+ begin
67
+ request = EmmyHttp::Request.new(
68
+ method: 'get',
69
+ url: 'http://google.com'
70
+ )
71
+ operation = EmmyHttp::Operation.new(request, FakeAdapter.new)
72
+ response = operation.sync
73
+ ensure
74
+ EventMachine.stop
75
+ end
73
76
 
74
77
  expect(response.status).to be 200
75
78
  expect(response.headers).to include("Content-Type")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emmy-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - che
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-16 00:00:00.000000000 Z
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: emmy-machine
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.1
33
+ version: 0.9.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.1
40
+ version: 0.9.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: model_pack
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -109,11 +109,13 @@ files:
109
109
  - emmy-http.gemspec
110
110
  - lib/emmy_http.rb
111
111
  - lib/emmy_http/adapter.rb
112
+ - lib/emmy_http/backend.rb
112
113
  - lib/emmy_http/operation.rb
113
114
  - lib/emmy_http/request.rb
114
115
  - lib/emmy_http/request/ssl.rb
115
116
  - lib/emmy_http/request/timeouts.rb
116
117
  - lib/emmy_http/response.rb
118
+ - lib/emmy_http/server/options.rb
117
119
  - lib/emmy_http/version.rb
118
120
  - spec/emmy_http_spec.rb
119
121
  - spec/spec_helper.rb