lib/phusion_passenger/abstract_request_handler.rb
def parse_http_request(socket)
		headers = {}
		
		data = ""
		while data !~ /\r\n\r\n/ && data.size < MAX_HEADER_SIZE
			data << socket.readpartial(16 * 1024)
		end
		if data.size >= MAX_HEADER_SIZE
			warn("*** Passenger RequestHandler warning: " <<
				"HTTP header size exceeded maximum.")
			return nil
		end
		
		data.gsub!(/\r\n\r\n.*/, '')
		data.split("\r\n").each_with_index do |line, i|
			if i == 0
				# GET / HTTP/1.1
				line =~ /^([A-Za-z]+) (.+?) (HTTP\/\d\.\d)$/
				request_method = $1
				request_uri    = $2
				protocol       = $3
				path_info, query_string    = request_uri.split("?", 2)
				headers[REQUEST_METHOD]    = request_method
				headers["REQUEST_URI"]     = request_uri
				headers["QUERY_STRING"]    = query_string || ""
				headers["SCRIPT_NAME"]     = ""
				headers["PATH_INFO"]       = path_info
				headers["SERVER_NAME"]     = "127.0.0.1"
				headers["SERVER_PORT"]     = socket.addr[1].to_s
				headers["SERVER_PROTOCOL"] = protocol
			else
				header, value = line.split(/\s*:\s*/, 2)
				header.upcase!            # "Foo-Bar" => "FOO-BAR"
				header.gsub!("-", "_")    #           => "FOO_BAR"
				if header == "CONTENT_LENGTH" || header == "CONTENT_TYPE"
					headers[header] = value
				else
					headers["HTTP_#{header}"] = value
				end
			end
		end
		
		if @connect_password && headers["HTTP_X_PASSENGER_CONNECT_PASSWORD"] != @connect_password
			warn "*** Passenger RequestHandler warning: " <<
				"someone tried to connect with an invalid connect password."
			return
		else
			return [headers, socket]
		end
	rescue EOFError
		return nil
	end
# Like parse_native_request, but parses an HTTP request. This is a very minimalistic
# HTTP parser and is not intended to be complete, fast or secure, since the HTTP server
# socket is intended to be used for debugging purposes only.
Like parse_native_request, but parses an HTTP request. This is a very minimalistic
HTTP parser and is not intended to be complete, fast or secure, since the HTTP server
socket is intended to be used for debugging purposes only.
Like parse_native_request but parses an HTTP request . This is a very minimalistic HTTP parser and is not intended to be complete fast or secure since the HTTP server socket is intended to be used for debugging purposes only .
def parse_http_request(socket)
		headers = {}
		data = ""
		while data !~ /\r\n\r\n/ && data.size < MAX_HEADER_SIZE
			data << socket.readpartial(16 * 1024)
		end
		if data.size >= MAX_HEADER_SIZE
			warn("*** Passenger RequestHandler warning: " <<
				"HTTP header size exceeded maximum.")
			return nil
		end
		data.gsub!(/\r\n\r\n.*/, '')
		data.split("\r\n").each_with_index do |line, i|
			if i == 0
				line =~ /^([A-Za-z]+) (.+?) (HTTP\/\d\.\d)$/
				request_method = $1
				request_uri    = $2
				protocol       = $3
				path_info, query_string    = request_uri.split("?", 2)
				headers[REQUEST_METHOD]    = request_method
				headers["REQUEST_URI"]     = request_uri
				headers["QUERY_STRING"]    = query_string || ""
				headers["SCRIPT_NAME"]     = ""
				headers["PATH_INFO"]       = path_info
				headers["SERVER_NAME"]     = "127.0.0.1"
				headers["SERVER_PORT"]     = socket.addr[1].to_s
				headers["SERVER_PROTOCOL"] = protocol
			else
				header, value = line.split(/\s*:\s*/, 2)
				header.upcase!            
				header.gsub!("-", "_")    
				if header == "CONTENT_LENGTH" || header == "CONTENT_TYPE"
					headers[header] = value
				else
					headers["HTTP_#{header}"] = value
				end
			end
		end
		if @connect_password && headers["HTTP_X_PASSENGER_CONNECT_PASSWORD"] != @connect_password
			warn "*** Passenger RequestHandler warning: " <<
				"someone tried to connect with an invalid connect password."
			return
		else
			return [headers, socket]
		end
	rescue EOFError
		return nil
	end
def parse_http_request ( socket ) headers = { } data = "" while data !~ / \r \n \r \n / && data . size < MAX_HEADER_SIZE data << socket . readpartial ( 16 * 1024 ) end if data . size >= MAX_HEADER_SIZE warn ( "*** Passenger RequestHandler warning: " << "HTTP header size exceeded maximum." ) return nil end data . gsub! ( / \r \n \r \n .* / , '' ) data . split ( "\r\n" ) . each_with_index do | line , i | if i == 0 line =~ / ^([A-Za-z]+) (.+?) (HTTP \/ \d \. \d )$ / request_method = $1 request_uri = $2 protocol = $3 path_info , query_string = request_uri . split ( "?" , 2 ) headers [ REQUEST_METHOD ] = request_method headers [ "REQUEST_URI" ] = request_uri headers [ "QUERY_STRING" ] = query_string || "" headers [ "SCRIPT_NAME" ] = "" headers [ "PATH_INFO" ] = path_info headers [ "SERVER_NAME" ] = "127.0.0.1" headers [ "SERVER_PORT" ] = socket . addr [ 1 ] . to_s headers [ "SERVER_PROTOCOL" ] = protocol else header , value = line . split ( / \s *: \s * / , 2 ) header . upcase! header . gsub! ( "-" , "_" ) if header == "CONTENT_LENGTH" || header == "CONTENT_TYPE" headers [ header ] = value else headers [ "HTTP_#{header}" ] = value end end end if @connect_password && headers [ "HTTP_X_PASSENGER_CONNECT_PASSWORD" ] != @connect_password warn "*** Passenger RequestHandler warning: " << "someone tried to connect with an invalid connect password." return else return [ headers , socket ] end rescue EOFError return nil end
Like parse_native_request, but parses an HTTP request.
Like parse_native_request but parses an HTTP request .
# GET / HTTP/1.1 # "Foo-Bar" => "FOO-BAR" #           => "FOO_BAR"
socket