Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
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
Łukasz Nowak
caddy
Commits
32ec39cd
Commit
32ec39cd
authored
Jul 27, 2017
by
Matt Holt
Committed by
GitHub
Jul 27, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1784 from mholt/trie-fallbacks
Move fallbackHosts to vhostTrie
parents
4991d702
a197c864
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
11 deletions
+20
-11
caddyhttp/httpserver/server.go
caddyhttp/httpserver/server.go
+11
-0
caddyhttp/httpserver/siteconfig.go
caddyhttp/httpserver/siteconfig.go
+3
-0
caddyhttp/httpserver/vhosttrie.go
caddyhttp/httpserver/vhosttrie.go
+6
-11
No files found.
caddyhttp/httpserver/server.go
View file @
32ec39cd
...
...
@@ -57,6 +57,16 @@ func makeTLSConfig(group []*SiteConfig) (*tls.Config, error) {
return
caddytls
.
MakeTLSConfig
(
tlsConfigs
)
}
func
getFallbacks
(
sites
[]
*
SiteConfig
)
[]
string
{
fallbacks
:=
[]
string
{}
for
_
,
sc
:=
range
sites
{
if
sc
.
FallbackSite
{
fallbacks
=
append
(
fallbacks
,
sc
.
Addr
.
Host
)
}
}
return
fallbacks
}
// NewServer creates a new Server instance that will listen on addr
// and will serve the sites configured in group.
func
NewServer
(
addr
string
,
group
[]
*
SiteConfig
)
(
*
Server
,
error
)
{
...
...
@@ -66,6 +76,7 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
sites
:
group
,
connTimeout
:
GracefulTimeout
,
}
s
.
vhosts
.
fallbackHosts
=
append
(
s
.
vhosts
.
fallbackHosts
,
getFallbacks
(
group
)
...
)
s
.
Server
=
makeHTTPServerWithHeaderLimit
(
s
.
Server
,
group
)
s
.
Server
.
Handler
=
s
// this is weird, but whatever
...
...
caddyhttp/httpserver/siteconfig.go
View file @
32ec39cd
...
...
@@ -52,6 +52,9 @@ type SiteConfig struct {
// preserving functionality needed for proxying,
// websockets, etc.
Timeouts
Timeouts
// If true all unmatched requests will be served by this site
FallbackSite
bool
}
// Timeouts specify various timeouts for a server to use.
...
...
caddyhttp/httpserver/vhosttrie.go
View file @
32ec39cd
...
...
@@ -10,6 +10,7 @@ import (
// wildcards as TLS certificates support them), then
// by longest matching path.
type
vhostTrie
struct
{
fallbackHosts
[]
string
edges
map
[
string
]
*
vhostTrie
site
*
SiteConfig
// site to match on this node; also known as a virtual host
path
string
// the path portion of the key for the associated site
...
...
@@ -17,7 +18,7 @@ type vhostTrie struct {
// newVHostTrie returns a new vhostTrie.
func
newVHostTrie
()
*
vhostTrie
{
return
&
vhostTrie
{
edges
:
make
(
map
[
string
]
*
vhostTrie
)}
return
&
vhostTrie
{
edges
:
make
(
map
[
string
]
*
vhostTrie
)
,
fallbackHosts
:
[]
string
{
"0.0.0.0"
,
""
}
}
}
// Insert adds stack to t keyed by key. The key should be
...
...
@@ -45,12 +46,6 @@ func (t *vhostTrie) insertPath(remainingPath, originalPath string, site *SiteCon
t
.
edges
[
ch
]
.
insertPath
(
remainingPath
[
1
:
],
originalPath
,
site
)
}
// When matching a site, the given host will be tried first.
// Then, FallbackHosts will be tried in order.
// Default FallbackHosts are following wildcards,
// which could be modified by plugins and directives.
var
FallbackHosts
=
[]
string
{
"0.0.0.0"
,
""
}
// Match returns the virtual host (site) in v with
// the closest match to key. If there was a match,
// it returns the SiteConfig and the path portion of
...
...
@@ -65,7 +60,7 @@ func (t *vhostTrie) Match(key string) (*SiteConfig, string) {
host
,
path
:=
t
.
splitHostPath
(
key
)
// try the given host, then, if no match, try fallback hosts
branch
:=
t
.
matchHost
(
host
)
for
_
,
h
:=
range
F
allbackHosts
{
for
_
,
h
:=
range
t
.
f
allbackHosts
{
if
branch
!=
nil
{
break
}
...
...
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