@@ -92,12 +92,16 @@ class HttpResponse
9292 505 => "505 HTTP Version Not Supported"
9393 }
9494
95- attr_accessor :status , :content , : headers, :chunks , :multiparts
95+ attr_accessor :status , :headers , :chunks , :multiparts
9696
9797 def initialize
9898 @headers = { }
9999 end
100100
101+ def content = ( value ) @content = value . to_s end
102+ def content ( ) @content || '' end
103+ def content? ( ) !!@content end
104+
101105 def keep_connection_open arg = true
102106 @keep_connection_open = arg
103107 end
@@ -189,7 +193,7 @@ def generate_header_lines in_hash
189193 #
190194 def fixup_headers
191195 if @content
192- @headers [ "Content-Length" ] = @content . to_s . length
196+ @headers [ "Content-Length" ] = @content . bytesize
193197 elsif @chunks
194198 @headers [ "Transfer-Encoding" ] = "chunked"
195199 # Might be nice to ENSURE there is no content-length header,
@@ -207,14 +211,11 @@ def fixup_headers
207211 # DO NOT close the connection or send any goodbye kisses. This method can
208212 # be called multiple times to send out chunks or multiparts.
209213 def send_body
210- if @content
211- send_content
212- elsif @chunks
214+ if @chunks
213215 send_chunks
214216 elsif @multiparts
215217 send_multiparts
216218 else
217- @content = ""
218219 send_content
219220 end
220221 end
@@ -225,9 +226,7 @@ def send_body
225226 #
226227 def send_trailer
227228 send_headers unless @sent_headers
228- if @content
229- # no-op
230- elsif @chunks
229+ if @chunks
231230 unless @last_chunk_sent
232231 chunk ""
233232 send_chunks
@@ -238,15 +237,13 @@ def send_trailer
238237 # supposed to interact with the case where we leave the connection
239238 # open after transmitting the multipart response.
240239 send_data "\r \n --#{ @multipart_boundary } --\r \n \r \n "
241- else
242- # no-op
243240 end
244241 end
245242
246243 def send_content
247244 raise "sent content already" if @sent_content
248245 @sent_content = true
249- send_data ( ( @ content || "" ) . to_s )
246+ send_data ( content )
250247 end
251248
252249 # add a chunk to go to the output.
0 commit comments