Skip to content

Conversation

@gaby
Copy link
Member

@gaby gaby commented Oct 1, 2025

Summary

  • add client and request options to disable path normalizing and plumb them through request configuration
  • update URL parsing to preserve encoded paths when normalization is disabled and add regression tests

Fixes #3096

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 1, 2025

Walkthrough

Adds a client- and request-level disablePathNormalizing flag, propagates it via Config into Request construction and hooks, applies the effective setting to RawRequest.URI (optionally forcing PathBytes = PathOriginal), resets flags on Reset, and adds tests ensuring pre-encoded paths are preserved when normalization is disabled.

Changes

Cohort / File(s) Summary
Client API: path normalizing flag
client/client.go
Adds unexported disablePathNormalizing to Client, public accessors DisablePathNormalizing() and SetDisablePathNormalizing(bool) *Client, adds DisablePathNormalizing bool to Config, propagates config to requests, and resets the flag in Reset().
Request API: path normalizing flag
client/request.go
Adds internal disablePathNormalizing on Request, public DisablePathNormalizing() getter and SetDisablePathNormalizing(bool) *Request setter that updates the underlying RawRequest.URI(); Reset() clears the flag.
Hook control flow for path handling
client/hooks.go
Computes effective disablePathNormalizing from client + request, assigns it to RawRequest.URI().DisablePathNormalizing, and when true forces PathBytes = PathOriginal to avoid path normalization.
Tests: path normalization behavior
client/hooks_test.go
Adds subtests asserting that request- and client-level disabling preserves the original, already-encoded URL in RawRequest.URI().String() (i.e., no normalization occurs).

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant C as Client
  participant R as Request
  participant H as Hooks
  participant U as RawRequest.URI

  Note over C,R: Request creation and config application
  C->>R: apply Config (may call r.SetDisablePathNormalizing(true))
  C->>H: Build request
  H->>R: read r.DisablePathNormalizing()
  H->>C: read c.DisablePathNormalizing()
  H->>H: effective = c || r
  H->>U: set U.DisablePathNormalizing = effective
  alt effective == true
    H->>U: set U.PathBytes = U.PathOriginal (preserve encoding)
  else
    H->>U: allow default path normalization
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • sixcolors
  • efectn
  • ReneWerner87

Poem

I hop through paths, percent signs bright,
I guard each % and keep it tight.
One toggle stops the nibbling spree,
Encoded carrots stay with me.
A rabbit's promise: bytes stay right. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The provided description gives a brief summary of added options and regression tests and references the linked issue, but it does not follow the repository’s required template. It is missing the “## Changes introduced” section with checklist items, the “Type of change” classification, and the mandatory checklist for documentation, testing, and performance considerations. Consequently, it lacks essential structure and detail expected by the template for clarity and completeness. Please update the pull request description to include all sections from the repository template, including “## Changes introduced” with the checklist items, the “Type of change” section, and the full compliance checklist to ensure consistency and comprehensive documentation of the changes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the primary change by indicating that the DisablePathNormalizing flag will now be respected in client requests, directly reflecting the core functionality added in the changeset. It avoids vague or generic phrasing by naming the specific feature being fixed, making its purpose immediately obvious to reviewers. Although it includes an emoji which is unnecessary noise, the title remains concise and focused on the main enhancement.
Linked Issues Check ✅ Passed The code adds client-level and request-level DisablePathNormalizing flags, propagates them through configuration, adjusts URL parsing logic to preserve percent-encoded paths when the flag is set, and includes regression tests verifying both client and request behaviors. These modifications directly satisfy all objectives from issue #3096 by exposing the necessary configuration, ensuring the flag prevents path normalization, and preserving encoded segments as intended.
Out of Scope Changes Check ✅ Passed All altered files and code paths pertain exclusively to the disable-path-normalization feature and its tests, with no modifications outside the scope of preserving encoded URL segments and respecting the new configuration flags. There are no unrelated changes or additional features introduced beyond the objectives defined in the linked issue.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-url-encoding-issue-in-requests

📜 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 42c4309 and adeeabe.

📒 Files selected for processing (1)
  • client/client.go (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • client/client.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: repeated
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: unit (1.25.x, macos-13)
  • GitHub Check: Compare

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 and usage tips.

@gaby gaby changed the title Respect DisablePathNormalizing when building client request URLs 🐛 bug: Respect DisablePathNormalizing when building client request URLs Oct 1, 2025
@gaby gaby changed the title 🐛 bug: Respect DisablePathNormalizing when building client request URLs 🐛 bug: Respect DisablePathNormalizing during client requests Oct 1, 2025
@codecov
Copy link

codecov bot commented Oct 1, 2025

Codecov Report

❌ Patch coverage is 80.95238% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.62%. Comparing base (b25339d) to head (adeeabe).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
client/client.go 55.55% 3 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3773      +/-   ##
==========================================
- Coverage   91.70%   91.62%   -0.08%     
==========================================
  Files         113      113              
  Lines       11940    11959      +19     
==========================================
+ Hits        10949    10958       +9     
- Misses        728      736       +8     
- Partials      263      265       +2     
Flag Coverage Δ
unittests 91.62% <80.95%> (-0.08%) ⬇️

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.

@gaby gaby added this to v3 Oct 1, 2025
@gaby gaby added this to the v3 milestone Oct 1, 2025
@gaby gaby moved this to In Progress in v3 Oct 1, 2025
@gaby gaby marked this pull request as ready for review October 1, 2025 07:09
@gaby gaby requested a review from a team as a code owner October 1, 2025 07:09
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 implements support for disabling path normalization during client requests to preserve encoded paths in URLs. This addresses issue #3096 where encoded characters in URL paths were being unintentionally normalized.

  • Adds disablePathNormalizing fields to both Client and Request structs with corresponding getter/setter methods
  • Updates URL parsing logic to respect the disable path normalizing setting and preserve original encoded paths
  • Includes comprehensive test coverage for both client-level and request-level path normalization control

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
client/client.go Adds disablePathNormalizing field to Client struct with getter/setter methods and Config support
client/request.go Adds disablePathNormalizing field to Request struct with getter/setter methods and Reset handling
client/hooks.go Updates URL parsing logic to check and respect path normalization settings
client/hooks_test.go Adds regression tests for both client and request level path normalization control

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b25339d and 974d2d4.

📒 Files selected for processing (4)
  • client/client.go (5 hunks)
  • client/hooks.go (1 hunks)
  • client/hooks_test.go (1 hunks)
  • client/request.go (3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Format Go code using gofumpt (enforced via make format)
Ensure code passes golangci-lint checks (enforced via make lint)
Optimize struct field alignment using betteralign (enforced via make betteralign)
Modernize Go code using gopls modernize (enforced via make modernize)

Files:

  • client/hooks.go
  • client/request.go
  • client/hooks_test.go
  • client/client.go
🧬 Code graph analysis (1)
client/hooks_test.go (2)
client/client.go (1)
  • New (651-656)
client/request.go (2)
  • AcquireRequest (980-986)
  • ReleaseRequest (990-993)
🪛 GitHub Actions: golangci-lint
client/client.go

[error] 32-32: golangci-lint: govet: fieldalignment: struct of size 312 could be 304

⏰ 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 (8)
client/hooks_test.go (1)

211-240: LGTM! Comprehensive test coverage for path normalization control.

The two test cases effectively verify that DisablePathNormalizing works at both the request and client levels, ensuring percent-encoded characters (like %2F and %23) are preserved when normalization is disabled.

client/client.go (4)

358-367: LGTM! API follows established patterns.

The getter/setter methods are consistent with other client options like Debug()/DisableDebug() and follow the builder pattern correctly.


545-545: LGTM! Reset behavior is correct.

The flag is properly reset to false in the Reset() method, ensuring clean state when the client is reused.


574-574: LGTM! Config field follows naming conventions.

The field name and placement in the Config struct are consistent with other configuration options.


620-622: LGTM! Config propagation is correct.

The logic correctly propagates the DisablePathNormalizing flag from Config to the request when set to true, consistent with how other boolean config options are handled.

client/hooks.go (1)

96-101: LGTM! Combined flag logic and path preservation are correct.

The implementation correctly:

  1. Combines client and request-level flags using OR logic (either disables normalization)
  2. Applies the flag to the underlying fasthttp.Request.URI()
  3. Preserves the original encoded path by setting PathBytes to PathOriginal() when normalization is disabled

The order of operations is correct: first parse the URI with SetRequestURI, then override the path to preserve encoding when needed.

client/request.go (2)

610-620: LGTM! Request-level API is consistent and correct.

The getter/setter methods follow the same pattern as the client-level API. Setting RawRequest.URI().DisablePathNormalizing in the setter ensures the flag is propagated early, which is then reinforced by the hooks logic. This redundancy is safe and ensures consistency.


688-688: LGTM! Reset behavior is correct.

The flag is properly cleared when the request is recycled, ensuring clean state for pooled objects.

@ReneWerner87
Copy link
Member

@gaby can you check liniting

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: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 974d2d4 and 42c4309.

📒 Files selected for processing (1)
  • client/client.go (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Format Go code using gofumpt (enforced via make format)
Ensure code passes golangci-lint checks (enforced via make lint)
Optimize struct field alignment using betteralign (enforced via make betteralign)
Modernize Go code using gopls modernize (enforced via make modernize)

Files:

  • client/client.go
🧬 Code graph analysis (1)
client/client.go (1)
client/request.go (3)
  • Cookie (775-775)
  • PathParam (823-823)
  • File (929-934)
🪛 GitHub Actions: golangci-lint
client/client.go

[error] 58-58: golangci-lint: File is not properly formatted (gofmt).

⏰ 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: Compare
  • GitHub Check: unit (1.25.x, macos-13)
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: repeated
🔇 Additional comments (5)
client/client.go (5)

357-360: LGTM!

The getter method correctly returns the path normalizing flag and follows the established pattern for client configuration accessors.


560-574: LGTM!

The DisablePathNormalizing field addition to the Config struct is correctly typed and positioned, enabling request-level control over path normalization.


619-621: Verify one-way override behavior is intentional.

The logic only propagates DisablePathNormalizing when true, meaning a request cannot re-enable path normalization if the client has it disabled. Confirm this one-way override aligns with the intended API semantics.


544-544: LGTM!

Correctly resets the path normalizing flag to its default state during client reset.


362-366: Thread-safety consistent with existing simple setters. SetDisablePathNormalizing follows the established pattern of one-time boolean configuration during client initialization and isn’t modified concurrently. No mutex required.

@gaby
Copy link
Member Author

gaby commented Oct 1, 2025

@ReneWerner87 Should be good now

@ReneWerner87 ReneWerner87 merged commit a3c54bb into main Oct 1, 2025
18 of 20 checks passed
@ReneWerner87 ReneWerner87 deleted the fix-url-encoding-issue-in-requests branch October 1, 2025 19:02
@github-project-automation github-project-automation bot moved this from In Progress to Done in v3 Oct 1, 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.

🤗 [Question]: Is there any way to avoid parsing URLEncoded on Agent?

3 participants