Skip to content

Conversation

nastik-kum
Copy link

@nastik-kum nastik-kum commented Jun 30, 2025

References to other Issues or PRs

The PR is related to Issue #3700

Have you read the Contributing Guidelines?

Yes

Brief description of what is fixed or changed

Now http.Request has the Pattern field set. httpServeMux does this and other libraries make use of this value. Now runtime.ServeMux also populates this field.

Other comments

A bit more context in the comment

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, but this seems to me like it will break existing users, no?

@@ -532,6 +532,7 @@ type handler struct {
}

func (s *ServeMux) handleHandler(h handler, w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
r.Pattern = h.pat.GetPathPattern()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't this going to overwrite the Pattern set by net/http? What about users who use r.Pattern today?

Copy link
Author

Choose a reason for hiding this comment

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

This field is only set once by the ServeMux at this line. If grpc-gateway’s ServeMux doesn’t set the r.Pattern field, it will remain unset — nothing else will populate it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic runs after the net/http ServeMux logic that sets the field, so this will overwrite the field, correct? We may thus change what's written to this field for existing users who uses the existing field value for their own logic. That would constitute a breaking change in behavior, no?

Copy link
Author

Choose a reason for hiding this comment

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

Currently this field is not set, that's why I've even created this PR. Maybe I've missed the thing: could you explain when net/http.ServeMux is called?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We are not calling it explicitly, but since our ServeMux type is a http.Handler, we can expect users to use a http.ServeMux with the gateway as a parameter:

mux := http.NewServeMux()
mux.Handle("/api", gwMux)
// Now each API call goes through the http ServeMux and will have the `r.Pattern` populated.

In this case, this change will break any users who is using the pattern today, I think? Could you test this?

@@ -532,6 +532,7 @@ type handler struct {
}

func (s *ServeMux) handleHandler(h handler, w http.ResponseWriter, r *http.Request, pathParams map[string]string) {
r.Pattern = h.pat.GetPathPattern()
Copy link
Collaborator

Choose a reason for hiding this comment

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

This logic runs after the net/http ServeMux logic that sets the field, so this will overwrite the field, correct? We may thus change what's written to this field for existing users who uses the existing field value for their own logic. That would constitute a breaking change in behavior, no?

"google.golang.org/grpc/grpclog"

"github.com/grpc-ecosystem/grpc-gateway/v2/utilities"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Revert this change please, we use two import groups

Copy link
Author

Choose a reason for hiding this comment

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

Done, please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants