Fixed MIME multipart form data handler

And use content-length value if provided.
This commit is contained in:
Jocelyn Fiat
2013-03-29 15:10:17 +01:00
parent 1fcc69b268
commit 1470389600
2 changed files with 48 additions and 21 deletions

View File

@@ -52,7 +52,7 @@ feature {NONE} -- Implementation: Form analyzer
require require
a_content_type_valid: a_content_type /= Void and not a_content_type.has_error a_content_type_valid: a_content_type /= Void and not a_content_type.has_error
s_attached: s /= Void s_attached: s /= Void
same_content_length: req.content_length_value = s.count same_content_length: req.content_length_value > 0 implies req.content_length_value.as_integer_32 = s.count
vars_attached: vars /= Void vars_attached: vars /= Void
local local
p,i,next_b: INTEGER p,i,next_b: INTEGER
@@ -93,17 +93,37 @@ feature {NONE} -- Implementation: Form analyzer
m := s.substring (i, next_b - 1 - 1) --| 1 = LF = %N m := s.substring (i, next_b - 1 - 1) --| 1 = LF = %N
end end
analyze_multipart_form_input (req, m, vars) analyze_multipart_form_input (req, m, vars)
if s.valid_index (next_b + l_boundary_len + 1) then
if is_crlf then
if s[next_b + l_boundary_len] = '%R' and s[next_b + l_boundary_len + 1] = '%N' then
-- continue
else
i := 0 -- reached the end
end
else
if s[next_b + l_boundary_len + 1] = '%N' then
-- continue
else
i := 0 -- reached the end
end
end
else
i := 0 -- missing end ?
req.error_handler.add_custom_error (0, "Invalid form data", "Invalid ending for form data from input")
end
if i > 0 then
i := next_b + l_boundary_len + 1 i := next_b + l_boundary_len + 1
if is_crlf then if is_crlf then
i := i + 1 --| +1 = CR = %R i := i + 1 --| +1 = CR = %R
end end
end
else else
if is_crlf then if is_crlf then
i := i + 1 i := i + 1
end end
m := s.substring (i - 1, s.count) m := s.substring (i - 1, s.count)
m.right_adjust m.right_adjust
if not l_boundary_prefix.same_string (m) then if i >= s.count and not l_boundary_prefix.same_string (m) then
req.error_handler.add_custom_error (0, "Invalid form data", "Invalid ending for form data from input") req.error_handler.add_custom_error (0, "Invalid form data", "Invalid ending for form data from input")
end end
i := next_b i := next_b

View File

@@ -11,15 +11,20 @@ feature {NONE} -- Implementation
full_input_data (req: WSF_REQUEST): READABLE_STRING_8 full_input_data (req: WSF_REQUEST): READABLE_STRING_8
do do
Result := read_input_data (req.input) Result := read_input_data (req.input, req.content_length_value)
end end
read_input_data (a_input: WGI_INPUT_STREAM): STRING_8 read_input_data (a_input: WGI_INPUT_STREAM; a_content_length: NATURAL_64): STRING_8
-- All data from input form -- All data from input form
local local
n: INTEGER n: INTEGER
t: STRING t: STRING
do do
if a_content_length > 0 then
create Result.make (a_content_length.as_integer_32)
n := a_input.read_to_string (Result, 1, Result.capacity)
check n = a_content_length end
else
from from
n := 8_192 n := 8_192
create Result.make (n) create Result.make (n)
@@ -37,6 +42,8 @@ feature {NONE} -- Implementation
Result.append_string (t) Result.append_string (t)
end end
end end
end
end end
add_string_value_to_table (a_name: READABLE_STRING_8; a_value: READABLE_STRING_8; a_table: HASH_TABLE [WSF_VALUE, READABLE_STRING_GENERAL]) add_string_value_to_table (a_name: READABLE_STRING_8; a_value: READABLE_STRING_8; a_table: HASH_TABLE [WSF_VALUE, READABLE_STRING_GENERAL])
@@ -146,7 +153,7 @@ feature {NONE} -- Implementation
end end
note note
copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others" copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Olivier Ligot, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[
Eiffel Software Eiffel Software