When using the JSON config, you can now match when a header does not exist using a null value as of 4fc570711e170da2bd1164966d2c47f9dc3d3d6d. However, this syntax is impossible to use when using the Caddyfile.
My proposed solution is to support a null literal value for these matchers, perhaps using the same - character as with the map module.
I'm not sure I like either null or - here, I'd rather not have special values like that, because what if someone actually wants to match on exactly null or -? Yes it may be rare, but it doesn't seem like a limitation we should have.
@mholt how would you feel about implementing the ? prefix as a null value match?
I started tinkering around with this on a local fork (using the ? prefix convention for now) and I ran into what feels like a problem.
http.Header() does not allow you to set a field as nil using the public methods, so seemingly the only way to achieve this is to manually dereference the underlying map and set the field manually, which feels like a hack.
func (m *MatchHeader) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
// ...
temp := *m
temp[field] = nil
m = &temp
// ...
}
Was wondering if anyone knew a better way of going about doing this.
@lolPants Yep, something like that will probably do. Kind of annoying but I think that's how I'd do it.\
About the ?, I don't love that since it usually signifies optional or "if nil". I am not sure what the right syntax should be. Maybe ! instead?
I think header !Authorization makes sense :+1:
I've started a draft PR at #3909 for this issue
Most helpful comment
I think
header !Authorizationmakes sense :+1: