Added class HTTP_CONTENT_TYPE to help manipulation of Content-Type value

Now WSF_REQUEST return a HTTP_CONTENT_TYPE if available
Adapted WSF_MIME_HANDLER to use this new class
Added one manual autotest to test MIME handler
This commit is contained in:
Jocelyn Fiat
2012-03-23 16:40:13 +01:00
parent ac9cbb0bd2
commit 40c6aff423
14 changed files with 741 additions and 72 deletions

View File

@@ -0,0 +1,118 @@
note
description: "[
Eiffel tests that can be executed by testing tool.
]"
author: "EiffelStudio test wizard"
date: "$Date$"
revision: "$Revision$"
testing: "type/manual"
class
TEST_WSF_REQUEST_MIME_HANDLER
inherit
EQA_TEST_SET
WSF_SERVICE
undefine
default_create
end
feature {NONE} -- Events
port_number: INTEGER
base_url: detachable STRING
feature -- Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
--| do nothing
end
feature -- Tests
test_mime_handler
local
req: WSF_REQUEST
b: STRING_8
h: WSF_HEADER
ct: HTTP_CONTENT_TYPE
m: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]
do
m := <<
["REQUEST_METHOD", "GET"],
["QUERY_STRING", ""],
["REQUEST_URI", "/auto/test/foo"],
["SCRIPT_NAME", "/auto/test/test.ews"],
["PATH_INFO", "/foo"]
>>
create ct.make_from_content_type_header ({HTTP_MIME_TYPES}.multipart_form_data)
ct.set_parameter ("boundary", "__=_the_boundary_1332296477_1804289383_=__")
create h.make
h.put_content_type (ct)
b := "[
--__=_the_boundary_1332296477_1804289383_=__
Content-Disposition: form-data; name="user_name"
EWFdemo
--__=_the_boundary_1332296477_1804289383_=__
Content-Disposition: form-data; name="password"
EWFpassword
--__=_the_boundary_1332296477_1804289383_=__--
]"
h.put_content_length (b.count)
--| Case #1
req := new_request (m, h.string, b)
assert ("found user_name", attached req.form_parameter ("user_name") as u and then u.same_string ("EWFdemo"))
assert ("found password", attached req.form_parameter ("password") as u and then u.same_string ("EWFpassword"))
end
feature {NONE} -- Implementation
new_request (a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]; h: READABLE_STRING_8; s: READABLE_STRING_8): WSF_REQUEST_NULL
local
wgi_req: WGI_REQUEST
l_header: WSF_HEADER
lst: ARRAYED_LIST [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]
vn: STRING_8
do
create lst.make (10)
across
a_meta as c
loop
lst.extend (c.item)
end
create l_header.make_from_raw_header_data (h)
across
l_header.to_name_value_iterable as c
loop
--| for Any Abc-Def-Ghi add (or replace) the HTTP_ABC_DEF_GHI variable to `env'
vn := c.item.name.as_upper
vn.replace_substring_all ("-", "_")
if
vn.starts_with ("CONTENT_") and then
(vn.same_string_general ({WGI_META_NAMES}.content_type) or vn.same_string_general ({WGI_META_NAMES}.content_length))
then
--| Keep this name
else
vn.prepend ("HTTP_")
end
lst.extend ([vn, c.item.value])
-- lst.extend (c.item)
end
create {WGI_REQUEST_NULL} wgi_req.make_with_body (lst, s)
create Result.make_from_wgi (wgi_req)
end
end

View File

@@ -81,7 +81,7 @@ feature {NONE} -- Implementation
local
wgi_req: WGI_REQUEST
do
create {WGI_REQUEST_NULL} wgi_req.make (a_meta)
create {WGI_REQUEST_NULL} wgi_req.make_with_file (a_meta, io.input)
create Result.make_from_wgi (wgi_req)
end

View File

@@ -14,19 +14,20 @@ inherit
end
create
make
make_with_file,
make_with_body
feature {NONE} -- Initialization
make (a_meta: ARRAY [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]])
make_with_file (a_meta: ITERABLE [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]; f: FILE)
local
ht: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
i: WGI_NULL_INPUT_STREAM
i: WGI_NULL_FILE_INPUT_STREAM
c: WGI_NULL_CONNECTOR
do
create c.make
create i.make
create ht.make (a_meta.count)
create i.make (f)
create ht.make (10)
across
a_meta as curs
loop
@@ -35,6 +36,22 @@ feature {NONE} -- Initialization
wgi_request_from_table_make (ht, i, c)
end
make_with_body (a_meta: ITERABLE [TUPLE [name: READABLE_STRING_8; value: READABLE_STRING_8]]; s: READABLE_STRING_8)
local
ht: HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
i: WGI_NULL_STRING_INPUT_STREAM
c: WGI_NULL_CONNECTOR
do
create c.make
create i.make (s)
create ht.make (10)
across
a_meta as curs
loop
ht.force (curs.item.value, curs.item.name)
end
wgi_request_from_table_make (ht, i, c)
end
note
copyright: "2011-2011, Eiffel Software and others"

View File

@@ -18,6 +18,7 @@
<library name="http_client" location="..\..\..\client\http_client\http_client-safe.ecf" readonly="false"/>
<library name="testing" location="$ISE_LIBRARY\library\testing\testing-safe.ecf"/>
<library name="thread" location="$ISE_LIBRARY\library\thread\thread-safe.ecf"/>
<library name="http" location="..\..\..\protocol\http\http-safe.ecf" readonly="false"/>
<library name="wsf" location="..\wsf-safe.ecf" readonly="false"/>
<tests name="src" location=".\src\" recursive="true"/>
</target>