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

feat(mux): support query string in path #3281

Merged

Conversation

x1unix
Copy link
Contributor

@x1unix x1unix commented Dec 5, 2024

This PR adds support for request URLs with query strings for p/demo/mux package.

Previously, mux.Router would fail to find a correct handler if request URL contains query string.

r := mux.NewRouter()
r.HandleFunc("hello", func (rw *mux.ResponseWriter, req *mux.Request) {
  ...
})

reqUrl := "hello?foo=bar"
r.Render(reqUrl) // Fails

This PR fixes this behavior and introduces a new mux.Request.RawPath field which contains a raw request path including query string.

The RawPath field is designed to be used for packages like p/demo/avl/pager to extract query params from a string.
The Path field, as before, contains just path segment of request, without query strings.

Contributors' checklist...
  • Added new tests, or not needed, or not feasible
  • Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory
  • Updated the official documentation or not needed
  • No breaking changes were made, or a BREAKING CHANGE: xxx message was included in the description
  • Added references to related issues and PRs
  • Provided any useful hints for running manual tests

CC @moul @thehowl @jeronimoalbi

@github-actions github-actions bot added the 🧾 package/realm Tag used for new Realms or Packages. label Dec 5, 2024
@x1unix x1unix force-pushed the devx/feature/mux-router-improvements branch from 9122063 to 5c3ee8a Compare December 5, 2024 23:23
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Dec 5, 2024

I'm a bot that assists the Gno Core team in maintaining this repository. My role is to ensure that contributors understand and follow our guidelines, helping to streamline the development process.

The following requirements must be fulfilled before a pull request can be merged.
Some requirement checks are automated and can be verified by the CI, while others need manual verification by a staff member.

These requirements are defined in this configuration file.

Automated Checks

🔴 Maintainers must be able to edit this pull request (more info)
🔴 The pull request head branch must be up-to-date with its base (more info)

Manual Checks

  • The pull request description provides enough details (checked by @leohhhn)
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 On every pull request

Then

🔴 Requirement not satisfied
└── 🔴 Maintainer can modify this pull request

The pull request head branch must be up-to-date with its base (more info)

If

🟢 Condition met
└── 🟢 On every pull request

Then

🔴 Requirement not satisfied
└── 🔴 Head branch (gnostudio:devx/feature/mux-router-improvements) is up to date with base (master): behind by 1 / ahead by 7

Manual Checks
The pull request description provides enough details

If

🟢 Condition met
└── 🟢 Not (🔴 Pull request author is a member of the team: core-contributors)

Can be checked by

  • team core-contributors

Copy link

codecov bot commented Dec 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@x1unix x1unix force-pushed the devx/feature/mux-router-improvements branch from 5c3ee8a to 3d8b706 Compare December 5, 2024 23:23
@moul moul requested review from moul and leohhhn December 6, 2024 07:44
Copy link
Member

@moul moul left a comment

Choose a reason for hiding this comment

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

LGTM

I still consider that we should rename p/mux into p/router; what do you think?

Edit: Never mind, I remember that I chose mux because it mimics the http.Mux object with the ResponseWriter. Let's keep it named mux for now, and we can eventually extract the router part into a minimal router package if you're only interested in pure parsing. This can be done later.

@Kouteki Kouteki added the in focus Core team is prioritizing this work label Dec 6, 2024
@x1unix x1unix force-pushed the devx/feature/mux-router-improvements branch from fcfa91c to 136df2a Compare December 6, 2024 19:42
Copy link
Contributor

@leohhhn leohhhn left a comment

Choose a reason for hiding this comment

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

I assume we will get some weird edge cases that fail; but this is an upgrade that is needed for multiple packages, so let's fix along the way.

@thehowl
Copy link
Member

thehowl commented Dec 7, 2024

related #2876

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Dec 7, 2024
@thehowl thehowl merged commit 3de2475 into gnolang:master Dec 7, 2024
103 of 104 checks passed
@thehowl thehowl deleted the devx/feature/mux-router-improvements branch December 7, 2024 21:31
omarsy pushed a commit to TERITORI/gno that referenced this pull request Dec 7, 2024
This PR adds support for request URLs with query strings for
`p/demo/mux` package.

Previously, `mux.Router` would fail to find a correct handler if request
URL contains query string.

```go
r := mux.NewRouter()
r.HandleFunc("hello", func (rw *mux.ResponseWriter, req *mux.Request) {
  ...
})

reqUrl := "hello?foo=bar"
r.Render(reqUrl) // Fails
```

This PR fixes this behavior and introduces a new `mux.Request.RawPath`
field which contains a raw request path including query string.

The `RawPath` field is designed to be used for packages like
`p/demo/avl/pager` to extract query params from a string.\
The `Path` field, as before, contains just path segment of request,
without query strings.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>


CC @moul @thehowl @jeronimoalbi

---------

Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: Morgan <[email protected]>
Villaquiranm pushed a commit to Villaquiranm/gno that referenced this pull request Dec 9, 2024
This PR adds support for request URLs with query strings for
`p/demo/mux` package.

Previously, `mux.Router` would fail to find a correct handler if request
URL contains query string.

```go
r := mux.NewRouter()
r.HandleFunc("hello", func (rw *mux.ResponseWriter, req *mux.Request) {
  ...
})

reqUrl := "hello?foo=bar"
r.Render(reqUrl) // Fails
```

This PR fixes this behavior and introduces a new `mux.Request.RawPath`
field which contains a raw request path including query string.

The `RawPath` field is designed to be used for packages like
`p/demo/avl/pager` to extract query params from a string.\
The `Path` field, as before, contains just path segment of request,
without query strings.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>


CC @moul @thehowl @jeronimoalbi

---------

Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: Morgan <[email protected]>
r3v4s pushed a commit to gnoswap-labs/gno that referenced this pull request Dec 10, 2024
This PR adds support for request URLs with query strings for
`p/demo/mux` package.

Previously, `mux.Router` would fail to find a correct handler if request
URL contains query string.

```go
r := mux.NewRouter()
r.HandleFunc("hello", func (rw *mux.ResponseWriter, req *mux.Request) {
  ...
})

reqUrl := "hello?foo=bar"
r.Render(reqUrl) // Fails
```

This PR fixes this behavior and introduces a new `mux.Request.RawPath`
field which contains a raw request path including query string.

The `RawPath` field is designed to be used for packages like
`p/demo/avl/pager` to extract query params from a string.\
The `Path` field, as before, contains just path segment of request,
without query strings.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>


CC @moul @thehowl @jeronimoalbi

---------

Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: Morgan <[email protected]>
@Kouteki Kouteki removed the in focus Core team is prioritizing this work label Dec 16, 2024
albttx pushed a commit that referenced this pull request Jan 10, 2025
This PR adds support for request URLs with query strings for
`p/demo/mux` package.

Previously, `mux.Router` would fail to find a correct handler if request
URL contains query string.

```go
r := mux.NewRouter()
r.HandleFunc("hello", func (rw *mux.ResponseWriter, req *mux.Request) {
  ...
})

reqUrl := "hello?foo=bar"
r.Render(reqUrl) // Fails
```

This PR fixes this behavior and introduces a new `mux.Request.RawPath`
field which contains a raw request path including query string.

The `RawPath` field is designed to be used for packages like
`p/demo/avl/pager` to extract query params from a string.\
The `Path` field, as before, contains just path segment of request,
without query strings.

<details><summary>Contributors' checklist...</summary>

- [x] Added new tests, or not needed, or not feasible
- [x] Provided an example (e.g. screenshot) to aid review or the PR is
self-explanatory
- [x] Updated the official documentation or not needed
- [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message
was included in the description
- [x] Added references to related issues and PRs
- [x] Provided any useful hints for running manual tests
</details>


CC @moul @thehowl @jeronimoalbi

---------

Co-authored-by: Leon Hudak <[email protected]>
Co-authored-by: Morgan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related 🧾 package/realm Tag used for new Realms or Packages.
Projects
Development

Successfully merging this pull request may close these issues.

7 participants