Skip to content
Browse files

Fix wrong Content-Length with non ASCII-8BIT strings (closes #12)

  • Loading branch information...
1 parent c58f5b8 commit 4eca69d0583b5e271692907141733448b909120a @meh meh committed with tmm1 Nov 23, 2012
Showing with 9 additions and 13 deletions.
  1. +0 −1 eventmachine_httpserver.gemspec
  2. +9 −12 lib/evma_httpserver/response.rb
View
1 eventmachine_httpserver.gemspec
@@ -6,7 +6,6 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Francis Cianfrocca"]
- s.cert_chain = nil
s.date = %q{2007-03-16}
s.description = %q{}
s.email = %q{garbagecat10@gmail.com}
View
21 lib/evma_httpserver/response.rb
@@ -92,12 +92,16 @@ class HttpResponse
505 => "505 HTTP Version Not Supported"
}
- attr_accessor :status, :content, :headers, :chunks, :multiparts
+ attr_accessor :status, :headers, :chunks, :multiparts
def initialize
@headers = {}
end
+ def content=(value) @content = value.to_s end
+ def content() @content || '' end
+ def content?() !!@content end
+
def keep_connection_open arg=true
@keep_connection_open = arg
end
@@ -189,7 +193,7 @@ def generate_header_lines in_hash
#
def fixup_headers
if @content
- @headers["Content-Length"] = @content.to_s.length
+ @headers["Content-Length"] = @content.bytesize
elsif @chunks
@headers["Transfer-Encoding"] = "chunked"
# Might be nice to ENSURE there is no content-length header,
@@ -207,14 +211,11 @@ def fixup_headers
# DO NOT close the connection or send any goodbye kisses. This method can
# be called multiple times to send out chunks or multiparts.
def send_body
- if @content
- send_content
- elsif @chunks
+ if @chunks
send_chunks
elsif @multiparts
send_multiparts
else
- @content = ""
send_content
end
end
@@ -225,9 +226,7 @@ def send_body
#
def send_trailer
send_headers unless @sent_headers
- if @content
- # no-op
- elsif @chunks
+ if @chunks
unless @last_chunk_sent
chunk ""
send_chunks
@@ -238,15 +237,13 @@ def send_trailer
# supposed to interact with the case where we leave the connection
# open after transmitting the multipart response.
send_data "\r\n--#{@multipart_boundary}--\r\n\r\n"
- else
- # no-op
end
end
def send_content
raise "sent content already" if @sent_content
@sent_content = true
- send_data((@content || "").to_s)
+ send_data(content)
end
# add a chunk to go to the output.

0 comments on commit 4eca69d

Please sign in to comment.
Something went wrong with that request. Please try again.