lib/net/http/server/requests.rb in net-http-server-0.1.0 vs lib/net/http/server/requests.rb in net-http-server-0.2.0

- old
+ new

@@ -22,33 +22,37 @@ # The raw HTTP Request or `nil` if the Request was malformed. # def read_request(stream) buffer = '' - request_line = stream.readline("\r\n") + begin + request_line = stream.readline("\r\n") - # the request line must contain 'HTTP/' - return unless request_line.include?('HTTP/') + # the request line must contain 'HTTP/' + return unless request_line.include?('HTTP/') - buffer << request_line + buffer << request_line - stream.each_line("\r\n") do |header| - buffer << header + stream.each_line("\r\n") do |header| + buffer << header - # a header line must contain a ':' character followed by - # linear-white-space (either ' ' or "\t"). - unless (header.include?(': ') || header.include?(":\t")) - # if this is not a header line, check if it is the end - # of the request - if header == "\r\n" - # end of the request - break - else - # invalid header line - return + # a header line must contain a ':' character followed by + # linear-white-space (either ' ' or "\t"). + unless (header.include?(': ') || header.include?(":\t")) + # if this is not a header line, check if it is the end + # of the request + if header == "\r\n" + # end of the request + break + else + # invalid header line + return + end end end + rescue IOError, SystemCallError + return end return buffer end @@ -90,11 +94,11 @@ headers = request[:headers] normalized_headers = {} unless headers.empty? headers.each do |header| - name = header[:name] - value = header[:value] + name = header[:name].to_s + value = header[:value].to_s if normalized_headers.has_key?(name) previous_value = normalized_headers[name] if previous_value.kind_of?(Array)