Skip to content

Conversation

@gaby
Copy link
Member

@gaby gaby commented Aug 11, 2025

Summary

  • ensure route parameters copy when Immutable config enabled
  • use config-aware getter for HTTP protocol and Content-Encoding headers
  • add test ensuring Params uses independent memory under Immutable

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Updated AutoFormat documentation to list additional content types. DefaultReq now returns copied param strings when App.Config.Immutable is true and reads headers via r.App().getString(...). Two tests asserting param immutability were added (duplicated). No exported signatures changed.

Changes

Cohort / File(s) Summary
Docs: AutoFormat comments
ctx_interface_gen.go, res_interface_gen.go
Expanded documented supported content types for AutoFormat to include application/vnd.msgpack and application/cbor (comments only).
Request handling internals
req.go
Params(...) returns a copied string when App().config.Immutable is true (uses utils.CopyString); header reads now use r.App().getString(...) instead of utils.UnsafeString.
Tests: Params immutability
ctx_test.go
Added tests asserting route params remain unchanged when underlying path bytes mutate with Config{Immutable: true}. Two identical Test_Ctx_Params_Immutable functions were added (duplication).

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant App
  participant Ctx
  participant Req

  Client->>App: HTTP request
  App->>Ctx: Acquire context
  Ctx->>Req: Params("user")
  alt App.Config.Immutable == true
    Req-->>Ctx: return copy of value
  else
    Req-->>Ctx: return original reference
  end
  Ctx-->>Client: Handler uses param
Loading
sequenceDiagram
  participant Ctx
  participant Req
  participant App

  Ctx->>Req: read header (Protocol/Content-Encoding)
  Req->>App: getString(Header.*)
  App-->>Req: normalized safe string
  Req-->>Ctx: header-derived value
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested labels

☢️ Bug

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

I hop through bytes with careful paws,
I copy names to keep their cause.
I tidy headers, calm and spry,
So params stay true when paths go by.
A little rabbit patch — hooray! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f0a5b25 and f21b54c.

📒 Files selected for processing (1)
  • ctx_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ctx_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Analyse
  • GitHub Check: Compare
  • GitHub Check: repeated
  • GitHub Check: unit (1.24.x, windows-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch 2025-08-11-00-12-44

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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 explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

I've implemented changes to improve the handling of immutable configurations within the application, focusing on how route parameters and certain HTTP headers are accessed. The primary goal is to ensure that when an Immutable setting is active, data retrieved from requests, such as route parameters, are provided as safe, independent copies. This prevents unintended side effects from subsequent modifications to the underlying request data. Additionally, I've updated the documentation to reflect broader content type support for automatic formatting.

Highlights

  • Enhanced Immutability for Route Parameters: I've ensured that when the Immutable configuration is enabled, route parameters returned by the Params method are now independent copies. This prevents external modifications to the underlying request path from inadvertently altering the parameter values, enhancing data integrity and predictability.
  • Config-Aware Header Retrieval: I've updated the retrieval of HTTP Content-Encoding and Protocol headers to use a new config-aware string getter. This change ensures that these header values are handled consistently with the application's immutability settings, moving away from potentially unsafe string conversions.
  • New Test Case for Params Immutability: I've added a new test case specifically to validate the immutability behavior of the Params method. This test confirms that even if the underlying request path is modified after a parameter is retrieved, the original parameter value remains unchanged, verifying the effectiveness of the immutability fix.
  • Documentation Update for AutoFormat: I've updated the documentation comments for the AutoFormat method in both ctx_interface_gen.go and res_interface_gen.go to explicitly list application/vnd.msgpack and application/cbor as supported content types. This provides clearer information for developers on the full range of content negotiation capabilities.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gaby gaby changed the title Respect immutable config for params and protocol 🧹 chore: Respect immutable config in params() and protocol() Aug 11, 2025
@gaby gaby added this to v3 Aug 11, 2025
@gaby gaby added this to the v3 milestone Aug 11, 2025
@gaby gaby moved this to In Progress in v3 Aug 11, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly implements the logic to respect the Immutable configuration for route parameters and some headers, ensuring that values are copied when the setting is enabled. A new test is added to verify this behavior. The changes are consistent with the project's design and improve the framework's robustness when dealing with immutable data.

@gaby gaby marked this pull request as ready for review August 11, 2025 00:15
Copilot AI review requested due to automatic review settings August 11, 2025 00:15
@gaby gaby requested a review from a team as a code owner August 11, 2025 00:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that the Fiber framework properly respects the Immutable configuration setting when accessing route parameters and HTTP headers. The changes prevent memory sharing issues that could occur when the Immutable config is enabled.

  • Updates Params() method to copy parameter values when Immutable config is enabled
  • Replaces direct header access with config-aware string getters for Protocol and Content-Encoding
  • Updates documentation to reflect additional supported content types for AutoFormat

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
req.go Modified Params() to copy strings when Immutable config is enabled, and updated Protocol() and Body() methods to use config-aware string getters
ctx_test.go Added test case to verify Params() creates independent memory copies under Immutable config
res_interface_gen.go Updated AutoFormat documentation to include additional supported content types
ctx_interface_gen.go Updated AutoFormat documentation to include additional supported content types

Copy link
Contributor

@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: 0

♻️ Duplicate comments (1)
ctx_test.go (1)

3115-3131: Test is correct; consider table-driven to cover mutable as well

Good coverage for Immutable=true. Suggest converting to a table-driven test to also assert the mutable behavior (Immutable=false yields “paul” after mutation).

-func Test_Ctx_Params_Immutable(t *testing.T) {
-	t.Parallel()
-	app := New(Config{Immutable: true})
-	c := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck,forcetypeassert // not needed
-
-	c.route = &Route{Params: []string{"user"}}
-	c.path = []byte("/test/john")
-	c.values[0] = utils.UnsafeString(c.path[6:])
-
-	param := c.Params("user")
-	c.path[6] = 'p'
-	c.path[7] = 'a'
-	c.path[8] = 'u'
-	c.path[9] = 'l'
-
-	require.Equal(t, "john", param)
-}
+func Test_Ctx_Params_Immutable(t *testing.T) {
+	t.Parallel()
+	tests := []struct {
+		name      string
+		immutable bool
+		expected  string
+	}{
+		{name: "immutable", immutable: true, expected: "john"},
+		{name: "mutable", immutable: false, expected: "paul"},
+	}
+	for _, tt := range tests {
+		tt := tt
+		t.Run(tt.name, func(t *testing.T) {
+			t.Parallel()
+			app := New(Config{Immutable: tt.immutable})
+			c := app.AcquireCtx(&fasthttp.RequestCtx{}).(*DefaultCtx) //nolint:errcheck,forcetypeassert
+			defer app.ReleaseCtx(c)
+
+			c.route = &Route{Params: []string{"user"}}
+			c.path = []byte("/test/john")
+			c.values[0] = utils.UnsafeString(c.path[6:])
+
+			param := c.Params("user")
+			c.path[6] = 'p'
+			c.path[7] = 'a'
+			c.path[8] = 'u'
+			c.path[9] = 'l'
+
+			require.Equal(t, tt.expected, param)
+		})
+	}
+}
🧹 Nitpick comments (2)
req.go (2)

150-152: Redundant lowercasing pass on encodings

headerEncoding is already lowercased before splitting. Lowercasing each token again is redundant and adds overhead.

Apply this diff to drop the extra pass:

- for i := range encodingOrder {
- 	encodingOrder[i] = utils.ToLower(encodingOrder[i])
- }

583-587: Params respects Immutable — good; minor nit to reuse local app

Returning a copied param when Immutable is enabled is the right fix. You can reuse the app local var instead of calling r.App() again.

-			val := values[i]
-			if r.App().config.Immutable {
+			val := values[i]
+			if app.config.Immutable {
 				return utils.CopyString(val)
 			}
 			return val
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9ca6ebd and fb5ff89.

📒 Files selected for processing (4)
  • ctx_interface_gen.go (1 hunks)
  • ctx_test.go (1 hunks)
  • req.go (3 hunks)
  • res_interface_gen.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ctx_test.go (3)
ctx.go (5)
  • DefaultCtx (47-67)
  • DefaultCtx (116-118)
  • DefaultCtx (128-130)
  • DefaultCtx (140-142)
  • DefaultCtx (304-306)
router.go (1)
  • Route (43-62)
req.go (1)
  • Params (608-614)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: repeated
  • GitHub Check: Compare
🔇 Additional comments (5)
res_interface_gen.go (1)

47-47: Doc update LGTM

Expanding the supported content types list is accurate and consistent with the codebase.

ctx_interface_gen.go (1)

323-323: Doc update LGTM

AutoFormat’s supported content types list looks correct and matches Res interface docs.

req.go (2)

140-142: Use of config-aware getter + normalization is correct

Switching to App.getString(...) and lowercasing the Content-Encoding header improves consistency with Immutable semantics and avoids unsafe conversions.


658-659: Protocol uses App.getString — good

Switching to the config-aware getter aligns with the Immutable strategy and avoids unsafe conversions.

ctx_test.go (1)

3115-3131: No duplicate Test_Ctx_Params_Immutable found — resolved

Ripgrep across the repository returned a single match at ctx_test.go:3115, so there is no duplicate test definition to remove.

  • Location: ctx_test.go:3115 — func Test_Ctx_Params_Immutable(t *testing.T) { }

@gaby gaby changed the title 🧹 chore: Respect immutable config in params() and protocol() 🧹 chore: Respect immutable config in Params(), Protocol(), and Body() Aug 11, 2025
Copy link
Member

@ReneWerner87 ReneWerner87 left a comment

Choose a reason for hiding this comment

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

@codecov
Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.85%. Comparing base (77667e5) to head (f21b54c).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3676   +/-   ##
=======================================
  Coverage   91.85%   91.85%           
=======================================
  Files         113      113           
  Lines       11453    11457    +4     
=======================================
+ Hits        10520    10524    +4     
  Misses        669      669           
  Partials      264      264           
Flag Coverage Δ
unittests 91.85% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.

Benchmark suite Current: f21b54c Previous: 77667e5 Ratio
Benchmark_Ctx_Protocol 4.362 ns/op 0 B/op 0 allocs/op 2.49 ns/op 0 B/op 0 allocs/op 1.75
Benchmark_Ctx_Protocol - ns/op 4.362 ns/op 2.49 ns/op 1.75

This comment was automatically generated by workflow using github-action-benchmark.

@ReneWerner87 ReneWerner87 merged commit e7b0508 into main Aug 11, 2025
14 of 15 checks passed
@ReneWerner87 ReneWerner87 deleted the 2025-08-11-00-12-44 branch August 11, 2025 13:12
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants