15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/packet_mongrel.rb', line 15
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] @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
|