/library/server/httpd/interface/response/httpd_file_response.e

http://github.com/jocelyn/EiffelWebReloaded · Specman e · 68 lines · 51 code · 15 blank · 2 comment · 1 complexity · d3a90dc7f3f306bf5154c353a7af85ba MD5 · raw file

  1. note
  2. description: "Summary description for {HTTPD_FILE_RESPONSE}."
  3. date: "$Date$"
  4. revision: "$Revision$"
  5. class
  6. HTTPD_FILE_RESPONSE
  7. inherit
  8. HTTPD_RESPONSE
  9. redefine
  10. send
  11. end
  12. HTTP_FILE_SYSTEM_UTILITIES
  13. create
  14. make
  15. feature {NONE} -- Initialization
  16. make (a_filename: STRING)
  17. do
  18. file_name := a_filename
  19. base_name := basename (a_filename)
  20. initialize
  21. prepare
  22. end
  23. prepare
  24. local
  25. h: like headers
  26. bfn: STRING
  27. do
  28. h := headers
  29. bfn := base_name
  30. h.put_content_type_with_name (content_type_by_extension (file_extension (bfn)), bfn)
  31. h.put_content_transfer_encoding ("binary")
  32. h.put_content_length (filesize (file_name))
  33. h.put_content_disposition ("attachment", "filename=%""+ bfn +"%"")
  34. h.put_expires (0)
  35. h.put_cache_control ("no-cache, must-revalidate")
  36. h.put_pragma_no_cache
  37. end
  38. feature -- Access
  39. file_name: STRING
  40. base_name: STRING
  41. feature -- Query
  42. string: STRING
  43. -- String representation of the response
  44. do
  45. Result := headers.string
  46. --TODO append the file's content ...
  47. end
  48. send (output: HTTPD_SERVER_OUTPUT)
  49. do
  50. output.put_string (headers.string)
  51. output.put_file_content (file_name)
  52. end
  53. end