Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
c238031b
Commit
c238031b
authored
May 28, 2012
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
net/http: speed up ServeMux when no patterns contain hostnames
R=golang-dev, r CC=golang-dev
https://golang.org/cl/6248053
parent
469e3a91
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
4 deletions
+11
-4
src/pkg/net/http/server.go
src/pkg/net/http/server.go
+11
-4
No files found.
src/pkg/net/http/server.go
View file @
c238031b
...
@@ -840,8 +840,9 @@ func RedirectHandler(url string, code int) Handler {
...
@@ -840,8 +840,9 @@ func RedirectHandler(url string, code int) Handler {
// redirecting any request containing . or .. elements to an
// redirecting any request containing . or .. elements to an
// equivalent .- and ..-free URL.
// equivalent .- and ..-free URL.
type
ServeMux
struct
{
type
ServeMux
struct
{
mu
sync
.
RWMutex
mu
sync
.
RWMutex
m
map
[
string
]
muxEntry
m
map
[
string
]
muxEntry
hosts
bool
// whether any patterns contain hostnames
}
}
type
muxEntry
struct
{
type
muxEntry
struct
{
...
@@ -903,12 +904,14 @@ func (mux *ServeMux) match(path string) Handler {
...
@@ -903,12 +904,14 @@ func (mux *ServeMux) match(path string) Handler {
}
}
// handler returns the handler to use for the request r.
// handler returns the handler to use for the request r.
func
(
mux
*
ServeMux
)
handler
(
r
*
Request
)
Handler
{
func
(
mux
*
ServeMux
)
handler
(
r
*
Request
)
(
h
Handler
)
{
mux
.
mu
.
RLock
()
mux
.
mu
.
RLock
()
defer
mux
.
mu
.
RUnlock
()
defer
mux
.
mu
.
RUnlock
()
// Host-specific pattern takes precedence over generic ones
// Host-specific pattern takes precedence over generic ones
h
:=
mux
.
match
(
r
.
Host
+
r
.
URL
.
Path
)
if
mux
.
hosts
{
h
=
mux
.
match
(
r
.
Host
+
r
.
URL
.
Path
)
}
if
h
==
nil
{
if
h
==
nil
{
h
=
mux
.
match
(
r
.
URL
.
Path
)
h
=
mux
.
match
(
r
.
URL
.
Path
)
}
}
...
@@ -950,6 +953,10 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
...
@@ -950,6 +953,10 @@ func (mux *ServeMux) Handle(pattern string, handler Handler) {
mux
.
m
[
pattern
]
=
muxEntry
{
explicit
:
true
,
h
:
handler
}
mux
.
m
[
pattern
]
=
muxEntry
{
explicit
:
true
,
h
:
handler
}
if
pattern
[
0
]
!=
'/'
{
mux
.
hosts
=
true
}
// Helpful behavior:
// Helpful behavior:
// If pattern is /tree/, insert an implicit permanent redirect for /tree.
// If pattern is /tree/, insert an implicit permanent redirect for /tree.
// It can be overridden by an explicit registration.
// It can be overridden by an explicit registration.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment