summaryrefslogtreecommitdiff
path: root/modules/caddyhttp
diff options
context:
space:
mode:
authorMatthew Holt <mholt@users.noreply.github.com>2019-06-14 11:58:28 -0600
committerMatthew Holt <mholt@users.noreply.github.com>2019-06-14 11:58:28 -0600
commit5137859e47678aae81e178ca7d164f9e2b4e3121 (patch)
treef0e5cb9b9a4ad5dc03b53127fcea2a536bd6ee27 /modules/caddyhttp
parentb8e7453fef3dac6036403bc384eec96becff5114 (diff)
Rename caddy2 -> caddy
Removes the version from the package name
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r--modules/caddyhttp/caddyhttp.go20
-rw-r--r--modules/caddyhttp/caddylog/log.go6
-rw-r--r--modules/caddyhttp/encode/brotli/brotli.go8
-rw-r--r--modules/caddyhttp/encode/encode.go10
-rw-r--r--modules/caddyhttp/encode/gzip/gzip.go12
-rw-r--r--modules/caddyhttp/encode/zstd/zstd.go6
-rw-r--r--modules/caddyhttp/errors.go4
-rw-r--r--modules/caddyhttp/fileserver/browse.go8
-rw-r--r--modules/caddyhttp/fileserver/browselisting.go4
-rw-r--r--modules/caddyhttp/fileserver/matcher.go6
-rw-r--r--modules/caddyhttp/fileserver/staticfiles.go14
-rw-r--r--modules/caddyhttp/headers/headers.go26
-rw-r--r--modules/caddyhttp/markdown/markdown.go6
-rw-r--r--modules/caddyhttp/matchers.go40
-rw-r--r--modules/caddyhttp/matchers_test.go10
-rw-r--r--modules/caddyhttp/replacer.go4
-rw-r--r--modules/caddyhttp/requestbody/requestbody.go6
-rw-r--r--modules/caddyhttp/responsewriter.go20
-rwxr-xr-xmodules/caddyhttp/reverseproxy/module.go4
-rwxr-xr-xmodules/caddyhttp/reverseproxy/upstream.go8
-rw-r--r--modules/caddyhttp/rewrite/rewrite.go8
-rw-r--r--modules/caddyhttp/routes.go4
-rw-r--r--modules/caddyhttp/server.go18
-rw-r--r--modules/caddyhttp/staticresp.go6
-rw-r--r--modules/caddyhttp/staticresp_test.go6
-rw-r--r--modules/caddyhttp/table.go6
26 files changed, 137 insertions, 133 deletions
diff --git a/modules/caddyhttp/caddyhttp.go b/modules/caddyhttp/caddyhttp.go
index 89ea58f..50c0316 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 bad54fe..d44e542 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 3289f0c..6bfd11f 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 2d6f524..cf658e3 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 b08385a..156eb0d 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 eb66ad8..2bb8771 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 0e7b8f2..4895dad 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 d86bc64..1329541 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 ba915bf..eb0ec97 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 0bdbf67..ff4321a 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 d094406..080e1a8 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 bce5435..84dc453 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 e65d4e6..90d615a 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 5abaa54..86a2c69 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.<scope>.<mre.Name>.<N>" where
// <N> 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 9e5ee45..08ab156 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 c854a2f..425a225 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 a0840de..b926dfe 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 4599fd2..3bf3965 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 76c487f..ecb5353 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 db03954..171f343 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 bbe7659..198bc39 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 3d78c21..596149d 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 a2199ca..3de82f6 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 ad59681..dfb3277 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 ac868d8..45c5fec 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 62077a8..b06e902 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) },
})