mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
Minor improvements; comments and shorter placeholders & module IDs
This commit is contained in:
parent
f935458e3e
commit
87b6cf470b
7 changed files with 19 additions and 15 deletions
|
@ -561,10 +561,10 @@ type LogSampling struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// StdoutWriter can write logs to stdout.
|
// StdoutWriter writes logs to standard out.
|
||||||
StdoutWriter struct{}
|
StdoutWriter struct{}
|
||||||
|
|
||||||
// StderrWriter can write logs to stdout.
|
// StderrWriter writes logs to standard error.
|
||||||
StderrWriter struct{}
|
StderrWriter struct{}
|
||||||
|
|
||||||
// DiscardWriter discards all writes.
|
// DiscardWriter discards all writes.
|
||||||
|
|
|
@ -74,7 +74,7 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
|
||||||
}
|
}
|
||||||
|
|
||||||
repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
|
repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer)
|
||||||
repl.Set("http.handlers.authentication.user.id", user.ID)
|
repl.Set("http.authentication.user.id", user.ID)
|
||||||
|
|
||||||
return next.ServeHTTP(w, r)
|
return next.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
|
@ -596,7 +596,7 @@ func (m MatchRemoteIP) Match(r *http.Request) bool {
|
||||||
// CaddyModule returns the Caddy module information.
|
// CaddyModule returns the Caddy module information.
|
||||||
func (MatchStarlarkExpr) CaddyModule() caddy.ModuleInfo {
|
func (MatchStarlarkExpr) CaddyModule() caddy.ModuleInfo {
|
||||||
return caddy.ModuleInfo{
|
return caddy.ModuleInfo{
|
||||||
ID: "http.matchers.starlark_expr", // TODO: Rename to 'starlark'?
|
ID: "http.matchers.starlark",
|
||||||
New: func() caddy.Module { return new(MatchStarlarkExpr) },
|
New: func() caddy.Module { return new(MatchStarlarkExpr) },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
return d.Err("load balancing selection policy already specified")
|
return d.Err("load balancing selection policy already specified")
|
||||||
}
|
}
|
||||||
name := d.Val()
|
name := d.Val()
|
||||||
mod, err := caddy.GetModule("http.handlers.reverse_proxy.selection_policies." + name)
|
mod, err := caddy.GetModule("http.reverse_proxy.selection_policies." + name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d.Errf("getting load balancing policy module '%s': %v", mod, err)
|
return d.Errf("getting load balancing policy module '%s': %v", mod, err)
|
||||||
}
|
}
|
||||||
|
@ -389,7 +389,7 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
|
||||||
return d.Err("transport already specified")
|
return d.Err("transport already specified")
|
||||||
}
|
}
|
||||||
name := d.Val()
|
name := d.Val()
|
||||||
mod, err := caddy.GetModule("http.handlers.reverse_proxy.transport." + name)
|
mod, err := caddy.GetModule("http.reverse_proxy.transport." + name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return d.Errf("getting transport module '%s': %v", mod, err)
|
return d.Errf("getting transport module '%s': %v", mod, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ func cmdReverseProxy(fs caddycmd.Flags) (int, error) {
|
||||||
Headers: &headers.Handler{
|
Headers: &headers.Handler{
|
||||||
Request: &headers.HeaderOps{
|
Request: &headers.HeaderOps{
|
||||||
Set: http.Header{
|
Set: http.Header{
|
||||||
"Host": []string{"{http.handlers.reverse_proxy.upstream.host}"},
|
"Host": []string{"{http.reverse_proxy.upstream.host}"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -288,13 +288,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
// set placeholders with information about this upstream
|
// set placeholders with information about this upstream
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.address", dialInfo.String())
|
repl.Set("http.reverse_proxy.upstream.address", dialInfo.String())
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.hostport", dialInfo.Address)
|
repl.Set("http.reverse_proxy.upstream.hostport", dialInfo.Address)
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.host", dialInfo.Host)
|
repl.Set("http.reverse_proxy.upstream.host", dialInfo.Host)
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.port", dialInfo.Port)
|
repl.Set("http.reverse_proxy.upstream.port", dialInfo.Port)
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.requests", strconv.Itoa(upstream.Host.NumRequests()))
|
repl.Set("http.reverse_proxy.upstream.requests", strconv.Itoa(upstream.Host.NumRequests()))
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.max_requests", strconv.Itoa(upstream.MaxRequests))
|
repl.Set("http.reverse_proxy.upstream.max_requests", strconv.Itoa(upstream.MaxRequests))
|
||||||
repl.Set("http.handlers.reverse_proxy.upstream.fails", strconv.Itoa(upstream.Host.Fails()))
|
repl.Set("http.reverse_proxy.upstream.fails", strconv.Itoa(upstream.Host.Fails()))
|
||||||
|
|
||||||
// mutate request headers according to this upstream;
|
// mutate request headers according to this upstream;
|
||||||
// because we're in a retry loop, we have to copy
|
// because we're in a retry loop, we have to copy
|
||||||
|
|
|
@ -447,6 +447,10 @@ func (*HTTPErrorConfig) WithError(r *http.Request, err error) *http.Request {
|
||||||
|
|
||||||
// ServerLogConfig describes a server's logging configuration.
|
// ServerLogConfig describes a server's logging configuration.
|
||||||
type ServerLogConfig struct {
|
type ServerLogConfig struct {
|
||||||
|
// LoggerNames maps request hostnames to a custom logger name.
|
||||||
|
// For example, a mapping of "example.com" to "example" would
|
||||||
|
// cause access logs from requests with a Host of example.com
|
||||||
|
// to be emitted by a logger named "http.log.access.example".
|
||||||
LoggerNames map[string]string `json:"logger_names,omitempty"`
|
LoggerNames map[string]string `json:"logger_names,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +508,7 @@ func cloneURL(from, to *url.URL) {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CommonLogFormat is the common log format. https://en.wikipedia.org/wiki/Common_Log_Format
|
// CommonLogFormat is the common log format. https://en.wikipedia.org/wiki/Common_Log_Format
|
||||||
CommonLogFormat = `{http.request.remote.host} ` + CommonLogEmptyValue + ` {http.handlers.authentication.user.id} [{time.now.common_log}] "{http.request.orig_method} {http.request.orig_uri} {http.request.proto}" {http.response.status} {http.response.size}`
|
CommonLogFormat = `{http.request.remote.host} ` + CommonLogEmptyValue + ` {http.authentication.user.id} [{time.now.common_log}] "{http.request.orig_method} {http.request.orig_uri} {http.request.proto}" {http.response.status} {http.response.size}`
|
||||||
|
|
||||||
// CommonLogEmptyValue is the common empty log value.
|
// CommonLogEmptyValue is the common empty log value.
|
||||||
CommonLogEmptyValue = "-"
|
CommonLogEmptyValue = "-"
|
||||||
|
|
Loading…
Reference in a new issue