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
nexedi
caddy
Commits
e42c6ab5
Commit
e42c6ab5
authored
May 20, 2015
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Notice displayed if non-localhost hosts resolve to loopback
parent
9c039474
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
4 deletions
+17
-4
main.go
main.go
+17
-4
No files found.
main.go
View file @
e42c6ab5
...
@@ -71,7 +71,7 @@ func main() {
...
@@ -71,7 +71,7 @@ func main() {
// Start each server with its one or more configurations
// Start each server with its one or more configurations
for
addr
,
configs
:=
range
addresses
{
for
addr
,
configs
:=
range
addresses
{
s
,
err
:=
server
.
New
(
addr
,
configs
,
configs
[
0
]
.
TLS
.
Enabled
)
s
,
err
:=
server
.
New
(
addr
.
String
()
,
configs
,
configs
[
0
]
.
TLS
.
Enabled
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
...
@@ -89,12 +89,25 @@ func main() {
...
@@ -89,12 +89,25 @@ func main() {
for
_
,
config
:=
range
configs
{
for
_
,
config
:=
range
configs
{
fmt
.
Println
(
config
.
Address
())
fmt
.
Println
(
config
.
Address
())
}
}
for
addr
,
configs
:=
range
addresses
{
for
_
,
conf
:=
range
configs
{
if
addr
.
IP
.
IsLoopback
()
&&
!
isLocalhost
(
conf
.
Host
)
{
fmt
.
Printf
(
"Notice: %s is only accessible on this machine (%s)
\n
"
,
conf
.
Host
,
addr
.
IP
.
String
())
}
}
}
}
}
}
}
wg
.
Wait
()
wg
.
Wait
()
}
}
func
isLocalhost
(
s
string
)
bool
{
return
s
==
"localhost"
||
s
==
"::1"
||
strings
.
HasPrefix
(
s
,
"127."
)
}
// loadConfigs loads configuration from a file or stdin (piped).
// loadConfigs loads configuration from a file or stdin (piped).
// Configuration is obtained from one of three sources, tried
// Configuration is obtained from one of three sources, tried
// in this order: 1. -conf flag, 2. stdin, 3. Caddyfile.
// in this order: 1. -conf flag, 2. stdin, 3. Caddyfile.
...
@@ -146,8 +159,8 @@ func loadConfigs() ([]server.Config, error) {
...
@@ -146,8 +159,8 @@ func loadConfigs() ([]server.Config, error) {
// be grouped into the same address: 127.0.0.1. It will return an error
// be grouped into the same address: 127.0.0.1. It will return an error
// if the address lookup fails or if a TLS listener is configured on the
// if the address lookup fails or if a TLS listener is configured on the
// same address as a plaintext HTTP listener.
// same address as a plaintext HTTP listener.
func
arrangeBindings
(
allConfigs
[]
server
.
Config
)
(
map
[
string
][]
server
.
Config
,
error
)
{
func
arrangeBindings
(
allConfigs
[]
server
.
Config
)
(
map
[
*
net
.
TCPAddr
][]
server
.
Config
,
error
)
{
addresses
:=
make
(
map
[
string
][]
server
.
Config
)
addresses
:=
make
(
map
[
*
net
.
TCPAddr
][]
server
.
Config
)
// Group configs by bind address
// Group configs by bind address
for
_
,
conf
:=
range
allConfigs
{
for
_
,
conf
:=
range
allConfigs
{
...
@@ -155,7 +168,7 @@ func arrangeBindings(allConfigs []server.Config) (map[string][]server.Config, er
...
@@ -155,7 +168,7 @@ func arrangeBindings(allConfigs []server.Config) (map[string][]server.Config, er
if
err
!=
nil
{
if
err
!=
nil
{
return
addresses
,
errors
.
New
(
"Could not serve "
+
conf
.
Address
()
+
" - "
+
err
.
Error
())
return
addresses
,
errors
.
New
(
"Could not serve "
+
conf
.
Address
()
+
" - "
+
err
.
Error
())
}
}
addresses
[
addr
.
String
()]
=
append
(
addresses
[
addr
.
String
()
],
conf
)
addresses
[
addr
]
=
append
(
addresses
[
addr
],
conf
)
}
}
// Don't allow HTTP and HTTPS to be served on the same address
// Don't allow HTTP and HTTPS to be served on the same address
...
...
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