PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/tutorial/net/papoose_connection.e

http://github.com/tybor/Liberty
Specman e | 69 lines | 56 code | 8 blank | 5 comment | 4 complexity | 589cd00c4c5f8d315a39e25f72618441 MD5 | raw file
 1class PAPOOSE_CONNECTION
 2	--
 3	-- Handle one connection to the HTTP_SERVER. The method handlers are defined here.
 4	--
 5
 6inherit
 7	HTTP_CONNECTION
 8
 9creation {ANY}
10	make
11
12feature {}
13	method_handler_factory: FUNCTION[TUPLE[STRING, STRING, STRING, OUTPUT_STREAM], HTTP_METHOD_HANDLER]
14			-- The first argument is the method, the second is the URI, the third is the version; the fourth is
15			-- the output stream to the client socket
16
17	make (a_method_handler_factory: like method_handler_factory) is
18		do
19			method_handler_factory := a_method_handler_factory
20			create request_line.make_empty
21		end
22
23feature {} -- method handlers reuse
24	method_handlers: DICTIONARY[FAST_ARRAY[HTTP_METHOD_HANDLER], STRING] is
25		once
26			create {HASHED_DICTIONARY[FAST_ARRAY[HTTP_METHOD_HANDLER], STRING]} Result.make
27		end
28
29	no_method_handlers: FAST_ARRAY[HTTP_NO_METHOD_HANDLER] is
30		once
31			create Result.make(0)
32		end
33
34	get_method_handler (method, uri, version: STRING): HTTP_METHOD_HANDLER is
35		local
36			mh: FAST_ARRAY[HTTP_METHOD_HANDLER]
37			get: HTTP_GET_HANDLER
38			nop: HTTP_NO_METHOD_HANDLER
39		do
40			mh := method_handlers.reference_at(method)
41			if mh /= Void and then not mh.is_empty then
42				get ::= mh.last
43				mh.remove_last
44				get.make(method, uri, version)
45				Result := get
46			else
47				if method_handler_factory /= Void then
48					Result := method_handler_factory.item([method, uri, version, ios])
49				end
50				if Result = Void then
51					inspect
52						method
53					when "GET", "POST" then
54						create {HTTP_GET_HANDLER} Result.make(method, uri, version)
55					else
56						if no_method_handlers.is_empty then
57							create nop.make(uri, version)
58						else
59							nop := no_method_handlers.last
60							no_method_handlers.remove_last
61							nop.make(uri, version)
62						end
63						Result := nop
64					end
65				end
66			end
67		end
68
69end -- class PAPOOSE_CONNECTION