PageRenderTime 83ms CodeModel.GetById 79ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/library/server/httpd_connector/nino/src/httpd_nino_handler.e

http://github.com/jocelyn/EiffelWebReloaded
Specman e | 128 lines | 101 code | 21 blank | 6 comment | 7 complexity | ae41b00e62b552741b1d6a8aed6a646d MD5 | raw file
  1note
  2	description : "Objects that ..."
  3	author      : "$Author$"
  4	date        : "$Date$"
  5	revision    : "$Revision$"
  6
  7class
  8	HTTPD_NINO_HANDLER
  9
 10inherit
 11	HTTP_CONNECTION_HANDLER
 12
 13create
 14	make_with_callback
 15
 16feature {NONE} -- Initialization
 17
 18	make_with_callback (a_main_server: like main_server; a_name: STRING; a_callback: HTTPD_NINO_APPLICATION)
 19			-- Initialize `Current'.
 20		do
 21			make (a_main_server, a_name)
 22			callback := a_callback
 23		end
 24
 25	callback: HTTPD_NINO_APPLICATION
 26
 27feature -- Request processing
 28
 29	process_request (a_handler: HTTP_CONNECTION_HANDLER; a_input: HTTP_INPUT_STREAM; a_output: HTTP_OUTPUT_STREAM)
 30			-- Process request ...
 31		local
 32			env, vars: HASH_TABLE [STRING, STRING]
 33			p: INTEGER
 34			l_request_uri, l_script_name, l_query_string: STRING
 35			l_server_name, l_server_port: detachable STRING
 36			a_headers_map: HASH_TABLE [STRING, STRING]
 37
 38			e: EXECUTION_ENVIRONMENT
 39		do
 40			l_request_uri := a_handler.uri
 41			a_headers_map := a_handler.request_header_map
 42			create e
 43			vars := e.starting_environment_variables
 44			env := vars.twin
 45
 46			p := l_request_uri.index_of ('?', 1)
 47			if p > 0 then
 48				l_script_name := l_request_uri.substring (1, p - 1)
 49				l_query_string := l_request_uri.substring (p + 1, l_request_uri.count)
 50			else
 51				l_script_name := l_request_uri.string
 52				l_query_string := ""
 53			end
 54			if attached a_headers_map.item ("Host") as l_host then
 55				add_environment_variable (l_host, "HTTP_HOST", env)
 56				p := l_host.index_of (':', 1)
 57				if p > 0 then
 58					l_server_name := l_host.substring (1, p - 1)
 59					l_server_port := l_host.substring (p+1, l_host.count)
 60				else
 61					l_server_name := l_host
 62					l_server_port := "80" -- Default
 63				end
 64			end
 65
 66			add_environment_variable (a_headers_map.item ("User-Agent"), "HTTP_USER_AGENT", env)
 67			add_environment_variable (a_headers_map.item ("Accept"), "HTTP_ACCEPT", env)
 68			add_environment_variable (a_headers_map.item ("Accept-Language"), "HTTP_ACCEPT_LANGUAGE", env)
 69			add_environment_variable (a_headers_map.item ("Accept-Encoding"), "HTTP_ACCEPT_ENCODING", env)
 70			add_environment_variable (a_headers_map.item ("Accept-Charset"), "HTTP_ACCEPT_CHARSET", env)
 71			add_environment_variable (a_headers_map.item ("Connection"), "HTTP_CONNECTION", env)
 72			add_environment_variable (a_headers_map.item ("Referer"), "HTTP_REFERER", env)
 73
 74			if attached a_headers_map.item ("Authorization") as l_authorization then
 75				add_environment_variable (l_authorization, "HTTP_AUTHORIZATION", env)
 76				p := l_authorization.index_of (' ', 1)
 77				if p > 0 then
 78					add_environment_variable (l_authorization.substring (1, p - 1), "AUTH_TYPE", env)
 79				end
 80			end
 81
 82			add_environment_variable (a_headers_map.item ("Content-Length"), "CONTENT_LENGTH", env)
 83			add_environment_variable (a_headers_map.item ("Content-Type"), "CONTENT_TYPE", env)
 84
 85			add_environment_variable ("CGI/1.1", "GATEWAY_INTERFACE", env)
 86--			add_environment_variable (Void, "PATH_INFO", env)
 87--			add_environment_variable (Void, "PATH_TRANSLATED", env)
 88
 89			add_environment_variable (l_query_string, "QUERY_STRING", env)
 90
 91			if attached a_handler.remote_info as l_remote_info then
 92				add_environment_variable (l_remote_info.addr, "REMOTE_ADDR", env)
 93				add_environment_variable (l_remote_info.hostname, "REMOTE_HOST", env)
 94				add_environment_variable (l_remote_info.port.out, "REMOTE_PORT", env)
 95--				add_environment_variable (Void, "REMOTE_IDENT", env)
 96--				add_environment_variable (Void, "REMOTE_USER", env)			
 97			end
 98
 99			add_environment_variable (l_request_uri, "REQUEST_URI", env)
100			add_environment_variable (a_handler.method, "REQUEST_METHOD", env)
101
102			add_environment_variable (l_script_name, "SCRIPT_NAME", env)
103			add_environment_variable (l_server_name, "SERVER_NAME", env)
104			add_environment_variable (l_server_port, "SERVER_PORT", env)
105			add_environment_variable (a_handler.version, "SERVER_PROTOCOL", env)
106			add_environment_variable ({HTTP_SERVER_CONFIGURATION}.Server_details, "SERVER_SOFTWARE", env)
107
108			callback.process_request (env, a_handler.request_header, a_input, a_output)
109		end
110
111	add_environment_variable (a_value: detachable STRING; a_var_name: STRING; env: HASH_TABLE [STRING, STRING])
112		do
113			if a_value /= Void then
114				env.force (a_value, a_var_name)
115			end
116		end
117
118note
119	copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
120	license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
121	source: "[
122			Eiffel Software
123			5949 Hollister Ave., Goleta, CA 93117 USA
124			Telephone 805-685-1006, Fax 805-685-6869
125			Website http://www.eiffel.com
126			Customer support http://support.eiffel.com
127		]"
128end