Skip to content

Commit

Permalink
Merge pull request #353 from ysugimoto/fix/header-existence
Browse files Browse the repository at this point in the history
fix header existence logic, exactly treat as null or empty string
  • Loading branch information
ysugimoto authored Sep 26, 2024
2 parents 4ebf027 + 96c52d4 commit 52af080
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
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

0 comments on commit 52af080

Please sign in to comment.