Skip to content

Commit 42a8c7e

Browse files
authored
net.http: fix http.delete() checking (#20131)
1 parent fe4e1c0 commit 42a8c7e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

vlib/net/http/header.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,8 +469,8 @@ pub fn (mut h Header) delete(key CommonHeader) {
469469

470470
// delete_custom deletes all values for a custom header key.
471471
pub fn (mut h Header) delete_custom(key string) {
472-
for i, kv in h.data {
473-
if kv.key == key {
472+
for i := 0; i < h.cur_pos; i++ {
473+
if h.data[i].key == key {
474474
h.data[i] = HeaderKV{key, ''}
475475
}
476476
}

vlib/net/http/header_test.v

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ fn test_header_delete_not_existing() {
7979
// assert h.keys.len == 0
8080
}
8181

82+
fn test_delete_header() {
83+
mut r := new_request(.get, '', '')
84+
r.header.set(.authorization, 'foo')
85+
r.header.delete(.authorization)
86+
assert r.header.get(.authorization)! == ''
87+
}
88+
8289
fn test_custom_header() {
8390
mut h := new_header()
8491
h.add_custom('AbC', 'dEf')!

0 commit comments

Comments
 (0)