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
a197c864
Commit
a197c864
authored
Jul 27, 2017
by
Sergey Frolov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move fallbackHosts to vhostTrie
parent
4991d702
Changes
3
Hide 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 @
a197c864
...
@@ -57,6 +57,16 @@ func makeTLSConfig(group []*SiteConfig) (*tls.Config, error) {
...
@@ -57,6 +57,16 @@ func makeTLSConfig(group []*SiteConfig) (*tls.Config, error) {
return
caddytls
.
MakeTLSConfig
(
tlsConfigs
)
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
// NewServer creates a new Server instance that will listen on addr
// and will serve the sites configured in group.
// and will serve the sites configured in group.
func
NewServer
(
addr
string
,
group
[]
*
SiteConfig
)
(
*
Server
,
error
)
{
func
NewServer
(
addr
string
,
group
[]
*
SiteConfig
)
(
*
Server
,
error
)
{
...
@@ -66,6 +76,7 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
...
@@ -66,6 +76,7 @@ func NewServer(addr string, group []*SiteConfig) (*Server, error) {
sites
:
group
,
sites
:
group
,
connTimeout
:
GracefulTimeout
,
connTimeout
:
GracefulTimeout
,
}
}
s
.
vhosts
.
fallbackHosts
=
append
(
s
.
vhosts
.
fallbackHosts
,
getFallbacks
(
group
)
...
)
s
.
Server
=
makeHTTPServerWithHeaderLimit
(
s
.
Server
,
group
)
s
.
Server
=
makeHTTPServerWithHeaderLimit
(
s
.
Server
,
group
)
s
.
Server
.
Handler
=
s
// this is weird, but whatever
s
.
Server
.
Handler
=
s
// this is weird, but whatever
...
...
caddyhttp/httpserver/siteconfig.go
View file @
a197c864
...
@@ -52,6 +52,9 @@ type SiteConfig struct {
...
@@ -52,6 +52,9 @@ type SiteConfig struct {
// preserving functionality needed for proxying,
// preserving functionality needed for proxying,
// websockets, etc.
// websockets, etc.
Timeouts
Timeouts
Timeouts
Timeouts
// If true all unmatched requests will be served by this site
FallbackSite
bool
}
}
// Timeouts specify various timeouts for a server to use.
// Timeouts specify various timeouts for a server to use.
...
...
caddyhttp/httpserver/vhosttrie.go
View file @
a197c864
...
@@ -10,14 +10,15 @@ import (
...
@@ -10,14 +10,15 @@ import (
// wildcards as TLS certificates support them), then
// wildcards as TLS certificates support them), then
// by longest matching path.
// by longest matching path.
type
vhostTrie
struct
{
type
vhostTrie
struct
{
edges
map
[
string
]
*
vhostTrie
fallbackHosts
[]
string
site
*
SiteConfig
// site to match on this node; also known as a virtual host
edges
map
[
string
]
*
vhostTrie
path
string
// the path portion of the key for the associated site
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
}
}
// newVHostTrie returns a new vhostTrie.
// newVHostTrie returns a new vhostTrie.
func
newVHostTrie
()
*
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
// 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
...
@@ -45,12 +46,6 @@ func (t *vhostTrie) insertPath(remainingPath, originalPath string, site *SiteCon
t
.
edges
[
ch
]
.
insertPath
(
remainingPath
[
1
:
],
originalPath
,
site
)
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
// Match returns the virtual host (site) in v with
// the closest match to key. If there was a match,
// the closest match to key. If there was a match,
// it returns the SiteConfig and the path portion of
// it returns the SiteConfig and the path portion of
...
@@ -65,7 +60,7 @@ func (t *vhostTrie) Match(key string) (*SiteConfig, string) {
...
@@ -65,7 +60,7 @@ func (t *vhostTrie) Match(key string) (*SiteConfig, string) {
host
,
path
:=
t
.
splitHostPath
(
key
)
host
,
path
:=
t
.
splitHostPath
(
key
)
// try the given host, then, if no match, try fallback hosts
// try the given host, then, if no match, try fallback hosts
branch
:=
t
.
matchHost
(
host
)
branch
:=
t
.
matchHost
(
host
)
for
_
,
h
:=
range
F
allbackHosts
{
for
_
,
h
:=
range
t
.
f
allbackHosts
{
if
branch
!=
nil
{
if
branch
!=
nil
{
break
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