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

fix header existence logic, exactly treat as null or empty string #353

Merged
merged 1 commit into from
Sep 26, 2024
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
16 changes: 16 additions & 0 deletions examples/testing/default/default.test.vcl
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,19 @@ sub test_check_auth {
assert.equal(testing.state, "ERROR");
assert.equal(testing.inspect("obj.status"), 401);
}

// @scope: recv
// @suite: condition with not set string header
sub test_header_value {
declare local var.exists BOOL;
if (req.http.Check-Auth) {
set var.exists = true;
}
assert.false(var.exists);
set req.http.Check-Auth = "";
if (req.http.Check-Auth) {
set var.exists = true;
}
assert.true(var.exists);
}

16 changes: 8 additions & 8 deletions interpreter/variable/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
func getRequestHeaderValue(r *http.Request, name string) *value.String {
// Header name can contain ":" for object-like value
if !strings.Contains(name, ":") {
v := strings.Join(r.Header.Values(name), ", ")
if v == "" {
return &value.String{IsNotSet: true}
if _, ok := r.Header[textproto.CanonicalMIMEHeaderKey(name)]; ok {
v := strings.Join(r.Header.Values(name), ", ")
return &value.String{Value: v}
}
return &value.String{Value: v}
return &value.String{IsNotSet: true}
}
spl := strings.SplitN(name, ":", 2)
// Request header can modify cookie, then we need to retrieve value from Cookie pointer
Expand All @@ -40,11 +40,11 @@ func getRequestHeaderValue(r *http.Request, name string) *value.String {
func getResponseHeaderValue(r *http.Response, name string) *value.String {
// Header name can contain ":" for object-like value
if !strings.Contains(name, ":") {
v := strings.Join(r.Header.Values(name), ", ")
if v == "" {
return &value.String{IsNotSet: true}
if _, ok := r.Header[textproto.CanonicalMIMEHeaderKey(name)]; ok {
v := strings.Join(r.Header.Values(name), ", ")
return &value.String{Value: v}
}
return &value.String{Value: v}
return &value.String{IsNotSet: true}
}

spl := strings.SplitN(name, ":", 2)
Expand Down