Skip to content

Commit da92d2d

Browse files
committed
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)
1 parent ae0ba66 commit da92d2d

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

library/network/protocol/http/src/http_header_builder.e

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -83,70 +83,91 @@ feature -- Status report
8383
-- Has "Transfer-Encoding: chunked" header
8484
do
8585
if has_header_named ({HTTP_HEADER_NAMES}.header_transfer_encoding) then
86-
Result := attached header_named_value ({HTTP_HEADER_NAMES}.header_transfer_encoding) as v and then v.same_string (str_chunked)
86+
Result := attached item ({HTTP_HEADER_NAMES}.header_transfer_encoding) as v and then v.same_string (str_chunked)
8787
end
8888
end
8989

9090
feature -- Access
9191

92-
header_named_value (a_name: READABLE_STRING_8): detachable STRING_8
92+
item alias "[]" (a_header_name: READABLE_STRING_8): detachable READABLE_STRING_8 assign force
9393
-- First header item found for `a_name' if any
9494
local
95+
res: STRING_8
9596
n: INTEGER
9697
l_line: READABLE_STRING_8
9798
ic: like new_cursor
9899
do
99-
n := a_name.count
100+
n := a_header_name.count
100101

101102
from
102103
ic := new_cursor
103104
until
104105
ic.after or Result /= Void
105106
loop
106107
l_line := ic.item
107-
if has_same_header_name (l_line, a_name) then
108-
Result := l_line.substring (n + 2, l_line.count)
109-
Result.left_adjust
110-
Result.right_adjust
108+
if has_same_header_name (l_line, a_header_name) then
109+
res := l_line.substring (n + 2, l_line.count)
110+
res.left_adjust
111+
res.right_adjust
112+
Result := res
111113
end
112114
ic.forth
113115
end
114116
end
115117

118+
header_named_value (a_name: READABLE_STRING_8): like item
119+
-- First header item found for `a_name' if any
120+
obsolete
121+
"Use `item' [2014-03]"
122+
do
123+
Result := item (a_name)
124+
end
125+
116126
feature -- Header change: general
117127

118-
add_header_key_value (k,v: READABLE_STRING_8)
119-
-- Add header `k:v'.
128+
force (a_value: detachable READABLE_STRING_8; a_header_name: READABLE_STRING_8)
129+
-- Put header `a_header_name:a_value' or replace existing header of name `a_header_name'.
130+
--| this is used as assigner for `item'
131+
do
132+
if a_value = Void then
133+
put_header_key_value (a_header_name, "")
134+
else
135+
put_header_key_value (a_header_name, a_value)
136+
end
137+
end
138+
139+
add_header_key_value (a_header_name, a_value: READABLE_STRING_8)
140+
-- Add header `a_header_name:a_value'.
120141
-- If it already exists, there will be multiple header with same name
121142
-- which can also be valid
122143
local
123144
s: STRING_8
124145
do
125-
create s.make (k.count + 2 + v.count)
126-
s.append (k)
146+
create s.make (a_header_name.count + 2 + a_value.count)
147+
s.append (a_header_name)
127148
s.append (colon_space)
128-
s.append (v)
149+
s.append (a_value)
129150
add_header (s)
130151
ensure
131-
added: has_header_named (k)
152+
added: has_header_named (a_header_name)
132153
end
133154

134-
put_header_key_value (k,v: READABLE_STRING_8)
135-
-- Add header `k:v', or replace existing header of same header name/key
155+
put_header_key_value (a_header_name, a_value: READABLE_STRING_8)
156+
-- Add header `a_header_name:a_value', or replace existing header of same header name/key
136157
local
137158
s: STRING_8
138159
do
139-
create s.make (k.count + 2 + v.count)
140-
s.append (k)
160+
create s.make (a_header_name.count + 2 + a_value.count)
161+
s.append (a_header_name)
141162
s.append (colon_space)
142-
s.append (v)
163+
s.append (a_value)
143164
put_header (s)
144165
ensure
145-
added: has_header_named (k)
166+
added: has_header_named (a_header_name)
146167
end
147168

148-
put_header_key_values (k: READABLE_STRING_8; a_values: ITERABLE [READABLE_STRING_8]; a_separator: detachable READABLE_STRING_8)
149-
-- Add header `k: a_values', or replace existing header of same header values/key.
169+
put_header_key_values (a_header_name: READABLE_STRING_8; a_values: ITERABLE [READABLE_STRING_8]; a_separator: detachable READABLE_STRING_8)
170+
-- Add header `a_header_name: a_values', or replace existing header of same header values/key.
150171
-- Use `comma_space' as default separator if `a_separator' is Void or empty.
151172
local
152173
s: STRING_8
@@ -167,10 +188,10 @@ feature -- Header change: general
167188
s.append (c.item)
168189
end
169190
if not s.is_empty then
170-
put_header_key_value (k, s)
191+
put_header_key_value (a_header_name, s)
171192
end
172193
ensure
173-
added: has_header_named (k)
194+
added: has_header_named (a_header_name)
174195
end
175196

176197
feature -- Content related header

library/server/wsf/src/wsf_response_header.e

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
note
2-
description: "Summary description for {WSF_RESPONSE_HEADER}."
3-
author: ""
2+
description: "[
3+
Interface to build the http header associated with WSF_RESPONSE.
4+
]"
45
date: "$Date$"
56
revision: "$Revision$"
67

0 commit comments

Comments
 (0)