Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add Del func for requestHeader #950

Merged
merged 2 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/protocol/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,12 @@ func (h *RequestHeader) DelBytes(key []byte) {
h.del(h.bufKV.key)
}

// Del deletes header with the given key.
func (h *RequestHeader) Del(key string) {
k := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing)
h.del(k)
}

func (h *RequestHeader) SetArgBytes(key, value []byte, noValue bool) {
h.h = setArgBytes(h.h, key, value, noValue)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/protocol/header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestRequestHeaderDel(t *testing.T) {
var h RequestHeader
h.Set("Foo-Bar", "baz")
h.Set("aaa", "bbb")
h.Set("ccc", "ddd")
h.Set(consts.HeaderConnection, "keep-alive")
h.Set(consts.HeaderContentType, "aaa")
h.Set(consts.HeaderServer, "aaabbb")
Expand All @@ -226,11 +227,16 @@ func TestRequestHeaderDel(t *testing.T) {
h.del([]byte("Host"))
h.del([]byte(consts.HeaderTrailer))
h.DelCookie("foo")
h.Del("ccc")

hv := h.Peek("aaa")
if string(hv) != "bbb" {
t.Fatalf("unexpected header value: %q. Expecting %q", hv, "bbb")
}
hv = h.Peek("ccc")
if string(hv) != "" {
t.Fatalf("unexpected header value: %q. Expecting %q", hv, "")
}
hv = h.Peek("Foo-Bar")
if len(hv) > 0 {
t.Fatalf("non-zero header value: %q", hv)
Expand Down