1
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2024-12-16 21:56:40 -05:00

Rename caddy2 -> caddy

Removes the version from the package name
This commit is contained in:
Matthew Holt 2019-06-14 11:58:28 -06:00
parent b8e7453fef
commit 5137859e47
48 changed files with 199 additions and 193 deletions

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"bytes"

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"strings"

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"context"

View file

@ -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() {

View file

@ -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)

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"context"

6
go.mod
View file

@ -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

2
go.sum
View file

@ -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=

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"fmt"

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"bytes"

View file

@ -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)

View file

@ -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) },
})

View file

@ -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)
)

View file

@ -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)
)

View file

@ -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)
)

View file

@ -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) },
})

View file

@ -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")

View file

@ -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

View file

@ -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 (

View file

@ -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) },
})

View file

@ -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 {

View file

@ -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)

View file

@ -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) },
})

View file

@ -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)
)

View file

@ -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())

View file

@ -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 {

View file

@ -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) },
})

View file

@ -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)

View file

@ -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) },
})

View file

@ -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)
}

View file

@ -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 != "" {

View file

@ -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 {

View file

@ -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"

View file

@ -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

View file

@ -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
}

View file

@ -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) },
})

View file

@ -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()

View file

@ -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)

View file

@ -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{} },
})

View file

@ -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{} },
})

View file

@ -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{} },
})

View file

@ -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

View file

@ -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) },
})

View file

@ -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...

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"reflect"

View file

@ -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"
)

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"os"

View file

@ -1,4 +1,4 @@
package caddy2
package caddy
import (
"os"