Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 14, 05:15 UTC
Minor cleanups
Matthew Holt committed
Nov 15, 2019 at 12:47 UTC
0ca109db4ab0b8869a15d388ef9036d9117ec081
3 files changed
+27
-14
listeners.go
+3
-6
@@ -52,10 +52,7 @@ func Listen(network, addr string) (net.Listener, error) {
52
}
53
54
// make sure to start its usage counter at 1
55
- lnGlobal := &globalListener{
56
- usage: 1,
57
- ln: ln,
58
- }
55
+ lnGlobal := &globalListener{usage: 1, ln: ln}
56
listeners[lnKey] = lnGlobal
57
58
return &fakeCloseListener{
@@ -271,8 +268,8 @@ type ParsedAddress struct {
268
269
// JoinHostPort is like net.JoinHostPort, but where the port
270
// is StartPort + offset.
274
-func (l ParsedAddress) JoinHostPort(offset uint) string {
275
- return net.JoinHostPort(l.Host, strconv.Itoa(int(l.StartPort+offset)))
271
+func (pa ParsedAddress) JoinHostPort(offset uint) string {
272
+ return net.JoinHostPort(pa.Host, strconv.Itoa(int(pa.StartPort+offset)))
273
}
274
275
// PortRangeSize returns how many ports are in
modules/caddyhttp/fileserver/caddyfile.go
+15
@@ -83,6 +83,21 @@ func parseCaddyfile(h httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error)
83
return &fsrv, nil
84
}
85
86
+// parseTryFiles parses the try_files directive. It combines a file matcher
87
+// with a rewrite directive, so this is not a standard handler directive.
88
+// A try_files directive has this syntax (notice no matcher tokens accepted):
89
+//
90
+// try_files <files...>
91
+//
92
+// and is shorthand for:
93
+//
94
+// matcher:try_files {
95
+// file {
96
+// try_files <files...>
97
+// }
98
+// }
99
+// rewrite match:try_files {http.matchers.file.relative}{http.request.uri.query_string}
100
+//
101
func parseTryFiles(h httpcaddyfile.Helper) ([]httpcaddyfile.ConfigValue, error) {
102
if !h.Next() {
103
return nil, h.ArgErr()
usagepool.go
+9
-8
@@ -25,14 +25,15 @@ import (
25
// only inserted if they do not already exist. There
26
// are two ways to add values to the pool:
27
//
28
-// 1) LoadOrStore will increment usage and store the
29
-// value immediately if it does not already exist
30
-// 2) LoadOrNew will increment usage and construct the
31
-// value immediately if it does not already exist,
32
-// then store that value in the pool. When the
33
-// constructed value is finally deleted from the
34
-// pool (after its usage reaches 0), it will be
35
-// cleaned up by calling its Destruct method.
28
+// 1) LoadOrStore will increment usage and store the
29
+// value immediately if it does not already exist.
30
+// 2) LoadOrNew will atomically check for existence
31
+// and construct the value immediately if it does
32
+// not already exist, or increment the usage
33
+// otherwise, then store that value in the pool.
34
+// When the constructed value is finally deleted
35
+// from the pool (when its usage reaches 0), it
36
+// will be cleaned up by calling Destruct().
37
//
38
// The use of LoadOrNew allows values to be created
39
// and reused and finally cleaned up only once, even