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

Add support for ResponseHeaderModifier for HTTPRouteRule objects #1880

Open
wants to merge 70 commits into
base: main
Choose a base branch
from

Conversation

salonichf5
Copy link
Contributor

@salonichf5 salonichf5 commented Apr 25, 2024

Proposed changes

Problem: Users want to add, set, and remove response headers.

Solution: Use add_header NGINX directive to support ResponseHeaderModifier.

  • If the action is set, we simply configure the add_header directive with the given value in the HTTPRoute spec.
  • If the action is remove, we configure the add_header directive with the value set to an empty string.
  • If the action is add, we create a mapping for the $http_header_name variable appending a comma at the end of any client provided headers (if present) and prepend this to the given value in the HTTPRoute spec.

Testing: Describe any testing that you did.

Please focus on (optional): If you any specific areas where you would like reviewers to focus their attention or provide
specific feedback, add them here.

Closes #1397

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

Introduces support for the HTTP filter `ResponseHeaderModifier`, enabling the modification of response headers within HTTPRoutes.

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 25, 2024
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.83%. Comparing base (d264258) to head (2fc154f).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1880      +/-   ##
==========================================
+ Coverage   86.72%   86.83%   +0.11%     
==========================================
  Files          88       88              
  Lines        5972     6025      +53     
  Branches       50       50              
==========================================
+ Hits         5179     5232      +53     
  Misses        741      741              
  Partials       52       52              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@salonichf5 salonichf5 changed the title Feat/response header Add support for ResponseHeaderModifier for HTTPRouteRule objects Apr 25, 2024
@salonichf5 salonichf5 self-assigned this Apr 25, 2024
@salonichf5
Copy link
Contributor Author

Kevin's PR - #1494

@salonichf5
Copy link
Contributor Author

Shouldn't we be adding the responseHeaderModifier validation here ? @kate-osborn

@kate-osborn
Copy link
Contributor

kate-osborn commented May 1, 2024

Shouldn't we be adding the responseHeaderModifier validation here ? @kate-osborn

@salonichf5 it looks like the intent was to make the HTTPRequestHeaderValidator more generic so it could validate both request and response headers, and then add the response header-specific validation separately in the validateFilterResponseHeaderModifier function in httproute.go.

I like your suggestion of adding a new struct to the HTTPValidator that validates response headers. I would move the functionality of validateFilterResponseHeaderModifier to that new validator.

Edit: @salonichf5 after looking through the code again, I think there will be less code duplication if we keep the approach the same. I would just rename HTTPRequestHeaderValidator to HTTPHeaderValidator and keep everything else the same.

@salonichf5 salonichf5 marked this pull request as ready for review May 2, 2024 01:30
@salonichf5 salonichf5 requested review from a team as code owners May 2, 2024 01:30
examples/http-header-filter/README.md Outdated Show resolved Hide resolved
examples/http-response-header-filter/README.md Outdated Show resolved Hide resolved
examples/http-response-header-filter/headers.yaml Outdated Show resolved Hide resolved
examples/http-response-header-filter/headers.yaml Outdated Show resolved Hide resolved
examples/http-response-header-filter/README.md Outdated Show resolved Hide resolved
site/content/overview/gateway-api-compatibility.md Outdated Show resolved Hide resolved
site/content/overview/gateway-api-compatibility.md Outdated Show resolved Hide resolved
site/content/overview/gateway-api-compatibility.md Outdated Show resolved Hide resolved
site/content/overview/gateway-api-compatibility.md Outdated Show resolved Hide resolved
@salonichf5 salonichf5 requested a review from ciarams87 May 2, 2024 20:54
Problem: Users want to add, set, and remove response headers.

Solution: Use `add_header` NGINX directive to support `ResponseHeaderModifier`.
* If the action is `set`, we simply configure the `add_header` directive with the given value in the HTTPRoute spec.
* If the action is `remove`, we configure the `add_header` directive with the value set to an empty string.
* If the action is `add`, we create a mapping for the `$http_header_name` variable appending a comma at the end of any client provided headers (if present) and prepend this to the given value in the HTTPRoute spec.
@sjberman
Copy link
Contributor

sjberman commented May 6, 2024

Btw when we squash and merge, we can add @kevin85421 as a co-author to the commit so proper credit is given :)

Co-authored-by: Saylor Berman <s.berman@f5.com>
@kevin85421
Copy link
Contributor

@sjberman Thank you! You guys are so nice.

@salonichf5 salonichf5 requested a review from sjberman May 6, 2024 21:13
Copy link
Contributor

@ADubhlaoich ADubhlaoich left a comment

Choose a reason for hiding this comment

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

LGTM docs-wise but the PR is primarily code based so I will not approve.

Co-authored-by: Jon Torre <78599298+Jcahilltorre@users.noreply.github.com>
salonichf5 and others added 7 commits May 7, 2024 15:45
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
salonichf5 and others added 2 commits May 8, 2024 12:27
Co-authored-by: Kate Osborn <50597707+kate-osborn@users.noreply.github.com>
@salonichf5 salonichf5 requested a review from sjberman May 9, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request release-notes
Projects
Status: 🏗 In Progress
Development

Successfully merging this pull request may close these issues.

Filter: ResponseHeaderModifier
8 participants