From 42a8c7e16bfc15f22967f546b71edc240384f926 Mon Sep 17 00:00:00 2001 From: Felipe Pena Date: Sun, 10 Dec 2023 09:32:30 -0300 Subject: [PATCH] net.http: fix http.delete() checking (#20131) --- vlib/net/http/header.v | 4 ++-- vlib/net/http/header_test.v | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/vlib/net/http/header.v b/vlib/net/http/header.v index 9d8a180b5d..39c2e85c1b 100644 --- a/vlib/net/http/header.v +++ b/vlib/net/http/header.v @@ -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, ''} } } diff --git a/vlib/net/http/header_test.v b/vlib/net/http/header_test.v index 91ce936a2b..bedd6b9943 100644 --- a/vlib/net/http/header_test.v +++ b/vlib/net/http/header_test.v @@ -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')!