/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

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