]> Cypherpunks repositories - gostls13.git/commit
net/http: ServeMux handles extended patterns
authorJonathan Amsterdam <jba@google.com>
Wed, 13 Sep 2023 16:02:38 +0000 (12:02 -0400)
committerJonathan Amsterdam <jba@google.com>
Wed, 13 Sep 2023 20:07:22 +0000 (20:07 +0000)
commit545e4f38e0c177484ffa409c2fa1265423a5855f
tree4382de1fef7abcc2ff9079a747eb8dd3227df47f
parentf7f266c88598398dcf32b448bcea2100e1702630
net/http: ServeMux handles extended patterns

Modify ServeMux to handle patterns with methods and wildcards.

Remove the map and list of patterns. Instead patterns
are registered and matched using a routing tree.

We also reorganize the code around "trailing-slash redirection,"
the feature whereby a trailing slash is added to a path
if it doesn't match an existing one. The existing code
checked the map of paths twice, but searching the tree
twice would be needlessly expensive. The rewrite
searches the tree once, and then again only if a
trailing-slash redirection is possible.

There are a few omitted features in this CL, indicated
with TODOs.

Change-Id: Ifaef59f6c8c7b7131dc4a5d0f101cc22887bdc74
Reviewed-on: https://go-review.googlesource.com/c/go/+/528039
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/server.go
src/net/http/server_test.go