Skip to content

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Jan 8, 2025

match {
status <code...>
header <field> [<value>]
header <field> <value>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be reading this wrong, but this seemed to suggest that the header value is optional. This change to emphasize that both the header name and the value are required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's technically optional because you can do -Field to delete a header, in which case no value is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you talking about the header directive?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, yeah sorry. I didn't click through to the files changed so I didn't notice it was the response matcher in encode. That said, ! as a prefix is allowed, meaning "this header doesn't exist in the response" and in that case you omit the value. See https://caddyserver.com/docs/caddyfile/response-matchers#header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, didn't know about the ! syntax. I'll revert.

[defer]
# a match condition
match [status <code...> | header <field> <value>]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one's a bit strange cause it's not optional to provide a matcher, so the [] are sorta misplaced.

I think we should probably replace these to just <response_matcher...> instead, similar to how we have <matcher> in places where a request matcher can go. We can add a jquery blob at the top to transform those into links to https://caddyserver.com/docs/caddyfile/response-matchers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good idea. There are two ways in which response matchers can be used. I documented the difference.

encode and headers allow inline matching, intercept requires creating named response matchers.

Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this! @francislavoie Does this LGTY?

@francislavoie francislavoie merged commit 72aa1b3 into caddyserver:master Jun 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants