Skip to content

fix: trim optional whitespace in cache-control directives - #320

Open
dajiaohuang wants to merge 1 commit into
allaboutapps:masterfrom
dajiaohuang:fix/cache-control-whitespace
Open

dajiaohuang wants to merge 1 commit into
allaboutapps:masterfrom
dajiaohuang:fix/cache-control-whitespace

Conversation

@dajiaohuang

@dajiaohuang dajiaohuang commented Oct 23, 2026 •

Copy link
Copy Markdown

User description

ParseCacheControlHeader("no-cache, no-store") currently returns only no-cache, because the second directive retains its leading space. The request middleware passes this incomplete bitmask into the request context.

Trim optional spaces and tabs from directive names before matching. Add five offline parser cases covering compact lists, spaces, tabs, mixed case and unrelated directives.

Validation: four whitespace regression cases fail before the change; all five pass after it using go test cache_control.go context.go cache_control_parser_test.go -count=1 from internal/util. git diff --check also passes. The full service/database integration suite was not run; no database, Docker daemon or deployed service was used.


PR Type

Bug fix, Tests


Description

  • Trim whitespace in cache-control directives

  • Add tests for cache-control parsing


Diagram Walkthrough

flowchart LR
  A["Input Directive"] -- "Split by '='" --> B["Parts"]
  B -- "Trim spaces and tabs" --> C["Cleaned Directive"]
  C -- "Match" --> D["CacheControlDirective"]
Loading

File Walkthrough

Relevant files
Bug fix
cache_control.go
Trim whitespace in directive parsing                                         

internal/util/cache_control.go

  • Trim spaces and tabs from directive names before matching.
+1/-1     
Tests
cache_control_parser_test.go
Add tests for cache-control parsing                                           

internal/util/cache_control_parser_test.go

  • Add TestParseCacheControlWhitespace to verify parsing behavior.
  • Test various whitespace, casing, and compact list scenarios.
+20/-0   

@aaa-pr-agent

aaa-pr-agent Bot commented Oct 23, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@aaa-pr-agent

aaa-pr-agent Bot commented Oct 23, 2026

Copy link
Copy Markdown

PR Code Suggestions ✨

No code suggestions found for the PR.

@@ -0,0 +1,20 @@
package util

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fix, it’s spot on. One small thing before we merge: could you switch the test to package util_test and use testify (assert.Equal(t, want, util.ParseCacheControlHeader(input))) so it matches the other tests in internal/util? Feel free to move it into cache_control_test.go too, but a separate file is fine. Happy to merge once that’s in.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants