Class renaming for content_negotiation
Splitted SERVER_CONTENT_NEGOTIATION in 4 differents classes for each kind of negotiation Changed to use ITERABLE over LIST for supported variants arguments Factorized some code for http parameter parsing such as q=1.0;note="blabla" and so on Integrated within EWF
This commit is contained in:
@@ -63,7 +63,6 @@ feature {NONE} -- Initialization
|
||||
t: STRING_8
|
||||
i,n: INTEGER
|
||||
p: INTEGER
|
||||
cl: CELL [INTEGER]
|
||||
do
|
||||
-- Ignore starting space (should not be any)
|
||||
from
|
||||
@@ -79,15 +78,7 @@ feature {NONE} -- Initialization
|
||||
p := s.index_of (';', i)
|
||||
if p > 0 then
|
||||
t := s.substring (i, p - 1)
|
||||
from
|
||||
create cl.put (p)
|
||||
i := p + 1
|
||||
until
|
||||
i >= n
|
||||
loop
|
||||
add_parameter_from_string (s, i, cl)
|
||||
i := cl.item
|
||||
end
|
||||
create parameters.make_from_substring (s, p + 1, s.count)
|
||||
else
|
||||
t := s.substring (i, n)
|
||||
end
|
||||
@@ -116,7 +107,7 @@ feature {NONE} -- Initialization
|
||||
subtype := type
|
||||
end
|
||||
ensure
|
||||
not has_error implies (create {HTTP_CONTENT_TYPE}.make_from_string (string)).same_string (string)
|
||||
not has_error implies (create {HTTP_MEDIA_TYPE}.make_from_string (string)).same_string (string)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
@@ -149,7 +140,7 @@ feature -- Access
|
||||
end
|
||||
end
|
||||
|
||||
parameters: detachable HASH_TABLE [READABLE_STRING_8, READABLE_STRING_8]
|
||||
parameters: detachable HTTP_PARAMETER_TABLE
|
||||
-- Parameters
|
||||
|
||||
feature -- Conversion
|
||||
@@ -262,7 +253,7 @@ feature -- Element change
|
||||
-- Remove parameter named `a_name'
|
||||
do
|
||||
if attached parameters as plst then
|
||||
plst.prune (a_name)
|
||||
plst.remove (a_name)
|
||||
if plst.is_empty then
|
||||
parameters := Void
|
||||
end
|
||||
@@ -270,84 +261,6 @@ feature -- Element change
|
||||
internal_string := Void
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
add_parameter_from_string (s: READABLE_STRING_8; start_index: INTEGER; out_end_index: CELL [INTEGER])
|
||||
-- Add parameter from string " attribute=value "
|
||||
-- and put in `out_end_index' the index after found parameter.
|
||||
local
|
||||
n: INTEGER
|
||||
pn,pv: STRING_8
|
||||
i: INTEGER
|
||||
p, q: INTEGER
|
||||
err: BOOLEAN
|
||||
do
|
||||
n := s.count
|
||||
-- Skip spaces
|
||||
from
|
||||
i := start_index
|
||||
until
|
||||
i > n or not s[i].is_space
|
||||
loop
|
||||
i := i + 1
|
||||
end
|
||||
if s[i] = ';' then
|
||||
-- empty parameter
|
||||
out_end_index.replace (i + 1)
|
||||
elseif i < n then
|
||||
p := s.index_of ('=', i)
|
||||
if p > 0 then
|
||||
pn := s.substring (i, p - 1)
|
||||
if p >= n then
|
||||
pv := ""
|
||||
out_end_index.replace (n + 1)
|
||||
else
|
||||
if s[p+1] = '%"' then
|
||||
q := s.index_of ('%"', p + 2)
|
||||
if q > 0 then
|
||||
pv := s.substring (p + 2, q - 1)
|
||||
from
|
||||
i := q + 1
|
||||
until
|
||||
i > n or not s[i].is_space
|
||||
loop
|
||||
i := i + 1
|
||||
end
|
||||
if s[i] = ';' then
|
||||
i := i + 1
|
||||
end
|
||||
out_end_index.replace (i)
|
||||
else
|
||||
err := True
|
||||
pv := ""
|
||||
-- missing closing double quote.
|
||||
end
|
||||
else
|
||||
q := s.index_of (';', p + 1)
|
||||
if q = 0 then
|
||||
q := n + 1
|
||||
end
|
||||
pv := s.substring (p + 1, q - 1)
|
||||
out_end_index.replace (q + 1)
|
||||
end
|
||||
pv.right_adjust
|
||||
if not err then
|
||||
add_parameter (pn, pv)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- expecting: attribute "=" value
|
||||
err := True
|
||||
end
|
||||
end
|
||||
if err then
|
||||
out_end_index.replace (n + 1)
|
||||
end
|
||||
has_error := has_error or err
|
||||
ensure
|
||||
entry_processed: out_end_index.item > start_index
|
||||
end
|
||||
|
||||
feature {NONE} -- Internal
|
||||
|
||||
internal_string: detachable STRING_8
|
||||
|
||||
150
library/network/protocol/http/src/http_parameter_table.e
Normal file
150
library/network/protocol/http/src/http_parameter_table.e
Normal file
@@ -0,0 +1,150 @@
|
||||
note
|
||||
description: "[
|
||||
Table representing parameters of the form q=1.0;note="blabla";foo=bar
|
||||
]"
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
HTTP_PARAMETER_TABLE
|
||||
|
||||
inherit
|
||||
HASH_TABLE [READABLE_STRING_8, STRING_8]
|
||||
redefine
|
||||
empty_duplicate
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_from_string,
|
||||
make_from_substring
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_from_string (s: READABLE_STRING_8)
|
||||
-- Build table of parameters for `s'
|
||||
do
|
||||
make_from_substring (s, 1, s.count)
|
||||
end
|
||||
|
||||
make_from_substring (s: READABLE_STRING_8; a_start_index: INTEGER; a_end_index: INTEGER)
|
||||
-- Build table of parameters for `s.substring (a_start_index, a_end_index)'
|
||||
local
|
||||
cl: CELL [INTEGER]
|
||||
i: INTEGER
|
||||
do
|
||||
make (1)
|
||||
from
|
||||
i := a_start_index
|
||||
create cl.put (i)
|
||||
until
|
||||
i >= a_end_index
|
||||
loop
|
||||
force_substring (s, i, cl)
|
||||
i := cl.item
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_error: BOOLEAN
|
||||
-- Current has error?
|
||||
--| Mainly in relation with `make_from_string' and `force_substring'
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
force_substring (s: READABLE_STRING_8; start_index: INTEGER; out_end_index: CELL [INTEGER])
|
||||
-- Add parameter from string " attribute=value "
|
||||
-- and put in `out_end_index' the index after found parameter.
|
||||
local
|
||||
n: INTEGER
|
||||
pn,pv: STRING_8
|
||||
i: INTEGER
|
||||
p, q: INTEGER
|
||||
err: BOOLEAN
|
||||
do
|
||||
n := s.count
|
||||
-- Skip spaces
|
||||
from
|
||||
i := start_index
|
||||
until
|
||||
i > n or not s[i].is_space
|
||||
loop
|
||||
i := i + 1
|
||||
end
|
||||
if s[i] = ';' then
|
||||
-- empty parameter
|
||||
out_end_index.replace (i + 1)
|
||||
elseif i < n then
|
||||
p := s.index_of ('=', i)
|
||||
if p > 0 then
|
||||
pn := s.substring (i, p - 1)
|
||||
if p >= n then
|
||||
pv := ""
|
||||
out_end_index.replace (n + 1)
|
||||
else
|
||||
if s[p+1] = '%"' then
|
||||
q := s.index_of ('%"', p + 2)
|
||||
if q > 0 then
|
||||
pv := s.substring (p + 2, q - 1)
|
||||
from
|
||||
i := q + 1
|
||||
until
|
||||
i > n or not s[i].is_space
|
||||
loop
|
||||
i := i + 1
|
||||
end
|
||||
if s[i] = ';' then
|
||||
i := i + 1
|
||||
end
|
||||
out_end_index.replace (i)
|
||||
else
|
||||
err := True
|
||||
pv := ""
|
||||
-- missing closing double quote.
|
||||
end
|
||||
else
|
||||
q := s.index_of (';', p + 1)
|
||||
if q = 0 then
|
||||
q := n + 1
|
||||
end
|
||||
pv := s.substring (p + 1, q - 1)
|
||||
out_end_index.replace (q + 1)
|
||||
end
|
||||
pv.right_adjust
|
||||
if not err then
|
||||
force (pv, pn)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- expecting: attribute "=" value
|
||||
err := True
|
||||
end
|
||||
end
|
||||
if err then
|
||||
out_end_index.replace (n + 1)
|
||||
end
|
||||
has_error := has_error or err
|
||||
ensure
|
||||
entry_processed: out_end_index.item > start_index
|
||||
end
|
||||
|
||||
feature {NONE} -- Duplication
|
||||
|
||||
empty_duplicate (n: INTEGER): like Current
|
||||
-- Create an empty copy of Current that can accommodate `n' items
|
||||
do
|
||||
Result := Precursor (n)
|
||||
end
|
||||
|
||||
note
|
||||
copyright: "2011-2013, Jocelyn Fiat, 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
|
||||
Reference in New Issue
Block a user