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
82929b12
Commit
82929b12
authored
Jan 23, 2017
by
Matthew Holt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure active Caddyfile, if in site, is hidden no matter the cwd
parent
38c76647
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
10 deletions
+43
-10
caddyhttp/browse/browse.go
caddyhttp/browse/browse.go
+5
-4
caddyhttp/httpserver/plugin.go
caddyhttp/httpserver/plugin.go
+27
-5
caddyhttp/httpserver/siteconfig.go
caddyhttp/httpserver/siteconfig.go
+3
-0
caddyhttp/root/root.go
caddyhttp/root/root.go
+4
-0
caddyhttp/root/root_test.go
caddyhttp/root/root_test.go
+4
-1
No files found.
caddyhttp/browse/browse.go
View file @
82929b12
...
...
@@ -245,16 +245,17 @@ func directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, config
// ServeHTTP determines if the request is for this plugin, and if all prerequisites are met.
// If so, control is handed over to ServeListing.
func
(
b
Browse
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
var
bc
*
Config
// See if there's a browse configuration to match the path
var
bc
*
Config
for
i
:=
range
b
.
Configs
{
if
httpserver
.
Path
(
r
.
URL
.
Path
)
.
Matches
(
b
.
Configs
[
i
]
.
PathScope
)
{
bc
=
&
b
.
Configs
[
i
]
goto
inScope
break
}
}
return
b
.
Next
.
ServeHTTP
(
w
,
r
)
inScope
:
if
bc
==
nil
{
return
b
.
Next
.
ServeHTTP
(
w
,
r
)
}
// Browse works on existing directories; delegate everything else
requestedFilepath
,
err
:=
bc
.
Fs
.
Root
.
Open
(
r
.
URL
.
Path
)
...
...
caddyhttp/httpserver/plugin.go
View file @
82929b12
...
...
@@ -7,6 +7,7 @@ import (
"net"
"net/url"
"os"
"path/filepath"
"strings"
"time"
...
...
@@ -21,7 +22,7 @@ func init() {
flag
.
StringVar
(
&
Host
,
"host"
,
DefaultHost
,
"Default host"
)
flag
.
StringVar
(
&
Port
,
"port"
,
DefaultPort
,
"Default port"
)
flag
.
StringVar
(
&
Root
,
"root"
,
DefaultRoot
,
"Root path of default site"
)
flag
.
DurationVar
(
&
GracefulTimeout
,
"grace"
,
5
*
time
.
Second
,
"Maximum duration of graceful shutdown"
)
// TODO
flag
.
DurationVar
(
&
GracefulTimeout
,
"grace"
,
5
*
time
.
Second
,
"Maximum duration of graceful shutdown"
)
flag
.
BoolVar
(
&
HTTP2
,
"http2"
,
true
,
"Use HTTP/2"
)
flag
.
BoolVar
(
&
QUIC
,
"quic"
,
false
,
"Use experimental QUIC"
)
...
...
@@ -44,10 +45,31 @@ func init() {
NewContext
:
newContext
,
})
caddy
.
RegisterCaddyfileLoader
(
"short"
,
caddy
.
LoaderFunc
(
shortCaddyfileLoader
))
caddy
.
RegisterParsingCallback
(
serverType
,
"root"
,
hideCaddyfile
)
caddy
.
RegisterParsingCallback
(
serverType
,
"tls"
,
activateHTTPS
)
caddytls
.
RegisterConfigGetter
(
serverType
,
func
(
c
*
caddy
.
Controller
)
*
caddytls
.
Config
{
return
GetConfig
(
c
)
.
TLS
})
}
// hideCaddyfile hides the source/origin Caddyfile if it is within the
// site root. This function should be run after parsing the root directive.
func
hideCaddyfile
(
cctx
caddy
.
Context
)
error
{
ctx
:=
cctx
.
(
*
httpContext
)
for
_
,
cfg
:=
range
ctx
.
siteConfigs
{
absRoot
,
err
:=
filepath
.
Abs
(
cfg
.
Root
)
if
err
!=
nil
{
return
err
}
absOriginCaddyfile
,
err
:=
filepath
.
Abs
(
cfg
.
originCaddyfile
)
if
err
!=
nil
{
return
err
}
if
strings
.
HasPrefix
(
absOriginCaddyfile
,
absRoot
)
{
cfg
.
HiddenFiles
=
append
(
cfg
.
HiddenFiles
,
strings
.
TrimPrefix
(
absOriginCaddyfile
,
absRoot
))
}
}
return
nil
}
func
newContext
()
caddy
.
Context
{
return
&
httpContext
{
keysToSiteConfigs
:
make
(
map
[
string
]
*
SiteConfig
)}
}
...
...
@@ -95,10 +117,10 @@ func (h *httpContext) InspectServerBlocks(sourceFile string, serverBlocks []cadd
// Save the config to our master list, and key it for lookups
cfg
:=
&
SiteConfig
{
Addr
:
addr
,
Root
:
Root
,
TLS
:
&
caddytls
.
Config
{
Hostname
:
addr
.
Host
},
HiddenFiles
:
[]
string
{
sourceFile
}
,
Addr
:
addr
,
Root
:
Root
,
TLS
:
&
caddytls
.
Config
{
Hostname
:
addr
.
Host
},
originCaddyfile
:
sourceFile
,
}
h
.
saveConfig
(
key
,
cfg
)
}
...
...
caddyhttp/httpserver/siteconfig.go
View file @
82929b12
...
...
@@ -33,6 +33,9 @@ type SiteConfig struct {
// Max amount of bytes a request can send on a given path
MaxRequestBodySizes
[]
PathLimit
// The path to the Caddyfile used to generate this site config
originCaddyfile
string
}
// PathLimit is a mapping from a site's path to its corresponding
...
...
caddyhttp/root/root.go
View file @
82929b12
...
...
@@ -23,6 +23,10 @@ func setupRoot(c *caddy.Controller) error {
return
c
.
ArgErr
()
}
config
.
Root
=
c
.
Val
()
if
c
.
NextArg
()
{
// only one argument allowed
return
c
.
ArgErr
()
}
}
// Check if root path exists
...
...
caddyhttp/root/root_test.go
View file @
82929b12
...
...
@@ -52,6 +52,9 @@ func TestRoot(t *testing.T) {
{
`root `
,
true
,
""
,
parseErrContent
,
},
{
`root /a /b`
,
true
,
""
,
parseErrContent
,
},
{
fmt
.
Sprintf
(
`root %s`
,
inaccessiblePath
),
true
,
""
,
unableToAccessErrContent
,
},
...
...
@@ -68,7 +71,7 @@ func TestRoot(t *testing.T) {
cfg
:=
httpserver
.
GetConfig
(
c
)
if
test
.
shouldErr
&&
err
==
nil
{
t
.
Errorf
(
"Test %d: Expected error but
found %s for input %s"
,
i
,
err
,
test
.
input
)
t
.
Errorf
(
"Test %d: Expected error but
got nil for input '%s'"
,
i
,
test
.
input
)
}
if
err
!=
nil
{
...
...
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