From 5137859e47678aae81e178ca7d164f9e2b4e3121 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Fri, 14 Jun 2019 11:58:28 -0600 Subject: [PATCH] Rename caddy2 -> caddy Removes the version from the package name --- admin.go | 2 +- admin_test.go | 2 +- caddy.go | 2 +- cmd/caddy2/main.go | 30 +++++++------- cmd/run.go | 6 +-- context.go | 2 +- go.mod | 6 +-- go.sum | 2 + listeners.go | 2 +- modules.go | 2 +- modules/caddyhttp/caddyhttp.go | 20 +++++----- modules/caddyhttp/caddylog/log.go | 6 +-- modules/caddyhttp/encode/brotli/brotli.go | 8 ++-- modules/caddyhttp/encode/encode.go | 10 ++--- modules/caddyhttp/encode/gzip/gzip.go | 12 +++--- modules/caddyhttp/encode/zstd/zstd.go | 6 +-- modules/caddyhttp/errors.go | 4 +- modules/caddyhttp/fileserver/browse.go | 8 ++-- modules/caddyhttp/fileserver/browselisting.go | 4 +- modules/caddyhttp/fileserver/matcher.go | 6 +-- modules/caddyhttp/fileserver/staticfiles.go | 14 +++---- modules/caddyhttp/headers/headers.go | 26 ++++++------ modules/caddyhttp/markdown/markdown.go | 6 +-- modules/caddyhttp/matchers.go | 40 +++++++++---------- modules/caddyhttp/matchers_test.go | 10 ++--- modules/caddyhttp/replacer.go | 4 +- modules/caddyhttp/requestbody/requestbody.go | 6 +-- modules/caddyhttp/responsewriter.go | 20 ++++++---- modules/caddyhttp/reverseproxy/module.go | 4 +- modules/caddyhttp/reverseproxy/upstream.go | 8 ++-- modules/caddyhttp/rewrite/rewrite.go | 8 ++-- modules/caddyhttp/routes.go | 4 +- modules/caddyhttp/server.go | 18 ++++----- modules/caddyhttp/staticresp.go | 6 +-- modules/caddyhttp/staticresp_test.go | 6 +-- modules/caddyhttp/table.go | 6 +-- modules/caddytls/acmemanager.go | 16 ++++---- modules/caddytls/connpolicy.go | 6 +-- modules/caddytls/fileloader.go | 4 +- modules/caddytls/folderloader.go | 4 +- modules/caddytls/matchers.go | 4 +- modules/caddytls/sessiontickets.go | 8 ++-- modules/caddytls/standardstek/stek.go | 6 +-- modules/caddytls/tls.go | 10 ++--- modules_test.go | 2 +- pkg/caddyscript/matcherenv.go | 2 +- replacer.go | 2 +- storage.go | 2 +- 48 files changed, 199 insertions(+), 193 deletions(-) diff --git a/admin.go b/admin.go index 511ab019..cacdfd00 100644 --- a/admin.go +++ b/admin.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "bytes" diff --git a/admin_test.go b/admin_test.go index 73a9efea..ed1d5a97 100644 --- a/admin_test.go +++ b/admin_test.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "strings" diff --git a/caddy.go b/caddy.go index c43a7c0e..f8f6e45b 100644 --- a/caddy.go +++ b/caddy.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "context" diff --git a/cmd/caddy2/main.go b/cmd/caddy2/main.go index 310b8c1b..c2320efe 100644 --- a/cmd/caddy2/main.go +++ b/cmd/caddy2/main.go @@ -1,23 +1,23 @@ package main import ( - caddycmd "github.com/caddyserver/caddy2/cmd" + caddycmd "github.com/caddyserver/caddy/cmd" // this is where modules get plugged in - _ "github.com/caddyserver/caddy2/modules/caddyhttp" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/caddylog" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/encode" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/brotli" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/gzip" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/zstd" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/fileserver" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/headers" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/markdown" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/requestbody" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/reverseproxy" - _ "github.com/caddyserver/caddy2/modules/caddyhttp/rewrite" - _ "github.com/caddyserver/caddy2/modules/caddytls" - _ "github.com/caddyserver/caddy2/modules/caddytls/standardstek" + _ "github.com/caddyserver/caddy/modules/caddyhttp" + _ "github.com/caddyserver/caddy/modules/caddyhttp/caddylog" + _ "github.com/caddyserver/caddy/modules/caddyhttp/encode" + _ "github.com/caddyserver/caddy/modules/caddyhttp/encode/brotli" + _ "github.com/caddyserver/caddy/modules/caddyhttp/encode/gzip" + _ "github.com/caddyserver/caddy/modules/caddyhttp/encode/zstd" + _ "github.com/caddyserver/caddy/modules/caddyhttp/fileserver" + _ "github.com/caddyserver/caddy/modules/caddyhttp/headers" + _ "github.com/caddyserver/caddy/modules/caddyhttp/markdown" + _ "github.com/caddyserver/caddy/modules/caddyhttp/requestbody" + _ "github.com/caddyserver/caddy/modules/caddyhttp/reverseproxy" + _ "github.com/caddyserver/caddy/modules/caddyhttp/rewrite" + _ "github.com/caddyserver/caddy/modules/caddytls" + _ "github.com/caddyserver/caddy/modules/caddytls/standardstek" ) func main() { diff --git a/cmd/run.go b/cmd/run.go index d7f12d77..703e1191 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -4,18 +4,18 @@ import ( "flag" "log" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // Main executes the main function of the caddy command. func Main() { flag.Parse() - err := caddy2.StartAdmin(*listenAddr) + err := caddy.StartAdmin(*listenAddr) if err != nil { log.Fatal(err) } - defer caddy2.StopAdmin() + defer caddy.StopAdmin() log.Println("Caddy 2 admin endpoint listening on", *listenAddr) diff --git a/context.go b/context.go index dcfb09f1..2af38ff6 100644 --- a/context.go +++ b/context.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "context" diff --git a/go.mod b/go.mod index b1cdb2a5..5a7d6359 100644 --- a/go.mod +++ b/go.mod @@ -1,16 +1,16 @@ -module github.com/caddyserver/caddy2 +module github.com/caddyserver/caddy go 1.12 require ( github.com/DataDog/zstd v1.4.0 // indirect - github.com/andybalholm/brotli v0.0.0-20190430215306-5c318f9037cb // indirect + github.com/andybalholm/brotli v0.0.0-20190430215306-5c318f9037cb github.com/dustin/go-humanize v1.0.0 github.com/go-acme/lego v2.6.0+incompatible github.com/google/go-cmp v0.3.0 // indirect github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b github.com/klauspost/cpuid v1.2.1 - github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641 + github.com/mholt/certmagic v0.6.0 github.com/rs/cors v1.6.0 github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/starlight-go/starlight v0.0.0-20181207205707-b06f321544f3 diff --git a/go.sum b/go.sum index b9d96e19..fbd3bb64 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641 h1:wNqOQ0DFxcZDNpPChhHfL8KscFMnxARN6Q2FiX4/VKI= github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY= +github.com/mholt/certmagic v0.6.0 h1:gZwuBuONw2v8/fZh2nd39kvjFNjnSF2uIR4GzKaaryw= +github.com/mholt/certmagic v0.6.0/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY= github.com/miekg/dns v1.1.3 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM= github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/listeners.go b/listeners.go index 31b81fc3..0b07afaf 100644 --- a/listeners.go +++ b/listeners.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "fmt" diff --git a/modules.go b/modules.go index 9ee38358..bc5ac2c3 100644 --- a/modules.go +++ b/modules.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "bytes" diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go index 89ea58f2..50c03163 100644 --- a/modules/caddyhttp/caddyhttp.go +++ b/modules/caddyhttp/caddyhttp.go @@ -12,15 +12,15 @@ import ( "strings" "time" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddytls" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddytls" "github.com/mholt/certmagic" ) func init() { weakrand.Seed(time.Now().UnixNano()) - err := caddy2.RegisterModule(caddy2.Module{ + err := caddy.RegisterModule(caddy.Module{ Name: "http", New: func() interface{} { return new(App) }, }) @@ -33,19 +33,19 @@ func init() { type App struct { HTTPPort int `json:"http_port,omitempty"` HTTPSPort int `json:"https_port,omitempty"` - GracePeriod caddy2.Duration `json:"grace_period,omitempty"` + GracePeriod caddy.Duration `json:"grace_period,omitempty"` Servers map[string]*Server `json:"servers,omitempty"` servers []*http.Server - ctx caddy2.Context + ctx caddy.Context } // Provision sets up the app. -func (app *App) Provision(ctx caddy2.Context) error { +func (app *App) Provision(ctx caddy.Context) error { app.ctx = ctx - repl := caddy2.NewReplacer() + repl := caddy.NewReplacer() for _, srv := range app.Servers { // TODO: Test this function to ensure these replacements are performed @@ -121,7 +121,7 @@ func (app *App) Start() error { return fmt.Errorf("%s: parsing listen address '%s': %v", srvName, lnAddr, err) } for _, addr := range addrs { - ln, err := caddy2.Listen(network, addr) + ln, err := caddy.Listen(network, addr) if err != nil { return fmt.Errorf("%s: listening on %s: %v", network, addr, err) } @@ -376,7 +376,7 @@ type MiddlewareHandler interface { // // If any handler encounters an error, it should be returned for proper // handling. Return values should be propagated down the middleware chain -// by returning it unchanged. +// by returning it unchanged. Returned errors should not be re-wrapped. type Handler interface { ServeHTTP(http.ResponseWriter, *http.Request) error } @@ -455,4 +455,4 @@ const ( ) // Interface guard -var _ caddy2.App = (*App)(nil) +var _ caddy.App = (*App)(nil) diff --git a/modules/caddyhttp/caddylog/log.go b/modules/caddyhttp/caddylog/log.go index bad54fe2..d44e542c 100644 --- a/modules/caddyhttp/caddylog/log.go +++ b/modules/caddyhttp/caddylog/log.go @@ -5,12 +5,12 @@ import ( "net/http" "time" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.log", New: func() interface{} { return new(Log) }, }) diff --git a/modules/caddyhttp/encode/brotli/brotli.go b/modules/caddyhttp/encode/brotli/brotli.go index 3289f0c1..6bfd11f7 100644 --- a/modules/caddyhttp/encode/brotli/brotli.go +++ b/modules/caddyhttp/encode/brotli/brotli.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/andybalholm/brotli" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp/encode" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp/encode" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.encoders.brotli", New: func() interface{} { return new(Brotli) }, }) @@ -47,5 +47,5 @@ func (b Brotli) NewEncoder() encode.Encoder { // Interface guards var ( _ encode.Encoding = (*Brotli)(nil) - _ caddy2.Validator = (*Brotli)(nil) + _ caddy.Validator = (*Brotli)(nil) ) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index 2d6f5242..cf658e37 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -16,12 +16,12 @@ import ( "strings" "sync" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.encode", New: func() interface{} { return new(Encode) }, }) @@ -39,7 +39,7 @@ type Encode struct { } // Provision provisions enc. -func (enc *Encode) Provision(ctx caddy2.Context) error { +func (enc *Encode) Provision(ctx caddy.Context) error { enc.Encodings = make(map[string]Encoding) enc.writerPools = make(map[string]*sync.Pool) @@ -280,7 +280,7 @@ const defaultMinLength = 512 // Interface guards var ( - _ caddy2.Provisioner = (*Encode)(nil) + _ caddy.Provisioner = (*Encode)(nil) _ caddyhttp.MiddlewareHandler = (*Encode)(nil) _ caddyhttp.HTTPInterfaces = (*responseWriter)(nil) ) diff --git a/modules/caddyhttp/encode/gzip/gzip.go b/modules/caddyhttp/encode/gzip/gzip.go index b08385ab..156eb0d2 100644 --- a/modules/caddyhttp/encode/gzip/gzip.go +++ b/modules/caddyhttp/encode/gzip/gzip.go @@ -5,12 +5,12 @@ import ( "compress/gzip" // TODO: consider using https://github.com/klauspost/compress/gzip "fmt" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp/encode" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp/encode" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.encoders.gzip", New: func() interface{} { return new(Gzip) }, }) @@ -22,7 +22,7 @@ type Gzip struct { } // Provision provisions g's configuration. -func (g *Gzip) Provision(ctx caddy2.Context) error { +func (g *Gzip) Provision(ctx caddy.Context) error { if g.Level == 0 { g.Level = defaultGzipLevel } @@ -52,6 +52,6 @@ var defaultGzipLevel = 5 // Interface guards var ( _ encode.Encoding = (*Gzip)(nil) - _ caddy2.Provisioner = (*Gzip)(nil) - _ caddy2.Validator = (*Gzip)(nil) + _ caddy.Provisioner = (*Gzip)(nil) + _ caddy.Validator = (*Gzip)(nil) ) diff --git a/modules/caddyhttp/encode/zstd/zstd.go b/modules/caddyhttp/encode/zstd/zstd.go index eb66ad87..2bb8771e 100644 --- a/modules/caddyhttp/encode/zstd/zstd.go +++ b/modules/caddyhttp/encode/zstd/zstd.go @@ -1,13 +1,13 @@ package caddyzstd import ( - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp/encode" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp/encode" "github.com/klauspost/compress/zstd" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.encoders.zstd", New: func() interface{} { return new(Zstd) }, }) diff --git a/modules/caddyhttp/errors.go b/modules/caddyhttp/errors.go index 0e7b8f2b..4895dad6 100644 --- a/modules/caddyhttp/errors.go +++ b/modules/caddyhttp/errors.go @@ -7,7 +7,7 @@ import ( "runtime" "strings" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // Error is a convenient way for a Handler to populate the @@ -102,4 +102,4 @@ var ErrRehandle = fmt.Errorf("rehandling request") // ErrorCtxKey is the context key to use when storing // an error (for use with context.Context). -const ErrorCtxKey = caddy2.CtxKey("handler_chain_error") +const ErrorCtxKey = caddy.CtxKey("handler_chain_error") diff --git a/modules/caddyhttp/fileserver/browse.go b/modules/caddyhttp/fileserver/browse.go index d86bc644..13295416 100644 --- a/modules/caddyhttp/fileserver/browse.go +++ b/modules/caddyhttp/fileserver/browse.go @@ -9,8 +9,8 @@ import ( "path" "strings" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) // Browse configures directory browsing. @@ -37,7 +37,7 @@ func (fsrv *FileServer) serveBrowse(dirPath string, w http.ResponseWriter, r *ht } defer dir.Close() - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) // calling path.Clean here prevents weird breadcrumbs when URL paths are sketchy like /%2e%2e%2f listing, err := fsrv.loadDirectoryContents(dir, path.Clean(r.URL.Path), repl) @@ -71,7 +71,7 @@ func (fsrv *FileServer) serveBrowse(dirPath string, w http.ResponseWriter, r *ht return nil } -func (fsrv *FileServer) loadDirectoryContents(dir *os.File, urlPath string, repl caddy2.Replacer) (browseListing, error) { +func (fsrv *FileServer) loadDirectoryContents(dir *os.File, urlPath string, repl caddy.Replacer) (browseListing, error) { files, err := dir.Readdir(-1) if err != nil { return browseListing{}, err diff --git a/modules/caddyhttp/fileserver/browselisting.go b/modules/caddyhttp/fileserver/browselisting.go index ba915bf4..eb0ec974 100644 --- a/modules/caddyhttp/fileserver/browselisting.go +++ b/modules/caddyhttp/fileserver/browselisting.go @@ -9,11 +9,11 @@ import ( "strings" "time" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" "github.com/dustin/go-humanize" ) -func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, repl caddy2.Replacer) browseListing { +func (fsrv *FileServer) directoryListing(files []os.FileInfo, canGoUp bool, urlPath string, repl caddy.Replacer) browseListing { filesToHide := fsrv.transformHidePaths(repl) var ( diff --git a/modules/caddyhttp/fileserver/matcher.go b/modules/caddyhttp/fileserver/matcher.go index 0bdbf67d..ff4321ad 100644 --- a/modules/caddyhttp/fileserver/matcher.go +++ b/modules/caddyhttp/fileserver/matcher.go @@ -4,12 +4,12 @@ import ( "net/http" "os" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.file", New: func() interface{} { return new(FileMatcher) }, }) diff --git a/modules/caddyhttp/fileserver/staticfiles.go b/modules/caddyhttp/fileserver/staticfiles.go index d0944068..080e1a80 100644 --- a/modules/caddyhttp/fileserver/staticfiles.go +++ b/modules/caddyhttp/fileserver/staticfiles.go @@ -12,14 +12,14 @@ import ( "strings" "time" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { weakrand.Seed(time.Now().UnixNano()) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.responders.file_server", New: func() interface{} { return new(FileServer) }, }) @@ -40,7 +40,7 @@ type FileServer struct { } // Provision sets up the static files responder. -func (fsrv *FileServer) Provision(ctx caddy2.Context) error { +func (fsrv *FileServer) Provision(ctx caddy.Context) error { if fsrv.Fallback != nil { err := fsrv.Fallback.Provision(ctx) if err != nil { @@ -94,7 +94,7 @@ func (fsrv *FileServer) Validate() error { } func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) error { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) filesToHide := fsrv.transformHidePaths(repl) @@ -251,7 +251,7 @@ func mapDirOpenError(originalErr error, name string) error { // transformHidePaths performs replacements for all the elements of // fsrv.Hide and returns a new list of the transformed values. -func (fsrv *FileServer) transformHidePaths(repl caddy2.Replacer) []string { +func (fsrv *FileServer) transformHidePaths(repl caddy.Replacer) []string { hide := make([]string, len(fsrv.Hide)) for i := range fsrv.Hide { hide[i] = repl.ReplaceAll(fsrv.Hide[i], "") @@ -288,7 +288,7 @@ func sanitizedPathJoin(root, reqPath string) string { // by default) to map the request r to a filename. The full path to // the file is returned if one is found; otherwise, an empty string // is returned. -func (fsrv *FileServer) selectFile(r *http.Request, repl caddy2.Replacer, filesToHide []string) string { +func (fsrv *FileServer) selectFile(r *http.Request, repl caddy.Replacer, filesToHide []string) string { root := repl.ReplaceAll(fsrv.Root, "") if fsrv.Files == nil { diff --git a/modules/caddyhttp/headers/headers.go b/modules/caddyhttp/headers/headers.go index bce54354..84dc453d 100644 --- a/modules/caddyhttp/headers/headers.go +++ b/modules/caddyhttp/headers/headers.go @@ -4,12 +4,12 @@ import ( "net/http" "strings" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.headers", New: func() interface{} { return new(Headers) }, }) @@ -38,7 +38,7 @@ type RespHeaderOps struct { } func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) apply(h.Request, r.Header, repl) if h.Response.Deferred || h.Response.Require != nil { w = &responseWriterWrapper{ @@ -53,7 +53,7 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt return next.ServeHTTP(w, r) } -func apply(ops *HeaderOps, hdr http.Header, repl caddy2.Replacer) { +func apply(ops *HeaderOps, hdr http.Header, repl caddy.Replacer) { for fieldName, vals := range ops.Add { fieldName = repl.ReplaceAll(fieldName, "") for _, v := range vals { @@ -76,19 +76,12 @@ func apply(ops *HeaderOps, hdr http.Header, repl caddy2.Replacer) { // operations until WriteHeader is called. type responseWriterWrapper struct { *caddyhttp.ResponseWriterWrapper - replacer caddy2.Replacer + replacer caddy.Replacer require *caddyhttp.ResponseMatcher headerOps *HeaderOps wroteHeader bool } -func (rww *responseWriterWrapper) Write(d []byte) (int, error) { - if !rww.wroteHeader { - rww.WriteHeader(http.StatusOK) - } - return rww.ResponseWriterWrapper.Write(d) -} - func (rww *responseWriterWrapper) WriteHeader(status int) { if rww.wroteHeader { return @@ -100,6 +93,13 @@ func (rww *responseWriterWrapper) WriteHeader(status int) { rww.ResponseWriterWrapper.WriteHeader(status) } +func (rww *responseWriterWrapper) Write(d []byte) (int, error) { + if !rww.wroteHeader { + rww.WriteHeader(http.StatusOK) + } + return rww.ResponseWriterWrapper.Write(d) +} + // Interface guards var ( _ caddyhttp.MiddlewareHandler = (*Headers)(nil) diff --git a/modules/caddyhttp/markdown/markdown.go b/modules/caddyhttp/markdown/markdown.go index e65d4e66..90d615a0 100644 --- a/modules/caddyhttp/markdown/markdown.go +++ b/modules/caddyhttp/markdown/markdown.go @@ -6,12 +6,12 @@ import ( "gopkg.in/russross/blackfriday.v2" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.markdown", New: func() interface{} { return new(Markdown) }, }) diff --git a/modules/caddyhttp/matchers.go b/modules/caddyhttp/matchers.go index 5abaa544..86a2c69e 100644 --- a/modules/caddyhttp/matchers.go +++ b/modules/caddyhttp/matchers.go @@ -13,8 +13,8 @@ import ( "regexp" "strings" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/pkg/caddyscript" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/pkg/caddyscript" "go.starlark.net/starlark" ) @@ -65,47 +65,47 @@ type ( ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.host", New: func() interface{} { return new(MatchHost) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.path", New: func() interface{} { return new(MatchPath) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.path_regexp", New: func() interface{} { return new(MatchPathRE) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.method", New: func() interface{} { return new(MatchMethod) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.query", New: func() interface{} { return new(MatchQuery) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.header", New: func() interface{} { return new(MatchHeader) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.header_regexp", New: func() interface{} { return new(MatchHeaderRE) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.protocol", New: func() interface{} { return new(MatchProtocol) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.remote_ip", New: func() interface{} { return new(MatchRemoteIP) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.not", New: func() interface{} { return new(MatchNegate) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.starlark_expr", New: func() interface{} { return new(MatchStarlarkExpr) }, }) @@ -158,7 +158,7 @@ func (m MatchPath) Match(r *http.Request) bool { // Match returns true if r matches m. func (m MatchPathRE) Match(r *http.Request) bool { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) return m.MatchRegexp.Match(r.URL.Path, repl, "path_regexp") } @@ -209,7 +209,7 @@ func (m MatchHeader) Match(r *http.Request) bool { // Match returns true if r matches m. func (m MatchHeaderRE) Match(r *http.Request) bool { for field, rm := range m { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) match := rm.Match(r.Header.Get(field), repl, "header_regexp") if !match { return false @@ -262,7 +262,7 @@ func (m *MatchNegate) UnmarshalJSON(data []byte) error { } // Provision loads the matcher modules to be negated. -func (m *MatchNegate) Provision(ctx caddy2.Context) error { +func (m *MatchNegate) Provision(ctx caddy.Context) error { for modName, rawMsg := range m.matchersRaw { val, err := ctx.LoadModule("http.matchers."+modName, rawMsg) if err != nil { @@ -281,7 +281,7 @@ func (m MatchNegate) Match(r *http.Request) bool { } // Provision parses m's IP ranges, either from IP or CIDR expressions. -func (m *MatchRemoteIP) Provision(ctx caddy2.Context) error { +func (m *MatchRemoteIP) Provision(ctx caddy.Context) error { for _, str := range m.Ranges { if strings.Contains(str, "/") { _, ipNet, err := net.ParseCIDR(str) @@ -387,7 +387,7 @@ func (mre *MatchRegexp) Validate() error { // (namespace). Capture groups stored to repl will take on // the name "http.matchers..." where // is the name or number of the capture group. -func (mre *MatchRegexp) Match(input string, repl caddy2.Replacer, scope string) bool { +func (mre *MatchRegexp) Match(input string, repl caddy.Replacer, scope string) bool { matches := mre.compiled.FindStringSubmatch(input) if matches == nil { return false @@ -478,8 +478,8 @@ var ( _ RequestMatcher = (*MatchHeaderRE)(nil) _ RequestMatcher = (*MatchProtocol)(nil) _ RequestMatcher = (*MatchRemoteIP)(nil) - _ caddy2.Provisioner = (*MatchRemoteIP)(nil) + _ caddy.Provisioner = (*MatchRemoteIP)(nil) _ RequestMatcher = (*MatchNegate)(nil) - _ caddy2.Provisioner = (*MatchNegate)(nil) + _ caddy.Provisioner = (*MatchNegate)(nil) _ RequestMatcher = (*MatchStarlarkExpr)(nil) ) diff --git a/modules/caddyhttp/matchers_test.go b/modules/caddyhttp/matchers_test.go index 9e5ee45c..08ab1566 100644 --- a/modules/caddyhttp/matchers_test.go +++ b/modules/caddyhttp/matchers_test.go @@ -8,7 +8,7 @@ import ( "net/url" "testing" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func TestHostMatcher(t *testing.T) { @@ -227,8 +227,8 @@ func TestPathREMatcher(t *testing.T) { // set up the fake request and its Replacer req := &http.Request{URL: &url.URL{Path: tc.input}} - repl := caddy2.NewReplacer() - ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl) + repl := caddy.NewReplacer() + ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) req = req.WithContext(ctx) addHTTPVarsToReplacer(repl, req, httptest.NewRecorder()) @@ -345,8 +345,8 @@ func TestHeaderREMatcher(t *testing.T) { // set up the fake request and its Replacer req := &http.Request{Header: tc.input, URL: new(url.URL)} - repl := caddy2.NewReplacer() - ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl) + repl := caddy.NewReplacer() + ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl) req = req.WithContext(ctx) addHTTPVarsToReplacer(repl, req, httptest.NewRecorder()) diff --git a/modules/caddyhttp/replacer.go b/modules/caddyhttp/replacer.go index c854a2f1..425a2259 100644 --- a/modules/caddyhttp/replacer.go +++ b/modules/caddyhttp/replacer.go @@ -7,13 +7,13 @@ import ( "path" "strings" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // TODO: A simple way to format or escape or encode each value would be nice // ... TODO: Should we just use templates? :-/ yeesh... -func addHTTPVarsToReplacer(repl caddy2.Replacer, req *http.Request, w http.ResponseWriter) { +func addHTTPVarsToReplacer(repl caddy.Replacer, req *http.Request, w http.ResponseWriter) { httpVars := func() map[string]string { m := make(map[string]string) if req != nil { diff --git a/modules/caddyhttp/requestbody/requestbody.go b/modules/caddyhttp/requestbody/requestbody.go index a0840de5..b926dfeb 100644 --- a/modules/caddyhttp/requestbody/requestbody.go +++ b/modules/caddyhttp/requestbody/requestbody.go @@ -3,12 +3,12 @@ package requestbody import ( "net/http" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.request_body", New: func() interface{} { return new(RequestBody) }, }) diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index 4599fd2c..3bf39652 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/modules/caddyhttp/responsewriter.go @@ -19,31 +19,31 @@ type ResponseWriterWrapper struct { } // Hijack implements http.Hijacker. It simply calls the underlying -// ResponseWriter's Hijack method if there is one, or returns an error. +// ResponseWriter's Hijack method if there is one, or returns +// ErrNotImplemented otherwise. func (rww *ResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) { if hj, ok := rww.ResponseWriter.(http.Hijacker); ok { return hj.Hijack() } - return nil, nil, fmt.Errorf("not a hijacker") + return nil, nil, ErrNotImplemented } // Flush implements http.Flusher. It simply calls the underlying -// ResponseWriter's Flush method if there is one, or panics. +// ResponseWriter's Flush method if there is one. func (rww *ResponseWriterWrapper) Flush() { if f, ok := rww.ResponseWriter.(http.Flusher); ok { f.Flush() - } else { - panic("not a flusher") } } // Push implements http.Pusher. It simply calls the underlying -// ResponseWriter's Push method if there is one, or returns an error. +// ResponseWriter's Push method if there is one, or returns +// ErrNotImplemented otherwise. func (rww *ResponseWriterWrapper) Push(target string, opts *http.PushOptions) error { - if pusher, hasPusher := rww.ResponseWriter.(http.Pusher); hasPusher { + if pusher, ok := rww.ResponseWriter.(http.Pusher); ok { return pusher.Push(target, opts) } - return fmt.Errorf("not a pusher") + return ErrNotImplemented } // HTTPInterfaces mix all the interfaces that middleware ResponseWriters need to support. @@ -54,5 +54,9 @@ type HTTPInterfaces interface { http.Hijacker } +// ErrNotImplemented is returned when an underlying +// ResponseWriter does not implement the required method. +var ErrNotImplemented = fmt.Errorf("method not implemented") + // Interface guards var _ HTTPInterfaces = (*ResponseWriterWrapper)(nil) diff --git a/modules/caddyhttp/reverseproxy/module.go b/modules/caddyhttp/reverseproxy/module.go index 76c487ff..ecb53530 100755 --- a/modules/caddyhttp/reverseproxy/module.go +++ b/modules/caddyhttp/reverseproxy/module.go @@ -1,12 +1,12 @@ package reverseproxy import ( - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // Register caddy module. func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.responders.reverse_proxy", New: func() interface{} { return new(LoadBalanced) }, }) diff --git a/modules/caddyhttp/reverseproxy/upstream.go b/modules/caddyhttp/reverseproxy/upstream.go index db039542..171f343d 100755 --- a/modules/caddyhttp/reverseproxy/upstream.go +++ b/modules/caddyhttp/reverseproxy/upstream.go @@ -14,7 +14,7 @@ import ( "sync/atomic" "time" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // CircuitBreaker defines the functionality of a circuit breaker module. @@ -72,7 +72,7 @@ var ( ) // NewLoadBalancedReverseProxy returns a collection of Upstreams that are to be loadbalanced. -func NewLoadBalancedReverseProxy(lb *LoadBalanced, ctx caddy2.Context) error { +func NewLoadBalancedReverseProxy(lb *LoadBalanced, ctx caddy.Context) error { // set defaults if lb.NoHealthyUpstreamsMessage == "" { lb.NoHealthyUpstreamsMessage = msgNoHealthyUpstreams @@ -110,7 +110,7 @@ func NewLoadBalancedReverseProxy(lb *LoadBalanced, ctx caddy2.Context) error { var cb CircuitBreaker if uc.CircuitBreaker != nil { - if _, err := caddy2.GetModule(cbModule); err == nil { + if _, err := caddy.GetModule(cbModule); err == nil { val, err := ctx.LoadModule(cbModule, uc.CircuitBreaker) if err == nil { cbv, ok := val.(CircuitBreaker) @@ -191,7 +191,7 @@ func (lb *LoadBalanced) Cleanup() error { } // Provision sets up a new loadbalanced reverse proxy. -func (lb *LoadBalanced) Provision(ctx caddy2.Context) error { +func (lb *LoadBalanced) Provision(ctx caddy.Context) error { return NewLoadBalancedReverseProxy(lb, ctx) } diff --git a/modules/caddyhttp/rewrite/rewrite.go b/modules/caddyhttp/rewrite/rewrite.go index bbe7659e..198bc391 100644 --- a/modules/caddyhttp/rewrite/rewrite.go +++ b/modules/caddyhttp/rewrite/rewrite.go @@ -5,12 +5,12 @@ import ( "net/url" "strings" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddyhttp" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddyhttp" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.rewrite", New: func() interface{} { return new(Rewrite) }, }) @@ -24,7 +24,7 @@ type Rewrite struct { } func (rewr Rewrite) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) var rehandleNeeded bool if rewr.Method != "" { diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go index 3d78c217..596149d8 100644 --- a/modules/caddyhttp/routes.go +++ b/modules/caddyhttp/routes.go @@ -5,7 +5,7 @@ import ( "fmt" "net/http" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // ServerRoute represents a set of matching rules, @@ -56,7 +56,7 @@ func (mset MatcherSet) Match(r *http.Request) bool { type RouteList []ServerRoute // Provision sets up all the routes by loading the modules. -func (routes RouteList) Provision(ctx caddy2.Context) error { +func (routes RouteList) Provision(ctx caddy.Context) error { for i, route := range routes { // matchers for _, matcherSet := range route.MatcherSets { diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go index a2199cad..3de82f65 100644 --- a/modules/caddyhttp/server.go +++ b/modules/caddyhttp/server.go @@ -8,17 +8,17 @@ import ( "net/http" "strconv" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddytls" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddytls" ) // Server is an HTTP server. type Server struct { Listen []string `json:"listen,omitempty"` - ReadTimeout caddy2.Duration `json:"read_timeout,omitempty"` - ReadHeaderTimeout caddy2.Duration `json:"read_header_timeout,omitempty"` - WriteTimeout caddy2.Duration `json:"write_timeout,omitempty"` - IdleTimeout caddy2.Duration `json:"idle_timeout,omitempty"` + ReadTimeout caddy.Duration `json:"read_timeout,omitempty"` + ReadHeaderTimeout caddy.Duration `json:"read_header_timeout,omitempty"` + WriteTimeout caddy.Duration `json:"write_timeout,omitempty"` + IdleTimeout caddy.Duration `json:"idle_timeout,omitempty"` MaxHeaderBytes int `json:"max_header_bytes,omitempty"` Routes RouteList `json:"routes,omitempty"` Errors *httpErrorConfig `json:"errors,omitempty"` @@ -38,8 +38,8 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } // set up the context for the request - repl := caddy2.NewReplacer() - ctx := context.WithValue(r.Context(), caddy2.ReplacerCtxKey, repl) + repl := caddy.NewReplacer() + ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl) ctx = context.WithValue(ctx, TableCtxKey, make(map[string]interface{})) // TODO: Implement this r = r.WithContext(ctx) @@ -127,4 +127,4 @@ type httpErrorConfig struct { } // TableCtxKey is the context key for the request's variable table. -const TableCtxKey caddy2.CtxKey = "table" +const TableCtxKey caddy.CtxKey = "table" diff --git a/modules/caddyhttp/staticresp.go b/modules/caddyhttp/staticresp.go index ad596811..dfb3277f 100644 --- a/modules/caddyhttp/staticresp.go +++ b/modules/caddyhttp/staticresp.go @@ -5,11 +5,11 @@ import ( "net/http" "strconv" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.responders.static", New: func() interface{} { return new(Static) }, }) @@ -25,7 +25,7 @@ type Static struct { } func (s Static) ServeHTTP(w http.ResponseWriter, r *http.Request) error { - repl := r.Context().Value(caddy2.ReplacerCtxKey).(caddy2.Replacer) + repl := r.Context().Value(caddy.ReplacerCtxKey).(caddy.Replacer) // close the connection after responding r.Close = s.Close diff --git a/modules/caddyhttp/staticresp_test.go b/modules/caddyhttp/staticresp_test.go index ac868d82..45c5fec3 100644 --- a/modules/caddyhttp/staticresp_test.go +++ b/modules/caddyhttp/staticresp_test.go @@ -7,7 +7,7 @@ import ( "net/http/httptest" "testing" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func TestStaticResponseHandler(t *testing.T) { @@ -44,8 +44,8 @@ func TestStaticResponseHandler(t *testing.T) { func fakeRequest() *http.Request { r, _ := http.NewRequest("GET", "/", nil) - repl := caddy2.NewReplacer() - ctx := context.WithValue(r.Context(), caddy2.ReplacerCtxKey, repl) + repl := caddy.NewReplacer() + ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl) r = r.WithContext(ctx) return r } diff --git a/modules/caddyhttp/table.go b/modules/caddyhttp/table.go index 62077a81..b06e9024 100644 --- a/modules/caddyhttp/table.go +++ b/modules/caddyhttp/table.go @@ -3,16 +3,16 @@ package caddyhttp import ( "net/http" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.middleware.table", New: func() interface{} { return new(tableMiddleware) }, }) - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "http.matchers.table", New: func() interface{} { return new(tableMatcher) }, }) diff --git a/modules/caddytls/acmemanager.go b/modules/caddytls/acmemanager.go index 9cbf3493..50f8648d 100644 --- a/modules/caddytls/acmemanager.go +++ b/modules/caddytls/acmemanager.go @@ -7,13 +7,13 @@ import ( "github.com/go-acme/lego/certcrypto" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" "github.com/go-acme/lego/challenge" "github.com/mholt/certmagic" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls.management.acme", New: func() interface{} { return new(ACMEManagerMaker) }, }) @@ -30,9 +30,9 @@ func init() { type ACMEManagerMaker struct { CA string `json:"ca,omitempty"` Email string `json:"email,omitempty"` - RenewAhead caddy2.Duration `json:"renew_ahead,omitempty"` + RenewAhead caddy.Duration `json:"renew_ahead,omitempty"` KeyType string `json:"key_type,omitempty"` - ACMETimeout caddy2.Duration `json:"acme_timeout,omitempty"` + ACMETimeout caddy.Duration `json:"acme_timeout,omitempty"` MustStaple bool `json:"must_staple,omitempty"` Challenges ChallengesConfig `json:"challenges"` OnDemand *OnDemandConfig `json:"on_demand,omitempty"` @@ -49,7 +49,7 @@ func (m *ACMEManagerMaker) newManager(interactive bool) (certmagic.Manager, erro } // Provision sets up m. -func (m *ACMEManagerMaker) Provision(ctx caddy2.Context) error { +func (m *ACMEManagerMaker) Provision(ctx caddy.Context) error { // DNS providers if m.Challenges.DNS != nil { val, err := ctx.LoadModuleInline("provider", "tls.dns", m.Challenges.DNSRaw) @@ -66,7 +66,7 @@ func (m *ACMEManagerMaker) Provision(ctx caddy2.Context) error { if err != nil { return fmt.Errorf("loading TLS storage module: %s", err) } - cmStorage, err := val.(caddy2.StorageConverter).CertMagicStorage() + cmStorage, err := val.(caddy.StorageConverter).CertMagicStorage() if err != nil { return fmt.Errorf("creating TLS storage configuration: %v", err) } @@ -89,7 +89,7 @@ func (m *ACMEManagerMaker) SetDefaults() { m.Email = certmagic.Default.Email } if m.RenewAhead == 0 { - m.RenewAhead = caddy2.Duration(certmagic.Default.RenewDurationBefore) + m.RenewAhead = caddy.Duration(certmagic.Default.RenewDurationBefore) } if m.keyType == "" { m.keyType = certmagic.Default.KeyType @@ -102,7 +102,7 @@ func (m *ACMEManagerMaker) SetDefaults() { // makeCertMagicConfig converts m into a certmagic.Config, because // this is a special case where the default manager is the certmagic // Config and not a separate manager. -func (m *ACMEManagerMaker) makeCertMagicConfig(ctx caddy2.Context) certmagic.Config { +func (m *ACMEManagerMaker) makeCertMagicConfig(ctx caddy.Context) certmagic.Config { storage := m.storage if storage == nil { storage = ctx.Storage() diff --git a/modules/caddytls/connpolicy.go b/modules/caddytls/connpolicy.go index c1ca41dc..54cad7c0 100644 --- a/modules/caddytls/connpolicy.go +++ b/modules/caddytls/connpolicy.go @@ -7,7 +7,7 @@ import ( "fmt" "strings" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" "github.com/go-acme/lego/challenge/tlsalpn01" "github.com/mholt/certmagic" ) @@ -20,7 +20,7 @@ type ConnectionPolicies []*ConnectionPolicy // TLSConfig converts the group of policies to a standard-lib-compatible // TLS configuration which selects the first matching policy based on // the ClientHello. -func (cp ConnectionPolicies) TLSConfig(ctx caddy2.Context) (*tls.Config, error) { +func (cp ConnectionPolicies) TLSConfig(ctx caddy.Context) (*tls.Config, error) { // set up each of the connection policies for i, pol := range cp { // matchers @@ -110,7 +110,7 @@ type ConnectionPolicy struct { stdTLSConfig *tls.Config } -func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy2.Context) error { +func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy.Context) error { tlsAppIface, err := ctx.App("tls") if err != nil { return fmt.Errorf("getting tls app: %v", err) diff --git a/modules/caddytls/fileloader.go b/modules/caddytls/fileloader.go index c633f172..63592f95 100644 --- a/modules/caddytls/fileloader.go +++ b/modules/caddytls/fileloader.go @@ -5,11 +5,11 @@ import ( "fmt" "io/ioutil" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls.certificates.load_files", New: func() interface{} { return fileLoader{} }, }) diff --git a/modules/caddytls/folderloader.go b/modules/caddytls/folderloader.go index 0ce53b7a..bcc22d86 100644 --- a/modules/caddytls/folderloader.go +++ b/modules/caddytls/folderloader.go @@ -10,11 +10,11 @@ import ( "path/filepath" "strings" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls.certificates.load_folders", New: func() interface{} { return folderLoader{} }, }) diff --git a/modules/caddytls/matchers.go b/modules/caddytls/matchers.go index 712472f8..a0d26bb2 100644 --- a/modules/caddytls/matchers.go +++ b/modules/caddytls/matchers.go @@ -3,14 +3,14 @@ package caddytls import ( "crypto/tls" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // MatchServerName matches based on SNI. type MatchServerName []string func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls.handshake_match.sni", New: func() interface{} { return MatchServerName{} }, }) diff --git a/modules/caddytls/sessiontickets.go b/modules/caddytls/sessiontickets.go index 1d7d9b1e..246b396c 100644 --- a/modules/caddytls/sessiontickets.go +++ b/modules/caddytls/sessiontickets.go @@ -9,13 +9,13 @@ import ( "sync" "time" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" ) // SessionTicketService configures and manages TLS session tickets. type SessionTicketService struct { KeySource json.RawMessage `json:"key_source,omitempty"` - RotationInterval caddy2.Duration `json:"rotation_interval,omitempty"` + RotationInterval caddy.Duration `json:"rotation_interval,omitempty"` MaxKeys int `json:"max_keys,omitempty"` DisableRotation bool `json:"disable_rotation,omitempty"` Disabled bool `json:"disabled,omitempty"` @@ -27,13 +27,13 @@ type SessionTicketService struct { mu *sync.Mutex } -func (s *SessionTicketService) provision(ctx caddy2.Context) error { +func (s *SessionTicketService) provision(ctx caddy.Context) error { s.configs = make(map[*tls.Config]struct{}) s.mu = new(sync.Mutex) // establish sane defaults if s.RotationInterval == 0 { - s.RotationInterval = caddy2.Duration(defaultSTEKRotationInterval) + s.RotationInterval = caddy.Duration(defaultSTEKRotationInterval) } if s.MaxKeys <= 0 { s.MaxKeys = defaultMaxSTEKs diff --git a/modules/caddytls/standardstek/stek.go b/modules/caddytls/standardstek/stek.go index 939d021b..4ccb7f5d 100644 --- a/modules/caddytls/standardstek/stek.go +++ b/modules/caddytls/standardstek/stek.go @@ -5,12 +5,12 @@ import ( "sync" "time" - "github.com/caddyserver/caddy2" - "github.com/caddyserver/caddy2/modules/caddytls" + "github.com/caddyserver/caddy" + "github.com/caddyserver/caddy/modules/caddytls" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls.stek.standard", New: func() interface{} { return new(standardSTEKProvider) }, }) diff --git a/modules/caddytls/tls.go b/modules/caddytls/tls.go index 22749ae3..0614d241 100644 --- a/modules/caddytls/tls.go +++ b/modules/caddytls/tls.go @@ -6,13 +6,13 @@ import ( "fmt" "net/http" - "github.com/caddyserver/caddy2" + "github.com/caddyserver/caddy" "github.com/go-acme/lego/challenge" "github.com/mholt/certmagic" ) func init() { - caddy2.RegisterModule(caddy2.Module{ + caddy.RegisterModule(caddy.Module{ Name: "tls", New: func() interface{} { return new(TLS) }, }) @@ -26,11 +26,11 @@ type TLS struct { certificateLoaders []CertificateLoader certCache *certmagic.Cache - ctx caddy2.Context + ctx caddy.Context } // Provision sets up the configuration for the TLS app. -func (t *TLS) Provision(ctx caddy2.Context) error { +func (t *TLS) Provision(ctx caddy.Context) error { t.ctx = ctx // set up the certificate cache @@ -189,7 +189,7 @@ type AutomationPolicy struct { Management managerMaker `json:"-"` } -func (ap AutomationPolicy) makeCertMagicConfig(ctx caddy2.Context) certmagic.Config { +func (ap AutomationPolicy) makeCertMagicConfig(ctx caddy.Context) certmagic.Config { // default manager (ACME) is a special case because of how CertMagic is designed // TODO: refactor certmagic so that ACME manager is not a special case by extracting // its config fields out of the certmagic.Config struct, or something... diff --git a/modules_test.go b/modules_test.go index ff2ff4eb..6d54e648 100644 --- a/modules_test.go +++ b/modules_test.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "reflect" diff --git a/pkg/caddyscript/matcherenv.go b/pkg/caddyscript/matcherenv.go index 33e0e990..f2910422 100644 --- a/pkg/caddyscript/matcherenv.go +++ b/pkg/caddyscript/matcherenv.go @@ -3,7 +3,7 @@ package caddyscript import ( "net/http" - caddyscript "github.com/caddyserver/caddy2/pkg/caddyscript/lib" + caddyscript "github.com/caddyserver/caddy/pkg/caddyscript/lib" "go.starlark.net/starlark" ) diff --git a/replacer.go b/replacer.go index 6d7865ab..6e6cb45e 100644 --- a/replacer.go +++ b/replacer.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "os" diff --git a/storage.go b/storage.go index 2e35ac15..0baa2649 100644 --- a/storage.go +++ b/storage.go @@ -1,4 +1,4 @@ -package caddy2 +package caddy import ( "os"