Class: Webmachine::Adapters::Reel
Instance Attribute Summary
#configuration, #dispatcher
Instance Method Summary
collapse
#initialize, run
Instance Method Details
#fixup_callable_encoder(response) ⇒ Object
106
107
108
109
110
|
# File 'lib/webmachine/adapters/reel.rb', line 106
def fixup_callable_encoder(response)
if response.body.is_a?(Streaming::CallableEncoder)
response.body = [response.body.call]
end
end
|
98
99
100
101
102
103
104
|
# File 'lib/webmachine/adapters/reel.rb', line 98
def (response)
response..each do |key, value|
if value.is_a?(Array)
response.[key] = value.join(", ")
end
end
end
|
#process(connection) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/webmachine/adapters/reel.rb', line 36
def process(connection)
while request = connection.request
if request.is_a? ::Reel::WebSocket
if handler = @options[:websocket_handler]
handler.call(request)
else
request.respond :bad_request, "WebSockets not supported"
end
next
end
if @extra_verbs.include?(request.method)
method = "POST"
param = "_method=#{request.method}"
uri = request_uri(request.url, request., param)
else
method = request.method
uri = request_uri(request.url, request.)
end
= Webmachine::Headers[request..dup]
wm_request = Webmachine::Request.new(method, uri, ,
LazyRequestBody.new(request))
wm_response = Webmachine::Response.new
@dispatcher.dispatch(wm_request, wm_response)
(wm_response)
fixup_callable_encoder(wm_response)
request.respond ::Reel::Response.new(wm_response.code,
wm_response.,
wm_response.body)
end
end
|
#request_uri(path, headers, extra_query_params = nil) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/webmachine/adapters/reel.rb', line 78
def request_uri(path, , = nil)
host_parts = .fetch('Host').split(':')
path_parts = path.split('?')
uri_hash = {host: host_parts.first, path: path_parts.first}
uri_hash[:port] = host_parts.last.to_i if host_parts.length == 2
uri_hash[:query] = path_parts.last if path_parts.length == 2
if
if uri_hash[:query]
uri_hash[:query] << "&#{}"
else
uri_hash[:query] =
end
end
URI::HTTP.build(uri_hash)
end
|
#run ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/webmachine/adapters/reel.rb', line 13
def run
@options = {
:port => configuration.port,
:host => configuration.ip
}.merge(configuration.adapter_options)
if = configuration.adapter_options[:extra_verbs]
@extra_verbs = Set.new(.map(&:to_s).map(&:upcase))
else
@extra_verbs = Set.new
end
@server = ::Reel::Server.supervise(@options[:host], @options[:port], &method(:process))
trap("INT") { @server.terminate; exit 0 }
Celluloid::Actor.join(@server)
end
|
#shutdown ⇒ Object
32
33
34
|
# File 'lib/webmachine/adapters/reel.rb', line 32
def shutdown
@server.terminate! if @server
end
|