Added HTTP_FILE_EXTENSION_MIME_MAPPING

Added REQUEST_FILE_SYSTEM_HANDLER to the router library
Added file system handler in "hello_routed_world" example
This commit is contained in:
Jocelyn Fiat
2011-10-14 14:13:40 +02:00
parent 4c36d75ef3
commit 1453873b6c
13 changed files with 2150 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all">
<option warning="true" full_class_checking="true" is_attached_by_default="true" void_safety="all" syntax="provisional">
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base-safe.ecf"/>

View File

@@ -7,7 +7,7 @@
<exclude>/EIFGENs$</exclude>
<exclude>/.svn$</exclude>
</file_rule>
<option warning="true" full_class_checking="true">
<option warning="true" full_class_checking="true" syntax="provisional">
<assertions precondition="true"/>
</option>
<library name="base" location="$ISE_LIBRARY\library\base\base.ecf"/>

View File

@@ -0,0 +1,240 @@
note
description: "[
Various common MIME types for file extensions
See also for longer list and description
http://www.webmaster-toolkit.com/mime-types.shtml
Please suggest missing entries
]"
date: "$Date$"
revision: "$Revision$"
class
HTTP_FILE_EXTENSION_MIME_MAPPING
inherit
ANY
HTTP_MIME_TYPES
export
{NONE} all
end
create
make_empty,
make_default,
make_from_string,
make_from_file
feature {NONE} -- Initialization
make_empty (n: INTEGER)
-- Create with no mapping
-- but one can use `map' to add new mapping
do
create mapping.make (n)
mapping.compare_objects
end
make_default
-- Create with default limited mapping
-- One can use `map' to add new mapping
local
m: like mapping
do
create m.make (40)
mapping := m
m.compare_objects
m.force (text_css, "css")
m.force (text_html, "html")
m.force (text_xml, "xml")
m.force (application_json, "json")
m.force (application_javascript, "js")
m.force (application_rss_xml, "rss")
m.force (application_atom_xml, "atom")
m.force (image_x_ico, "ico")
m.force (image_gif, "gif")
m.force (image_jpeg, "jpeg")
m.force (image_jpg, "jpg")
m.force (image_png, "png")
m.force (application_zip, "zip")
m.force (application_x_bzip, "bz")
m.force (application_x_bzip2, "bz2")
m.force (application_x_gzip, "gz")
m.force (application_x_gzip, "gzip")
m.force (application_x_tar, "tar")
m.force (application_x_compressed, "tgz")
m.force (application_postscript, "ps")
m.force (application_pdf, "pdf")
m.force (application_x_shockwave_flash, "swf")
m.force (text_plain, "conf")
m.force (text_plain, "log")
m.force (text_plain, "text")
m.force (text_plain, "txt")
end
make_from_file (fn: READABLE_STRING_8)
-- Create with mime.types file
-- One can use `map' to add new mapping
local
f: RAW_FILE
s: READABLE_STRING_8
do
create f.make (fn)
if f.exists and then f.is_readable then
make_empty (50)
f.open_read
from
f.read_line
until
f.exhausted or f.end_of_file
loop
add_mapping_line (f.last_string)
f.read_line
end
f.close
else
make_empty (0)
end
end
make_from_string (t: READABLE_STRING_8)
-- Set mapping from multiline string `t'
-- line should be formatted as in http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
--| # is a comment
--| mime-type space(s) extensions
local
i,j,n: INTEGER
do
make_empty (10)
n := t.count
if n > 0 then
from
i := 1
until
i = 0 or i > n
loop
j := t.index_of ('%N', i)
if j > 0 then
add_mapping_line (t.substring (i, j - 1))
i := j + 1
else
add_mapping_line (t.substring (i, n))
i := 0
end
end
end
end
feature -- Access
mime_type (ext: READABLE_STRING_8): detachable READABLE_STRING_8
-- Mime type for extension `ext'
do
Result := mapping.item (ext.as_lower)
end
feature -- Element change
map (e: READABLE_STRING_8; t: READABLE_STRING_8)
-- Add mapping extension `e' to mime type `t'
do
mapping.force (t, e.as_lower)
end
feature {NONE} -- Implementation
add_mapping_line (t: READABLE_STRING_8)
local
i,j,n: INTEGER
l_type, l_ext: READABLE_STRING_8
do
n := t.count
if n > 0 then
-- ignore blanks
i := next_non_blank_position (t, i)
if i > 0 then
if t[i] = '#' then
--| ignore
else
j := next_blank_position (t, i)
if j > i then
l_type := t.substring (i, j - 1)
from
until
i = 0
loop
i := next_non_blank_position (t, j)
if i > 0 then
j := next_blank_position (t, i)
if j = 0 then
l_ext := t.substring (i, n)
i := 0
else
l_ext := t.substring (i, j - 1)
i := j
end
map (l_ext, l_type)
end
end
end
end
end
end
end
next_blank_position (s: READABLE_STRING_8; p: INTEGER): INTEGER
local
i, n: INTEGER
do
n := s.count
from
i := p + 1
until
i > n or s[i].is_space
loop
i := i + 1
end
if i <= n then
Result := i
end
end
next_non_blank_position (s: READABLE_STRING_8; p: INTEGER): INTEGER
local
i, n: INTEGER
do
n := s.count
from
i := p + 1
until
i > n or not s[i].is_space
loop
i := i + 1
end
if i <= n then
Result := i
end
end
feature {NONE} -- Extension MIME mapping
mapping: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
invariant
mapping_keys_are_lowercase: across mapping as c all c.key.same_string (c.key.as_lower) end
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end

View File

@@ -19,11 +19,7 @@ feature -- Content type : application
application_atom_xml: STRING = "application/atom+xml"
-- atom application content-type header
application_x_www_form_encoded: STRING = "application/x-www-form-urlencoded"
-- Starting chars of form url-encoded data content-type header
application_octet_stream: STRING = "application/octet-stream"
-- Octet stream content-type header
application_force_download: STRING = "application/force-download"
application_javascript: STRING = "application/javascript"
-- JavaScript application content-type header
@@ -31,25 +27,54 @@ feature -- Content type : application
application_json: STRING = "application/json"
-- JSON application content-type header
application_octet_stream: STRING = "application/octet-stream"
-- Octet stream content-type header
application_pdf: STRING = "application/pdf"
-- pdf application content-type header
application_postscript: STRING = "application/postscript"
-- postscript application content-type header
application_rss_xml: STRING = "application/rss+xml"
-- rss application content-type header
application_rtf: STRING = "application/rtf"
-- RTF application content-type header
application_xml: STRING = "application/xml"
-- xml application content-type header
application_x_shockwave_flash: STRING = "application/x-shockwave-flash"
application_x_compressed: STRING = "application/x-compressed"
-- x-compressed application content-type header
application_x_gzip: STRING = "application/x-gzip"
application_zip: STRING = "application/zip"
-- ZIP application content-type header
application_x_bzip: STRING = "application/x-bzip"
application_x_bzip2: STRING = "application/x-bzip2"
application_x_tar: STRING = "application/x-tar"
application_x_www_form_encoded: STRING = "application/x-www-form-urlencoded"
-- Starting chars of form url-encoded data content-type header
feature -- Content type : audio
audio_mpeg3: STRING = "audio/mpeg3"
audio_mpeg: STRING = "audio/mpeg"
audio_wav: STRING = "audio/wav"
feature -- Content type : image
image_bmp: STRING = "image/bmp"
-- BMP image content-type header
image_gif: STRING = "image/gif"
-- GIF image content-type header
@@ -65,6 +90,12 @@ feature -- Content type : image
image_svg_xml: STRING = "image/svg+xml"
-- SVG+XML image content-type header
image_tiff: STRING = "image/tiff"
-- TIFF image content-type header
image_x_ico: STRING = "image/x-ico"
-- ICO image content-type header
feature -- Content type : message
message_http: STRING = "message/http"
@@ -81,6 +112,8 @@ feature -- Content type : message
feature -- Content type : model
model_vrml: STRING = "model/vrml"
feature -- Content type : multipart
multipart_mixed: STRING = "multipart/mixed"
@@ -95,6 +128,8 @@ feature -- Content type : multipart
multipart_encrypted: STRING = "multipart/encrypted"
multipart_x_gzip: STRING = "multipart/x-gzip"
feature -- Content type : text
text_css: STRING = "text/css"
@@ -119,13 +154,23 @@ feature -- Content type : text
text_rtf: STRING = "text/rtf"
-- rtf content-type header
text_tab_separated_values: STRING = "text/tab-separated-values"
-- TSV text content-type header
text_xml: STRING = "text/xml"
-- XML text content-type header
text_vcard: STRING = "text/vcard"
-- vcard text content-type header
feature -- Content type : video
feature -- Content type : video
video_avi: STRING = "video/avi"
video_quicktime: STRING = "video/quicktime"
video_x_motion_jpeg: STRING = "video/x-motion-jpeg"
note
copyright: "2011-2011, Eiffel Software and others"

View File

@@ -51,7 +51,7 @@ feature -- Methods intented for actions
method_delete: STRING = "DELETE"
-- Deletes the specified resource.
feature -- Other Methods
method_connect: STRING = "CONNECT"