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

WithContext breaks mux.Vars #766

Closed
1 task done
PhillipWhillier opened this issue Aug 3, 2024 · 2 comments
Closed
1 task done

WithContext breaks mux.Vars #766

PhillipWhillier opened this issue Aug 3, 2024 · 2 comments
Labels

Comments

@PhillipWhillier
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

When the WithContext is used the mux.Vars are unavailable in the route handler.

github.com/gorilla/mux v1.8.1

Expected Behavior

When the WithContext is used the mux.Vars are available in the route handler.

github.com/gorilla/mux v1.8.1

Steps To Reproduce

// Store the username in the context
ctx := context.WithValue(context.Background(), "username", claims.Username)
requestWithContext := request.WithContext(ctx)

// Update handles PUT requests to update an existing Item
func (this *ItemController) Update(response http.ResponseWriter, request *http.Request) {

vars := mux.Vars(request)
uuid := vars["uuid"]

Anything else?

No response

@guidog
Copy link

guidog commented Aug 6, 2024

One should use context coming w/ the request as base for WithContext. context.Background() returns an empty context, so all information already in the request context is lost.

@PhillipBSDL
Copy link

That's great, thanks for the tip, it works now

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

No branches or pull requests

4 participants