emmy-extends 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/emmy-extends.gemspec +4 -4
- data/lib/emmy_extends/em_http_request/adapter.rb +43 -35
- data/lib/emmy_extends/version.rb +1 -1
- data/spec/em_http_request_spec.rb +2 -2
- metadata +7 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a3710c71f753f825f9b64bec852bc517d174f26
|
4
|
+
data.tar.gz: d849f5f3e4753900dd30a76647b7161729bd4373
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8dec14fbc285fe82e87924c1d26ca38d501e48e8cb7f40763b21ac18b65e7adba5b9a8595b9bbeb76bdd4a1647724e2f637900707771aba3134e34967e583c74
|
7
|
+
data.tar.gz: b41d0223c7801402509c2dd42258cb30f1d972f55e9909baeb47415922e55760d10a14df966b9f95a80996e484a1fe709c103e6d788cc765de7c39f0d91d64cc
|
data/Gemfile
CHANGED
data/emmy-extends.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'emmy_extends/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "emmy-extends"
|
8
8
|
spec.version = EmmyExtends::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["inre"]
|
10
|
+
spec.email = ["inre.storm@gmail.com"]
|
11
11
|
spec.summary = %q{Emmy support em-http-request, thin, savon, mysql2 etc.}
|
12
12
|
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
13
|
spec.homepage = ""
|
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "eventmachine", "~> 1.0.3"
|
21
|
+
#spec.add_dependency "eventmachine", "~> 1.0.3"
|
22
22
|
spec.add_dependency "emmy-machine", "~> 0.1.6"
|
23
|
-
spec.add_dependency "emmy-http", "~> 0.1.
|
23
|
+
spec.add_dependency "emmy-http", "~> 0.1.4"
|
24
24
|
|
25
25
|
spec.add_development_dependency "rspec", "~> 3"
|
26
26
|
spec.add_development_dependency "bundler", "~> 1.7"
|
@@ -1,11 +1,27 @@
|
|
1
|
+
using EventObject
|
2
|
+
|
1
3
|
module EmmyExtends
|
2
|
-
class EmHttpRequest::Adapter
|
3
|
-
|
4
|
+
class EmHttpRequest::Adapter
|
5
|
+
include EmmyHttp::Adapter
|
4
6
|
|
5
7
|
attr_reader :http_request
|
6
8
|
attr_reader :http_client
|
7
9
|
attr_reader :body
|
8
10
|
attr_reader :connection
|
11
|
+
attr_reader :operation
|
12
|
+
attr_reader :response
|
13
|
+
|
14
|
+
# required for adapter
|
15
|
+
|
16
|
+
def delegate=(operation)
|
17
|
+
@operation = operation
|
18
|
+
setup_http_request
|
19
|
+
setup_http_client
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_a
|
23
|
+
["tcp://#{operation.request.url.host}:#{operation.request.url.port}", EmmyMachine::Connection, method(:initialize_connection), self]
|
24
|
+
end
|
9
25
|
|
10
26
|
def initialize_connection(conn)
|
11
27
|
@connection = conn
|
@@ -32,20 +48,22 @@ module EmmyExtends
|
|
32
48
|
conn.comm_inactivity_timeout = http_request.connopts.inactivity_timeout
|
33
49
|
|
34
50
|
@body = ''
|
35
|
-
|
51
|
+
#operation.connection = conn # update connection handler
|
52
|
+
operation.init!(operation, conn)
|
36
53
|
|
37
54
|
rescue EventMachine::ConnectionError => e
|
38
55
|
EventMachine.next_tick { @http_client.close(e.message) }
|
39
|
-
|
56
|
+
operation.error!("connection error", self)
|
40
57
|
end
|
41
58
|
|
42
59
|
def connection_options
|
43
60
|
{
|
44
|
-
connect_timeout:
|
45
|
-
inactivity_timeout:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
61
|
+
connect_timeout: operation.request.timeouts.connect,
|
62
|
+
inactivity_timeout: operation.request.timeouts.inactivity,
|
63
|
+
ssl: (operation.request.ssl?) ? {
|
64
|
+
cert_chain_file: operation.request.ssl.cert_chain_file,
|
65
|
+
verify_peer: (operation.request.ssl.verify_peer == :peer),
|
66
|
+
ssl_version: operation.request.ssl.ssl_version
|
49
67
|
} : {}
|
50
68
|
}
|
51
69
|
end
|
@@ -54,15 +72,15 @@ module EmmyExtends
|
|
54
72
|
{
|
55
73
|
redirects: 5,
|
56
74
|
keepalive: false,
|
57
|
-
path:
|
58
|
-
query:
|
59
|
-
body: encode_body(
|
60
|
-
head:
|
75
|
+
path: operation.request.url.path,
|
76
|
+
query: operation.request.url.query,
|
77
|
+
body: encode_body(operation.request.body),
|
78
|
+
head: operation.request.headers
|
61
79
|
}
|
62
80
|
end
|
63
81
|
|
64
82
|
def encode_body(body)
|
65
|
-
return body if
|
83
|
+
return body if operation.request.headers["Content-Encoding"] != "gzip"
|
66
84
|
wio = StringIO.new("w")
|
67
85
|
begin
|
68
86
|
w_gz = Zlib::GzipWriter.new(wio)
|
@@ -73,50 +91,40 @@ module EmmyExtends
|
|
73
91
|
end
|
74
92
|
end
|
75
93
|
|
76
|
-
def setup
|
77
|
-
raise 'delegator must be set before' unless delegate
|
78
|
-
setup_http_request
|
79
|
-
setup_http_client
|
80
|
-
end
|
81
|
-
|
82
94
|
def setup_http_client
|
83
95
|
@http_client = begin
|
84
|
-
type =
|
85
|
-
http_client_options = HttpClientOptions.new(
|
96
|
+
type = operation.request.type.to_s.upcase # http method
|
97
|
+
http_client_options = HttpClientOptions.new(operation.request.url, request_options, type)
|
86
98
|
EventMachine::HttpClient.new(@http_request, http_client_options).tap do |client|
|
87
99
|
client.stream do |chunk|
|
88
100
|
@body << chunk
|
89
101
|
end
|
90
102
|
|
91
103
|
client.headers do |response_header|
|
92
|
-
|
104
|
+
@response = EmmyHttp::Response.new
|
105
|
+
response.headers = http_client.response_header
|
106
|
+
response.status = status
|
107
|
+
operation.head!(response, operation, connection)
|
93
108
|
end
|
94
109
|
|
95
110
|
client.callback do
|
96
111
|
if @http_client.response_header && @http_client.response_header.status.zero?
|
97
|
-
|
112
|
+
operation.error!("connection timed out", operation, connection)
|
98
113
|
else
|
99
|
-
|
114
|
+
response.body = body
|
115
|
+
operation.success!(response, operation, connection)
|
100
116
|
end
|
101
117
|
end
|
102
118
|
|
103
119
|
client.errback do |c|
|
104
|
-
|
120
|
+
operation.error!(client.error, operation, connection)
|
105
121
|
end
|
106
122
|
end
|
107
123
|
end
|
108
124
|
end
|
109
125
|
|
110
126
|
def setup_http_request
|
111
|
-
@http_request = EventMachine::HttpRequest.new(
|
112
|
-
end
|
113
|
-
|
114
|
-
def to_a
|
115
|
-
["tcp://#{delegate.request.url.host}:#{delegate.request.url.port}", EmmyMachine::Connection, method(:initialize_connection), self]
|
116
|
-
end
|
117
|
-
|
118
|
-
def headers
|
119
|
-
@http_client.response_header
|
127
|
+
@http_request = EventMachine::HttpRequest.new(operation.request.url, connection_options)
|
120
128
|
end
|
121
129
|
|
122
130
|
def status
|
data/lib/emmy_extends/version.rb
CHANGED
@@ -17,7 +17,7 @@ describe EmmyExtends::EmHttpRequest do
|
|
17
17
|
|
18
18
|
expect(response.status).to be 200
|
19
19
|
expect(response.headers).to include("Content-Type")
|
20
|
-
expect(response.headers["Server"]).to eq("
|
20
|
+
expect(response.headers["Server"]).to eq("nginx")
|
21
21
|
expect(response.body.empty?).to be false
|
22
22
|
end
|
23
23
|
|
@@ -32,7 +32,7 @@ describe EmmyExtends::EmHttpRequest do
|
|
32
32
|
expect(operation.to_a.first).to eq("tcp://httpbin.org:443")
|
33
33
|
expect(response.status).to be 200
|
34
34
|
expect(response.headers).to include("Content-Type")
|
35
|
-
expect(response.headers["Server"]).to eq("
|
35
|
+
expect(response.headers["Server"]).to eq("nginx")
|
36
36
|
expect(response.body.empty?).to be false
|
37
37
|
end
|
38
38
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emmy-extends
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- inre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: eventmachine
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.0.3
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.0.3
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: emmy-machine
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +30,14 @@ dependencies:
|
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.
|
33
|
+
version: 0.1.4
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.
|
40
|
+
version: 0.1.4
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: rspec
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,7 +82,7 @@ dependencies:
|
|
96
82
|
version: '10.0'
|
97
83
|
description:
|
98
84
|
email:
|
99
|
-
-
|
85
|
+
- inre.storm@gmail.com
|
100
86
|
executables: []
|
101
87
|
extensions: []
|
102
88
|
extra_rdoc_files: []
|
@@ -157,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
143
|
version: '0'
|
158
144
|
requirements: []
|
159
145
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.4.
|
146
|
+
rubygems_version: 2.4.3
|
161
147
|
signing_key:
|
162
148
|
specification_version: 4
|
163
149
|
summary: Emmy support em-http-request, thin, savon, mysql2 etc.
|