Added alias "[]" to `item', to get header value for a header name.
Added assigner for `item' to make it easier to add header item without confusing key and value. Better parameter names (more explicit)
This commit is contained in:
@@ -83,20 +83,21 @@ feature -- Status report
|
|||||||
-- Has "Transfer-Encoding: chunked" header
|
-- Has "Transfer-Encoding: chunked" header
|
||||||
do
|
do
|
||||||
if has_header_named ({HTTP_HEADER_NAMES}.header_transfer_encoding) then
|
if has_header_named ({HTTP_HEADER_NAMES}.header_transfer_encoding) then
|
||||||
Result := attached header_named_value ({HTTP_HEADER_NAMES}.header_transfer_encoding) as v and then v.same_string (str_chunked)
|
Result := attached item ({HTTP_HEADER_NAMES}.header_transfer_encoding) as v and then v.same_string (str_chunked)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Access
|
feature -- Access
|
||||||
|
|
||||||
header_named_value (a_name: READABLE_STRING_8): detachable STRING_8
|
item alias "[]" (a_header_name: READABLE_STRING_8): detachable READABLE_STRING_8 assign force
|
||||||
-- First header item found for `a_name' if any
|
-- First header item found for `a_name' if any
|
||||||
local
|
local
|
||||||
|
res: STRING_8
|
||||||
n: INTEGER
|
n: INTEGER
|
||||||
l_line: READABLE_STRING_8
|
l_line: READABLE_STRING_8
|
||||||
ic: like new_cursor
|
ic: like new_cursor
|
||||||
do
|
do
|
||||||
n := a_name.count
|
n := a_header_name.count
|
||||||
|
|
||||||
from
|
from
|
||||||
ic := new_cursor
|
ic := new_cursor
|
||||||
@@ -104,49 +105,69 @@ feature -- Access
|
|||||||
ic.after or Result /= Void
|
ic.after or Result /= Void
|
||||||
loop
|
loop
|
||||||
l_line := ic.item
|
l_line := ic.item
|
||||||
if has_same_header_name (l_line, a_name) then
|
if has_same_header_name (l_line, a_header_name) then
|
||||||
Result := l_line.substring (n + 2, l_line.count)
|
res := l_line.substring (n + 2, l_line.count)
|
||||||
Result.left_adjust
|
res.left_adjust
|
||||||
Result.right_adjust
|
res.right_adjust
|
||||||
|
Result := res
|
||||||
end
|
end
|
||||||
ic.forth
|
ic.forth
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
header_named_value (a_name: READABLE_STRING_8): like item
|
||||||
|
-- First header item found for `a_name' if any
|
||||||
|
obsolete
|
||||||
|
"Use `item' [2014-03]"
|
||||||
|
do
|
||||||
|
Result := item (a_name)
|
||||||
|
end
|
||||||
|
|
||||||
feature -- Header change: general
|
feature -- Header change: general
|
||||||
|
|
||||||
add_header_key_value (k,v: READABLE_STRING_8)
|
force (a_value: detachable READABLE_STRING_8; a_header_name: READABLE_STRING_8)
|
||||||
-- Add header `k:v'.
|
-- Put header `a_header_name:a_value' or replace existing header of name `a_header_name'.
|
||||||
|
--| this is used as assigner for `item'
|
||||||
|
do
|
||||||
|
if a_value = Void then
|
||||||
|
put_header_key_value (a_header_name, "")
|
||||||
|
else
|
||||||
|
put_header_key_value (a_header_name, a_value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
add_header_key_value (a_header_name, a_value: READABLE_STRING_8)
|
||||||
|
-- Add header `a_header_name:a_value'.
|
||||||
-- If it already exists, there will be multiple header with same name
|
-- If it already exists, there will be multiple header with same name
|
||||||
-- which can also be valid
|
-- which can also be valid
|
||||||
local
|
local
|
||||||
s: STRING_8
|
s: STRING_8
|
||||||
do
|
do
|
||||||
create s.make (k.count + 2 + v.count)
|
create s.make (a_header_name.count + 2 + a_value.count)
|
||||||
s.append (k)
|
s.append (a_header_name)
|
||||||
s.append (colon_space)
|
s.append (colon_space)
|
||||||
s.append (v)
|
s.append (a_value)
|
||||||
add_header (s)
|
add_header (s)
|
||||||
ensure
|
ensure
|
||||||
added: has_header_named (k)
|
added: has_header_named (a_header_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_header_key_value (k,v: READABLE_STRING_8)
|
put_header_key_value (a_header_name, a_value: READABLE_STRING_8)
|
||||||
-- Add header `k:v', or replace existing header of same header name/key
|
-- Add header `a_header_name:a_value', or replace existing header of same header name/key
|
||||||
local
|
local
|
||||||
s: STRING_8
|
s: STRING_8
|
||||||
do
|
do
|
||||||
create s.make (k.count + 2 + v.count)
|
create s.make (a_header_name.count + 2 + a_value.count)
|
||||||
s.append (k)
|
s.append (a_header_name)
|
||||||
s.append (colon_space)
|
s.append (colon_space)
|
||||||
s.append (v)
|
s.append (a_value)
|
||||||
put_header (s)
|
put_header (s)
|
||||||
ensure
|
ensure
|
||||||
added: has_header_named (k)
|
added: has_header_named (a_header_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
put_header_key_values (k: READABLE_STRING_8; a_values: ITERABLE [READABLE_STRING_8]; a_separator: detachable READABLE_STRING_8)
|
put_header_key_values (a_header_name: READABLE_STRING_8; a_values: ITERABLE [READABLE_STRING_8]; a_separator: detachable READABLE_STRING_8)
|
||||||
-- Add header `k: a_values', or replace existing header of same header values/key.
|
-- Add header `a_header_name: a_values', or replace existing header of same header values/key.
|
||||||
-- Use `comma_space' as default separator if `a_separator' is Void or empty.
|
-- Use `comma_space' as default separator if `a_separator' is Void or empty.
|
||||||
local
|
local
|
||||||
s: STRING_8
|
s: STRING_8
|
||||||
@@ -167,10 +188,10 @@ feature -- Header change: general
|
|||||||
s.append (c.item)
|
s.append (c.item)
|
||||||
end
|
end
|
||||||
if not s.is_empty then
|
if not s.is_empty then
|
||||||
put_header_key_value (k, s)
|
put_header_key_value (a_header_name, s)
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
added: has_header_named (k)
|
added: has_header_named (a_header_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
feature -- Content related header
|
feature -- Content related header
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
note
|
note
|
||||||
description: "Summary description for {WSF_RESPONSE_HEADER}."
|
description: "[
|
||||||
author: ""
|
Interface to build the http header associated with WSF_RESPONSE.
|
||||||
|
]"
|
||||||
date: "$Date$"
|
date: "$Date$"
|
||||||
revision: "$Revision$"
|
revision: "$Revision$"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user