net.http: fix http.delete() checking (#20131)

This commit is contained in:
Felipe Pena 2023-12-10 09:32:30 -03:00 committed by GitHub
parent fe4e1c0672
commit 42a8c7e16b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -469,8 +469,8 @@ pub fn (mut h Header) delete(key CommonHeader) {
// delete_custom deletes all values for a custom header key.
pub fn (mut h Header) delete_custom(key string) {
for i, kv in h.data {
if kv.key == key {
for i := 0; i < h.cur_pos; i++ {
if h.data[i].key == key {
h.data[i] = HeaderKV{key, ''}
}
}

View File

@ -79,6 +79,13 @@ fn test_header_delete_not_existing() {
// assert h.keys.len == 0
}
fn test_delete_header() {
mut r := new_request(.get, '', '')
r.header.set(.authorization, 'foo')
r.header.delete(.authorization)
assert r.header.get(.authorization)! == ''
}
fn test_custom_header() {
mut h := new_header()
h.add_custom('AbC', 'dEf')!