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

feature request: add header only if not already set #3804

Closed
gilbsgilbs opened this issue Oct 18, 2020 · 0 comments · Fixed by #3807
Closed

feature request: add header only if not already set #3804

gilbsgilbs opened this issue Oct 18, 2020 · 0 comments · Fixed by #3807
Labels
feature ⚙️ New feature or request
Milestone

Comments

@gilbsgilbs
Copy link
Contributor

gilbsgilbs commented Oct 18, 2020

I'm in a case where I'd like the header directive to set the header only if it wasn't already set by an upstream server. Think it as a default value for headers. This would be useful for e.g. setting Cache-Control to no-store by default, except if the upstream server defines a specific Cache-Control value. I don't think it is possible yet (at least with the Caddyfile adapter).

The syntax could be inspired from the syntax used to append/delete headers:

#      ↓
header ?Cache-Control "no-store" {
  defer
}

or alternatively using an explicit parameter (but that wouldn't make much sense when used in combination with +/- IMHO):

header Cache-Control "no-store" {
  if_not_set
  defer
}

Would you accept such contribution? Or is it out of scope?

gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 18, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 18, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 18, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 19, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 19, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Oct 19, 2020
@francislavoie francislavoie added the feature ⚙️ New feature or request label Nov 3, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Nov 17, 2020
gilbsgilbs added a commit to gilbsgilbs/caddy that referenced this issue Nov 17, 2020
mholt added a commit that referenced this issue Nov 20, 2020
* implement default values for header directive

closes #3804

* remove `set_default` header op and rely on "require" handler instead

This has the following advantages over the previous attempt:

- It does not introduce a new operation for headers, but rather nicely
  extends over an existing feature in the header handler.
- It removes the need to specify the header as "deferred" because it is
  already implicitely deferred by the use of the require handler. This
  should be less confusing to the user.

* add integration test for header directive in caddyfile

* bubble up errors when parsing caddyfile header directive

* don't export unnecessarily and don't canonicalize headers unnecessarily

* fix response headers not passed in blocks

* caddyfile: fix clash when using default header in block

Each header is now set in a separate handler so that it doesn't clash
with other headers set/added/deleted in the same block.

* caddyhttp: New idle_timeout default of 5m

* reverseproxy: fix random hangs on http/2 requests with server push (#3875)

see golang/go#42534

* Refactor and cleanup with improvements

* More specific link

Co-authored-by: Matthew Holt <mholt@users.noreply.github.com>
Co-authored-by: Денис Телюх <telyukh.denis@gmail.com>
@mholt mholt added this to the v2.3.0 milestone Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants