Skip to content

OCPBUGS-70112: Add Cache-Control headers to console responses - #16923

Open
jrangelramos wants to merge 1 commit into
openshift:mainfrom
jrangelramos:OCPBUGS-70112-cache-control-headers-main
Open

OCPBUGS-70112: Add Cache-Control headers to console responses#16923
jrangelramos wants to merge 1 commit into
openshift:mainfrom
jrangelramos:OCPBUGS-70112-cache-control-headers-main

Conversation

@jrangelramos

@jrangelramos jrangelramos commented Aug 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Set restrictive cache headers (no-cache, no-store, must-revalidate + Pragma: no-cache) by default on all responses via WithSecurityHeaders
  • Override with aggressive caching (public, max-age=31536000, immutable) for content-hashed static assets under /static/ via new WithStaticCacheHeaders
  • Remove redundant inner WithSecurityHeaders wrap on the static handler (the outer mux-level middleware already covers it)

Test plan

  • go build ./cmd/bridge/... compiles cleanly
  • go test ./pkg/middleware/... — 3 new tests pass:
    • TestWithSecurityHeaders — all 6 headers (4 existing + 2 new)
    • TestWithStaticCacheHeaders — static handler overrides restrictive defaults
    • TestNonStaticEndpointHasNoCacheHeaders — API endpoints get no-store
  • Manual: browser DevTools Network tab confirms index.html gets no-store, /static/ bundles get max-age=31536000

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
    • Static assets now use long-lived, immutable caching to improve load times and reduce repeated downloads.
  • Bug Fixes
    • Non-static responses now consistently prevent browser and intermediary caching.
    • Static asset delivery retains compression and directory-listing protection while using optimized caching behavior.

Set restrictive cache headers (no-cache, no-store) by default on all
responses via WithSecurityHeaders, and override with aggressive caching
(public, max-age=31536000, immutable) for content-hashed static assets
under /static/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 7, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jrangelramos: This pull request references Jira Issue OCPBUGS-70112, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

Summary

  • Set restrictive cache headers (no-cache, no-store, must-revalidate + Pragma: no-cache) by default on all responses via WithSecurityHeaders
  • Override with aggressive caching (public, max-age=31536000, immutable) for content-hashed static assets under /static/ via new WithStaticCacheHeaders
  • Remove redundant inner WithSecurityHeaders wrap on the static handler (the outer mux-level middleware already covers it)

Test plan

  • go build ./cmd/bridge/... compiles cleanly
  • go test ./pkg/middleware/... — 3 new tests pass:
  • TestWithSecurityHeaders — all 6 headers (4 existing + 2 new)
  • TestWithStaticCacheHeaders — static handler overrides restrictive defaults
  • TestNonStaticEndpointHasNoCacheHeaders — API endpoints get no-store
  • Manual: browser DevTools Network tab confirms index.html gets no-store, /static/ bundles get max-age=31536000

🤖 Generated with Claude Code

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci
openshift-ci Bot requested review from Leo6Leo and jhadvig August 7, 2026 13:25
@openshift-ci openshift-ci Bot added the component/backend Related to backend label Aug 7, 2026
@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jrangelramos
Once this PR has been reviewed and has the lgtm label, please assign therealjon for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The middleware adds no-cache headers for protected responses and immutable public caching for static assets. The /static/ route uses the static cache middleware. Tests cover both behaviors and non-static endpoint defaults.

Changes

Cache header middleware

Layer / File(s) Summary
Cache header middleware and tests
pkg/middleware/middleware.go, pkg/middleware/middleware_test.go
WithSecurityHeaders sets no-cache headers. WithStaticCacheHeaders sets one-year immutable caching and removes Pragma. Tests cover static and non-static responses.
Static route integration
pkg/server/server.go
The /static/ route uses WithStaticCacheHeaders while retaining gzip encoding and directory-listing protection.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 12 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the implementation and tests but omits several required template sections, including root cause, browser conformance, and reviewers. Complete the required template sections, especially Analysis / Root cause, Browser conformance, Additional info, and Reviewers and assignees.
Linked Issues check ⚠️ Warning The title includes OCPBUGS-70112, but the CI summary reports that this Jira issue is invalid for the target version 5.0.0. Update the Jira issue or change the PR title to a valid issue, then run /jira refresh.
✅ Passed checks (12 passed)
Check name Status Explanation
Stable And Deterministic Test Names ✅ Passed The PR adds only static Go Test... names; no Ginkgo It/Describe/Context/When titles or dynamic values appear in test names. The hash-like abc123 value is only in a request body.
Test Structure And Quality ✅ Passed The affected tests use standard Go testing with httptest, not Ginkgo; they create no cluster resources or waits, and each t.Errorf includes diagnostic context.
Microshift Test Compatibility ✅ Passed The PR adds only standard Go unit tests in pkg/middleware; no new Ginkgo e2e tests or MicroShift-incompatible APIs and features are present.
Single Node Openshift (Sno) Test Compatibility ✅ Passed The PR adds only standard Go middleware unit tests using testing.T; no Ginkgo e2e tests or multi-node/HA assumptions were added.
Topology-Aware Scheduling Compatibility ✅ Passed The diff changes only HTTP cache-header middleware, tests, and static handler wiring; it adds no deployment manifests, operator/controller scheduling constraints, or topology assumptions.
Ote Binary Stdout Contract ✅ Passed The PR adds no OTE binary or suite setup and no process-level stdout writes; existing klog defaults to stderr per vendor/klog/v2/klog.go.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed The PR adds only standard Go unit tests using testing and httptest; no Ginkgo e2e tests, IPv4 assumptions, or external network access are present.
No-Weak-Crypto ✅ Passed The PR delta adds only HTTP cache-header middleware and tests; it introduces no weak-crypto API, custom crypto, or secret/token comparison. Existing MD5 code is unchanged.
Container-Privileges ✅ Passed The PR changes only Go files and adds no privileged, host namespace, SYS_ADMIN, or allowPrivilegeEscalation settings; the existing USER 0 build stage is unchanged and the final image uses USER 1001.
No-Sensitive-Data-In-Logs ✅ Passed The PR patch adds HTTP headers, middleware tests, and a route wrapper change; it adds no logging calls or log output containing sensitive data.
Title check ✅ Passed The title clearly identifies the Jira issue and the primary change: adding Cache-Control headers to console responses.
Out of Scope Changes check ✅ Passed The middleware changes, server integration, and tests directly support the stated objective of adding cache headers.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jrangelramos

Copy link
Copy Markdown
Member Author

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Aug 7, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jrangelramos: This pull request references Jira Issue OCPBUGS-70112, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

No GitHub users were found matching the public email listed for the QA contact in Jira (yapei@redhat.com), skipping review request.

Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jrangelramos: This pull request references Jira Issue OCPBUGS-70112, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)

No GitHub users were found matching the public email listed for the QA contact in Jira (yapei@redhat.com), skipping review request.

Details

In response to this:

Summary

  • Set restrictive cache headers (no-cache, no-store, must-revalidate + Pragma: no-cache) by default on all responses via WithSecurityHeaders
  • Override with aggressive caching (public, max-age=31536000, immutable) for content-hashed static assets under /static/ via new WithStaticCacheHeaders
  • Remove redundant inner WithSecurityHeaders wrap on the static handler (the outer mux-level middleware already covers it)

Test plan

  • go build ./cmd/bridge/... compiles cleanly
  • go test ./pkg/middleware/... — 3 new tests pass:
  • TestWithSecurityHeaders — all 6 headers (4 existing + 2 new)
  • TestWithStaticCacheHeaders — static handler overrides restrictive defaults
  • TestNonStaticEndpointHasNoCacheHeaders — API endpoints get no-store
  • Manual: browser DevTools Network tab confirms index.html gets no-store, /static/ bundles get max-age=31536000

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Performance
  • Static assets now use long-lived, immutable caching to improve load times and reduce repeated downloads.
  • Bug Fixes
  • Non-static responses now consistently prevent browser and intermediary caching.
  • Static asset delivery retains compression and directory-listing protection while using optimized caching behavior.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jrangelramos

Copy link
Copy Markdown
Member Author

manual verification

$ curl -skI $CONSOLE_URL | grep -iE 'cache-control|pragma|expires'  
cache-control: no-cache, no-store, must-revalidate
pragma: no-cache
$ curl -skI $CONSOLE_URL/static/main-bundle-135c35ac6fc8bd54.min.js | grep -iE 'cache-control|pragma|expires' 
cache-control: public, max-age=31536000, immutable
cache-control: private
$ curl -skI $CONSOLE_URL/api/console/version | grep -iE 'cache-control|pragma|expires'                       
cache-control: no-cache, no-store, must-revalidate
pragma: no-cache
$ echo $CONSOLE_URL    
https://console-openshift-console.apps.jeramos-1333.ci-psi.rhocf-dev.net

@jrangelramos

Copy link
Copy Markdown
Member Author

/verified by Jefferson Ramos

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Aug 7, 2026
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

@jrangelramos: This PR has been marked as verified by Jefferson Ramos.

Details

In response to this:

/verified by Jefferson Ramos

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jhadvig

jhadvig commented Aug 8, 2026

Copy link
Copy Markdown
Member

/retest

@openshift-ci

openshift-ci Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@jrangelramos: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/backend 6563a5b link true /test backend

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/backend Related to backend jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants