PageRenderTime 162ms CodeModel.GetById 141ms app.highlight 1ms RepoModel.GetById 19ms app.codeStats 0ms

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