/library/server/httpd/interface/httpd_application.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 142 lines · 105 code · 19 blank · 18 comment · 5 complexity · 8f38d0ed84e17c3da38661921d6e20c1 MD5 · raw file

  1. note
  2. description: "Summary description for {HTTPD_APPLICATION}."
  3. legal: "See notice at end of class."
  4. status: "See notice at end of class."
  5. date: "$Date$"
  6. revision: "$Revision$"
  7. deferred class
  8. HTTPD_APPLICATION
  9. feature -- Basic operation
  10. launch
  11. deferred
  12. end
  13. feature -- Execution
  14. call_execute (a_variables: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT)
  15. -- Call execute
  16. --| Note: you can redefine this feature, if you want to optimize
  17. --| as much as possible a very simple query
  18. --| without fetching GET, POST, ... data
  19. local
  20. rescued: BOOLEAN
  21. ctx: detachable like new_request_context
  22. do
  23. if not rescued then
  24. pre_execute
  25. ctx := new_request_context (a_variables, a_input, a_output)
  26. execute (ctx)
  27. post_execute (ctx)
  28. else
  29. rescue_execute (ctx, (create {EXCEPTION_MANAGER}).last_exception)
  30. end
  31. rescue
  32. rescued := True
  33. retry
  34. end
  35. pre_execute
  36. -- Operation processed before `execute'
  37. do
  38. end
  39. post_execute (ctx: detachable like new_request_context)
  40. -- Operation processed after `execute', or after `rescue_execute'
  41. do
  42. if ctx /= Void then
  43. ctx.recycle
  44. end
  45. end
  46. rescue_execute (ctx: detachable like new_request_context; e: detachable EXCEPTION)
  47. -- Operation processed after `execute', or on rescue
  48. do
  49. post_execute (ctx)
  50. end
  51. execute (ctx: like new_request_context)
  52. -- Execute the request
  53. deferred
  54. end
  55. feature {NONE} -- Context
  56. request_count: INTEGER
  57. -- Current request count
  58. deferred
  59. end
  60. new_request_context (a_vars: HASH_TABLE [STRING, STRING]; a_input: HTTPD_SERVER_INPUT; a_output: HTTPD_SERVER_OUTPUT): HTTPD_REQUEST_CONTEXT
  61. -- New httpd environment based on `a_vars' and `input'
  62. --| note: you can redefine this function to create your own
  63. --| descendant of HTTPD_REQUEST_CONTEXT , or even to reuse/recycle existing
  64. --| instance of HTTPD_REQUEST_CONTEXT
  65. do
  66. create Result.make (a_vars, a_input, a_output)
  67. end
  68. feature -- Output: helpers
  69. http_put_exception_trace (ctx: like new_request_context)
  70. -- Print exception trace is any
  71. do
  72. if attached (create {EXCEPTIONS}).exception_trace as l_trace then
  73. http_put_string ("Exception occurred%N", ctx)
  74. http_put_string ("<pre>" + l_trace + "</pre>", ctx)
  75. http_flush (ctx)
  76. end
  77. end
  78. http_put_file_content (fn: STRING; ctx: like new_request_context)
  79. -- Send the content of file `fn'
  80. local
  81. f: RAW_FILE
  82. o: like {HTTPD_REQUEST_CONTEXT}.output
  83. do
  84. create f.make (fn)
  85. if f.exists and then f.is_readable then
  86. o := ctx.output
  87. f.open_read
  88. from
  89. until
  90. f.exhausted
  91. loop
  92. f.read_stream (1024)
  93. o.put_string (f.last_string)
  94. end
  95. f.close
  96. end
  97. end
  98. http_put_header_line (s: STRING; ctx: like new_request_context)
  99. -- Send `s' to http client as header line
  100. do
  101. ctx.output.put_header_line (s)
  102. end
  103. http_put_string (s: STRING; ctx: like new_request_context)
  104. -- Send `s' to http client
  105. do
  106. ctx.output.put_string (s)
  107. end
  108. http_flush (ctx: like new_request_context)
  109. -- Flush the output to http client
  110. do
  111. ctx.output.flush
  112. end
  113. note
  114. copyright: "Copyright (c) 1984-2011, Eiffel Software and others"
  115. license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
  116. source: "[
  117. Eiffel Software
  118. 5949 Hollister Ave., Goleta, CA 93117 USA
  119. Telephone 805-685-1006, Fax 805-685-6869
  120. Website http://www.eiffel.com
  121. Customer support http://support.eiffel.com
  122. ]"
  123. end