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

🔧 rm default Expires response header filter #303

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

simonhir
Copy link
Member

@simonhir simonhir commented Dec 5, 2024

Description

Remove default-filter RemoveResponseHeader=Expires as it can lead to problems with applications.

  • Seems to initially added when the frontend was delivered directly via Spring (which isn't the case anymore).
  • It's not the responsibility of the gateway to remove the Expires header if a frontend/service sets it wrong.
  • When setting up the refarch archetype there where problems between Expires and Cache-Control

Summary by CodeRabbit

  • New Features

    • The gateway will now retain the Expires header in responses, improving caching behavior for users.
  • Bug Fixes

    • Resolved an issue where the Expires header was being stripped from responses.

@simonhir simonhir self-assigned this Dec 5, 2024
@simonhir simonhir requested a review from a team as a code owner December 5, 2024 06:31
Copy link

coderabbitai bot commented Dec 5, 2024

Walkthrough

The changes involve the modification of the application.yml configuration file for a Spring application. Specifically, the entry RemoveResponseHeader=Expires has been removed from the default-filters section under cloud.gateway. This adjustment affects the gateway's behavior by allowing the Expires header to remain in responses. Additionally, various test classes have been updated to reflect this change by removing assertions and stubbing related to the Expires header, streamlining response handling and expectations.

Changes

File Path Change Summary
refarch-gateway/src/main/resources/application.yml Removed RemoveResponseHeader=Expires from default-filters in cloud.gateway.
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalAuthenticationErrorFilterTest.java Removed Expires header from stubbed response and updated assertions in backendAuthenticationError.
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackend5xxTo400MapperTest.java Removed WWW_AUTHENTICATE and EXPIRES headers from response stubbing and assertions in backendError500 and backendError200.
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackendErrorFilterTest.java Removed Expires header from stubbed response and updated assertions in backendError.
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/route/BackendRouteTest.java Removed Expires header from stubbed response and adjusted request headers in backendRouteResponse.

Poem

In the realm of code where headers play,
A little change brightens the day.
The Expires now dances, no longer concealed,
In the gateway's heart, its fate is revealed.
Hooray for the headers, let them all thrive,
In the world of Spring, we feel so alive! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Component: API-Gateway Issues regarding the API Gateway Type: Maintenance The issue contains maintenance work. labels Dec 5, 2024
@simonhir simonhir changed the title 🔧 rm default Expires response header remove 🔧 rm default Expires response header filter Dec 5, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range comments (1)
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/route/BackendRouteTest.java (1)

Line range hint 32-45: Add test coverage for Expires header behavior.

Since the PR removes the RemoveResponseHeader=Expires filter, we should add test coverage to verify that Expires headers now pass through the gateway unchanged. This ensures the new behavior is working as expected.

Add the Expires header to the stub response and verify it in the test:

         stubFor(get(urlEqualTo("/remote/endpoint"))
                 .willReturn(aResponse()
                         .withStatus(HttpStatus.OK.value())
                         .withHeaders(new HttpHeaders(
                                 new HttpHeader(org.springframework.http.HttpHeaders.CONTENT_TYPE, "application/json"),
+                                new HttpHeader(org.springframework.http.HttpHeaders.EXPIRES, "Wed, 21 Oct 2025 07:28:00 GMT"),
                                 new HttpHeader(org.springframework.http.HttpHeaders.WWW_AUTHENTICATE,
                                         "Bearer realm=\"Access to the staging site\", charset=\"UTF-8\"") // removed by route filter
                         ))
                         .withBody("{ \"testkey\" : \"testvalue\" }")));

And in the test method:

                 .expectStatus().isEqualTo(HttpStatus.OK)
                 .expectHeader().valueMatches(org.springframework.http.HttpHeaders.CONTENT_TYPE, "application/json")
+                .expectHeader().valueMatches(org.springframework.http.HttpHeaders.EXPIRES, "Wed, 21 Oct 2025 07:28:00 GMT")
                 .expectHeader().doesNotExist(org.springframework.http.HttpHeaders.WWW_AUTHENTICATE)
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between 83b08fe and 9efc0ac.

📒 Files selected for processing (4)
  • refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalAuthenticationErrorFilterTest.java (1 hunks)
  • refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackend5xxTo400MapperTest.java (2 hunks)
  • refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackendErrorFilterTest.java (1 hunks)
  • refarch-gateway/src/test/java/de/muenchen/refarch/gateway/route/BackendRouteTest.java (1 hunks)
🔇 Additional comments (8)
refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackend5xxTo400MapperTest.java (3)

48-48: LGTM! Clean formatting of WWW_AUTHENTICATE header value

The formatting change improves code readability while maintaining the same functionality.


70-70: LGTM! Consistent formatting with previous change

The formatting change maintains consistency with the earlier change in backendError500.


Line range hint 1-83: Verify complete removal of Expires header handling

The changes align with the PR objective of removing the Expires header filter. Let's verify that all Expires header related code has been properly removed from the codebase.

✅ Verification successful

All Expires header related code has been properly removed

The search results show that all occurrences of "expires" in the Java codebase are related to S3 presigned URL functionality, which is a different feature from HTTP Expires header handling. There are no remaining references to HTTP Expires header filtering in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining references to Expires header in the codebase
rg -i "expires" --type java

Length of output: 21751

refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackendErrorFilterTest.java (2)

46-46: LGTM! Header setup correctly simplified

The removal of the Expires header from the test stub aligns with the PR objective of removing the default Expires header filter. The test remains focused on core error handling functionality.


Line range hint 52-60: Verify complete error handling test coverage

The test verifies essential aspects of error handling (status code, content type, WWW-Authenticate removal, error response format). However, let's verify that no other tests were responsible for Expires header behavior.

✅ Verification successful

Let me check the specific usage of "Expires" in the found test file to ensure we have complete context.


Error handling test coverage is complete - no Expires header concerns

The found references to "Expires" are unrelated to HTTP headers - they are part of S3 presigned URL functionality where expiresInMinutes is a parameter for URL expiration. There are no remaining test assertions for HTTP Expires headers in the codebase. The current error handling test coverage in GlobalBackendErrorFilterTest is sufficient.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining Expires header tests that might need updating
# Search for any test files that might still reference Expires headers

echo "Searching for any remaining test assertions for Expires header..."
rg -l "Expires" --type java --glob "*Test.java"

echo "Searching for any remaining header setup in test files..."
ast-grep --pattern 'new HttpHeader("Expires"' 

Length of output: 584


Script:

#!/bin/bash
# Check the specific usage of Expires header in the found test file
rg -A 5 -B 5 "Expires" refarch-integrations/refarch-s3-integration/refarch-s3-integration-rest/refarch-s3-integration-rest-client/src/test/java/de/muenchen/refarch/integration/s3/client/repository/presignedurl/PresignedUrlRestRepositoryTest.java

Length of output: 2376

refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalAuthenticationErrorFilterTest.java (2)

40-40: LGTM! Header configuration aligns with PR objectives

The removal of the Expires header from the test stub is consistent with the PR's goal of no longer managing the Expires header at the gateway level.


Line range hint 44-54: Verify complete test coverage for header handling

The test appropriately verifies authentication error scenarios and header management. However, let's ensure we have comprehensive test coverage for all header-related scenarios.

✅ Verification successful

Header handling test coverage is comprehensive and well-implemented

The test coverage for header handling is complete across the codebase. The current test and related test files demonstrate thorough verification of:

  • Content-Type header assertions
  • WWW-Authenticate header removal
  • CSRF token cookie handling
  • Error response headers
  • Authentication-related headers

Each scenario properly validates both the presence and absence of specific headers as needed, with appropriate assertions for header values and patterns.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other test files that might need similar header-related test updates

# Search for similar test patterns in other files
rg -l "expectHeader|withHeader" --type java src/test/

# Search for any remaining Expires header assertions
rg -i "expires" --type java src/test/

Length of output: 193


Script:

#!/bin/bash
# Description: Check for other test files that might need similar header-related test updates

# Search for similar test patterns in other files
rg -l "expectHeader|withHeader" --type java refarch-gateway/src/test/

# Search for any remaining Expires header assertions
rg -i "expires" --type java refarch-gateway/src/test/

# Look for other test files with HTTP status assertions to ensure complete coverage
rg -l "expectStatus|isEqualTo\(HttpStatus" --type java refarch-gateway/src/test/

# Search for authentication-related test files
rg -l "WithMockUser|Authentication" --type java refarch-gateway/src/test/

Length of output: 2099


Script:

#!/bin/bash
# Let's examine the header assertions in these test files to ensure complete coverage

# Check GlobalAuthenticationErrorFilterTest for all header-related tests
rg "expectHeader|withHeader" -A 3 -B 3 refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalAuthenticationErrorFilterTest.java

# Check other relevant test files for header assertions
rg "expectHeader|withHeader" -A 3 -B 3 refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/CsrfTokenAppendingHelperFilterTest.java
rg "expectHeader|withHeader" -A 3 -B 3 refarch-gateway/src/test/java/de/muenchen/refarch/gateway/filter/GlobalBackendErrorFilterTest.java

Length of output: 2689

refarch-gateway/src/test/java/de/muenchen/refarch/gateway/route/BackendRouteTest.java (1)

Line range hint 1-1: Verify consistent test updates across all gateway test files.

The AI summary indicates changes in other test files. Let's verify that all gateway test files are consistently updated to reflect the new Expires header behavior.

Copy link
Member

@devtobi devtobi left a comment

Choose a reason for hiding this comment

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

LGTM

@simonhir simonhir merged commit 74acd8c into main Dec 5, 2024
14 checks passed
@simonhir simonhir deleted the maint/remove-expires-header branch December 5, 2024 08:02
@simonhir simonhir added the BREAKING Change may cause existing code to break label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING Change may cause existing code to break Component: API-Gateway Issues regarding the API Gateway Type: Maintenance The issue contains maintenance work.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants