35
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/never_block/servers/mongrel.rb', line 35
def receive_data data
@linebuffer << data
@nparsed = @parser.execute(@params, @linebuffer, @nparsed) unless @parser.finished?
if @parser.finished?
if @request_len.nil?
@request_len = @params[::Mongrel::Const::CONTENT_LENGTH].to_i
script_name, path_info, handlers = ::Mongrel::HttpServer::Instance.classifier.resolve(@params[::Mongrel::Const::REQUEST_PATH])
if handlers
@params[::Mongrel::Const::PATH_INFO] = path_info
@params[::Mongrel::Const::SCRIPT_NAME] = script_name
@params[::Mongrel::Const::REMOTE_ADDR] = @params[::Mongrel::Const::HTTP_X_FORWARDED_FOR] || ::Socket.unpack_sockaddr_in(get_peername)[1]
@notifiers = handlers.select { |h| h.request_notify }
end
if @request_len > ::Mongrel::Const::MAX_BODY
new_buffer = Tempfile.new(::Mongrel::Const::MONGREL_TMP_BASE)
new_buffer.binmode
new_buffer << @linebuffer[@nparsed..-1]
@linebuffer = new_buffer
else
@linebuffer = StringIO.new(@linebuffer[@nparsed..-1])
@linebuffer.pos = @linebuffer.length
end
end
if @linebuffer.length >= @request_len
@linebuffer.rewind
::Mongrel::HttpServer::Instance.process_http_request(@params,@linebuffer,self)
@linebuffer.delete if Tempfile === @linebuffer
end
elsif @linebuffer.length > ::Mongrel::Const::MAX_HEADER
close_connection
raise ::Mongrel::HttpParserError.new("HEADER is longer than allowed, aborting client early.")
end
rescue ::Mongrel::HttpParserError
if $mongrel_debug_client
STDERR.puts "#{Time.now}: BAD CLIENT (#{params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last}): #$!"
STDERR.puts "#{Time.now}: REQUEST DATA: #{data.inspect}\n---\nPARAMS: #{params.inspect}\n---\n"
end
close_connection
rescue Exception => e
close_connection
raise e
end
|