@@ -47,9 +47,9 @@ class Rack < Adapter
4747 # Start the Rack adapter
4848 def run
4949 options = DEFAULT_OPTIONS . merge ( {
50- : app => self ,
51- : Port => application . configuration . port ,
52- : Host => application . configuration . ip
50+ app : self ,
51+ Port : application . configuration . port ,
52+ Host : application . configuration . ip
5353 } ) . merge ( application . configuration . adapter_options )
5454
5555 @server = ::Rack ::Server . new ( options )
@@ -69,33 +69,34 @@ def call(env)
6969
7070 response . headers [ SERVER ] = VERSION_STRING
7171
72- rack_status = response . code
72+ rack_status = response . code
7373 rack_headers = response . headers . flattened ( NEWLINE )
7474 rack_body = case response . body
75- when String # Strings are enumerable in ruby 1.8
76- [ response . body ]
77- else
78- if ( io_body = IO . try_convert ( response . body ) )
79- io_body
80- elsif response . body . respond_to? ( :call )
81- Webmachine ::ChunkedBody . new ( Array ( response . body . call ) )
82- elsif response . body . respond_to? ( :each )
83- # This might be an IOEncoder with a Content-Length, which shouldn't be chunked.
84- if response . headers [ TRANSFER_ENCODING ] == " chunked"
85- Webmachine ::ChunkedBody . new ( response . body )
86- else
87- response . body
88- end
89- else
90- [ response . body . to_s ]
91- end
92- end
75+ when String # Strings are enumerable in ruby 1.8
76+ [ response . body ]
77+ else
78+ if ( io_body = IO . try_convert ( response . body ) )
79+ io_body
80+ elsif response . body . respond_to? ( :call )
81+ Webmachine ::ChunkedBody . new ( Array ( response . body . call ) )
82+ elsif response . body . respond_to? ( :each )
83+ # This might be an IOEncoder with a Content-Length, which shouldn't be chunked.
84+ if response . headers [ TRANSFER_ENCODING ] == ' chunked'
85+ Webmachine ::ChunkedBody . new ( response . body )
86+ else
87+ response . body
88+ end
89+ else
90+ [ response . body . to_s ]
91+ end
92+ end
9393
9494 rack_res = RackResponse . new ( rack_body , rack_status , rack_headers )
9595 rack_res . finish
9696 end
9797
9898 protected
99+
99100 def routing_tokens ( rack_req )
100101 nil # no-op for default, un-mapped rack adapter
101102 end
@@ -105,15 +106,15 @@ def base_uri(rack_req)
105106 end
106107
107108 private
109+
108110 def build_webmachine_request ( rack_req , headers )
109111 RackRequest . new ( rack_req . request_method ,
110- rack_req . url ,
111- headers ,
112- RequestBody . new ( rack_req ) ,
113- routing_tokens ( rack_req ) ,
114- base_uri ( rack_req ) ,
115- rack_req . env
116- )
112+ rack_req . url ,
113+ headers ,
114+ RequestBody . new ( rack_req ) ,
115+ routing_tokens ( rack_req ) ,
116+ base_uri ( rack_req ) ,
117+ rack_req . env )
117118 end
118119
119120 class RackRequest < Webmachine ::Request
@@ -129,14 +130,14 @@ class RackResponse
129130 ONE_FIVE = '1.5' . freeze
130131
131132 def initialize ( body , status , headers )
132- @body = body
133- @status = status
133+ @body = body
134+ @status = status
134135 @headers = headers
135136 end
136137
137138 def finish
138139 @headers [ CONTENT_TYPE ] ||= TEXT_HTML if rack_release_enforcing_content_type
139- @headers . delete ( CONTENT_TYPE ) if response_without_body
140+ @headers . delete ( CONTENT_TYPE ) if response_without_body
140141 [ @status , @headers , @body ]
141142 end
142143
@@ -188,10 +189,13 @@ def to_s
188189 # @yieldparam [String] chunk a chunk of the request body
189190 def each
190191 if @value
191- @value . each { |chunk | yield chunk }
192+ @value . each { |chunk | yield chunk }
192193 else
193194 @value = [ ]
194- @request . body . each { |chunk | @value << chunk ; yield chunk }
195+ @request . body . each { |chunk |
196+ @value << chunk
197+ yield chunk
198+ }
195199 end
196200 end
197201 end # class RequestBody
0 commit comments