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

contrib/dimfeld/httptreemux.v5: fix route and name for 30X redirects #2685

Merged
merged 6 commits into from May 8, 2024

Conversation

darccio
Copy link
Contributor

@darccio darccio commented May 8, 2024

The httptreemux router has a redirect behaviour that is invoked when
a request URL and matched route only differs in a trailing slash. The
default behaviour is to respond with a 301 (moved permanently) to
redirect the client to the exact path of the matched handler. We
previously patched one of the two scenarios where this occurs in #2332.
The changes in this commit addresses the other scenario for the 301
redirect, but also the 307 and 308 redirect options. Several tests
were included to cover the various scenarios.

We also standardize the resource name in the event that there is a
trailing slash missmatch between request URL and matched handler. We
always truncate the trailing slash in the resource name.

Fixes #2663<!--

  • New contributors are highly encouraged to read our
    CONTRIBUTING documentation.
  • Commit and PR titles should be prefixed with the general area of the pull request's change.

-->

What does this PR do?

Motivation

Reviewer's Checklist

  • Changed code has unit tests for its functionality at or near 100% coverage.
  • System-Tests covering this feature have been added and enabled with the va.b.c-dev version tag.
  • There is a benchmark for any new code, or changes to existing code.
  • If this interacts with the agent in a new way, a system test has been added.
  • Add an appropriate team label so this PR gets put in the right place for the release notes.
  • Non-trivial go.mod changes, e.g. adding new modules, are reviewed by @DataDog/dd-trace-go-guild.

Unsure? Have a question? Request a review!

devillecodes and others added 5 commits April 25, 2024 11:01
The httptreemux router has a redirect behaviour that is invoked when
a request URL and matched route only differs in a trailing slash. The
default behaviour is to respond with a 301 (moved permanently) to
redirect the client to the exact path of the matched handler. We
previously patched one of the two scenarios where this occurs in #2332.
The changes in this commit addresses the other scenario for the 301
redirect, but also the 307 and 308 redirect options. Several tests
were included to cover the various scenarios.

We also standardize the resource name in the event that there is a
trailing slash missmatch between request URL and matched handler. We
always truncate the trailing slash in the resource name.

Fixes #2663
Simplied the unnecessarily verbose function comments of
isSupportedRedirectStatus and routerRedirectEnabled.
The new tests added to assert the redirect behaviour for
the four redirect modes supported by the router had
redundant test cases.

These test cases were reduced down to three scenarios per
redirect mode:
1. path not found
2. path with parameterized URL excluding a trailing slash
3. path with parameterized URL inclduing a trailing slash
When handling the supported redirect modes of the router
we were incorrectly trimming trailing slashes from the
route path matched by the router. The previous behaviour
is restored where we return the exact path matched by
the router.
@github-actions github-actions bot added the apm:ecosystem contrib/* related feature requests or bugs label May 8, 2024
@pr-commenter
Copy link

pr-commenter bot commented May 8, 2024

Benchmarks

Benchmark execution time: 2024-05-08 09:40:44

Comparing candidate commit b6005af in PR branch dario.castane/tmp-2664-check with baseline commit 3a426ca in branch main.

Found 0 performance improvements and 0 performance regressions! Performance is the same for 44 metrics, 0 unstable metrics.

The old image has been unpublished in Docker Hub.
@darccio darccio changed the title contrib/dimfeld/httptreemux.v5: fix route and name for 30X redirects [CI] contrib/dimfeld/httptreemux.v5: fix route and name for 30X redirects May 8, 2024
@darccio darccio marked this pull request as ready for review May 8, 2024 13:53
@darccio darccio requested review from a team as code owners May 8, 2024 13:53
@darccio darccio requested a review from rarguelloF May 8, 2024 13:53
@darccio darccio changed the title [CI] contrib/dimfeld/httptreemux.v5: fix route and name for 30X redirects contrib/dimfeld/httptreemux.v5: fix route and name for 30X redirects May 8, 2024
@darccio darccio merged commit 7f6597f into main May 8, 2024
160 checks passed
@darccio darccio deleted the dario.castane/tmp-2664-check branch May 8, 2024 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] contrib/dimfeld/httptreemux.v5: trailing slash requests are redirected with raw URL being tracked
3 participants