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

wfe: use wildcard patterns in HTTP handlers #7791

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

jsha
Copy link
Contributor

@jsha jsha commented Nov 7, 2024

Previously, we manually parsed path components. As of Go 1.22, we can include wildcards in ServeMux patterns: https://pkg.go.dev/net/http#hdr-Patterns-ServeMux. This simplifies our parsing code a little bit.

To get the values of such wildcards, we use request.PathValue. Our metrics/measured_http code interfered with setting those values, so I modified it. Instead of retrieving the handler for a given request, then calling it, we retrieve only the pattern matched by that request. Then we call .ServeHTTP() on the inner ServeMux.

(Needs unittest updates)

This allows us to take advantage of http.ServeMux's wildcard handling. If we
first retrieve the handler for a pattern, and then call it ourselves, the values
in `request.PathValue(...)` do not get filled.
@@ -421,33 +421,34 @@ func (wfe *WebFrontEndImpl) Handler(stats prometheus.Registerer, oTelHTTPOptions

// POSTable ACME endpoints
wfe.HandleFunc(m, newAcctPath, wfe.NewAccount, "POST")
wfe.HandleFunc(m, acctPath, wfe.Account, "POST")
wfe.HandleFunc(m, acctPath+"{acctID}", wfe.Account, "POST")
Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering why you didn't just change acctPath to include the pattern, but then I realized that we also use acctPath (and similar) as an argument to web.relativeEndpoint. Is there a reasonable way to update relativeEndpoint to take a pattern as input?

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