mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-30 22:34:15 -05:00
Rename caddy2 -> caddy
Removes the version from the package name
This commit is contained in:
parent
b8e7453fef
commit
5137859e47
48 changed files with 199 additions and 193 deletions
2
admin.go
2
admin.go
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
2
caddy.go
2
caddy.go
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
|
@ -1,23 +1,23 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
caddycmd "github.com/caddyserver/caddy2/cmd"
|
caddycmd "github.com/caddyserver/caddy/cmd"
|
||||||
|
|
||||||
// this is where modules get plugged in
|
// this is where modules get plugged in
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/caddylog"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/caddylog"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/encode"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/encode"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/brotli"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/encode/brotli"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/gzip"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/encode/gzip"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/encode/zstd"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/encode/zstd"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/fileserver"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/fileserver"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/headers"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/headers"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/markdown"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/markdown"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/requestbody"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/requestbody"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/reverseproxy"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/reverseproxy"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddyhttp/rewrite"
|
_ "github.com/caddyserver/caddy/modules/caddyhttp/rewrite"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddytls"
|
_ "github.com/caddyserver/caddy/modules/caddytls"
|
||||||
_ "github.com/caddyserver/caddy2/modules/caddytls/standardstek"
|
_ "github.com/caddyserver/caddy/modules/caddytls/standardstek"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
@ -4,18 +4,18 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Main executes the main function of the caddy command.
|
// Main executes the main function of the caddy command.
|
||||||
func Main() {
|
func Main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
err := caddy2.StartAdmin(*listenAddr)
|
err := caddy.StartAdmin(*listenAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
defer caddy2.StopAdmin()
|
defer caddy.StopAdmin()
|
||||||
|
|
||||||
log.Println("Caddy 2 admin endpoint listening on", *listenAddr)
|
log.Println("Caddy 2 admin endpoint listening on", *listenAddr)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -1,16 +1,16 @@
|
||||||
module github.com/caddyserver/caddy2
|
module github.com/caddyserver/caddy
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/DataDog/zstd v1.4.0 // indirect
|
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/dustin/go-humanize v1.0.0
|
||||||
github.com/go-acme/lego v2.6.0+incompatible
|
github.com/go-acme/lego v2.6.0+incompatible
|
||||||
github.com/google/go-cmp v0.3.0 // indirect
|
github.com/google/go-cmp v0.3.0 // indirect
|
||||||
github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b
|
github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b
|
||||||
github.com/klauspost/cpuid v1.2.1
|
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/rs/cors v1.6.0
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
github.com/starlight-go/starlight v0.0.0-20181207205707-b06f321544f3
|
github.com/starlight-go/starlight v0.0.0-20181207205707-b06f321544f3
|
||||||
|
|
2
go.sum
2
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/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 h1:wNqOQ0DFxcZDNpPChhHfL8KscFMnxARN6Q2FiX4/VKI=
|
||||||
github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
|
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 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM=
|
||||||
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
|
@ -12,15 +12,15 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddytls"
|
"github.com/caddyserver/caddy/modules/caddytls"
|
||||||
"github.com/mholt/certmagic"
|
"github.com/mholt/certmagic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
weakrand.Seed(time.Now().UnixNano())
|
weakrand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
err := caddy2.RegisterModule(caddy2.Module{
|
err := caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http",
|
Name: "http",
|
||||||
New: func() interface{} { return new(App) },
|
New: func() interface{} { return new(App) },
|
||||||
})
|
})
|
||||||
|
@ -33,19 +33,19 @@ func init() {
|
||||||
type App struct {
|
type App struct {
|
||||||
HTTPPort int `json:"http_port,omitempty"`
|
HTTPPort int `json:"http_port,omitempty"`
|
||||||
HTTPSPort int `json:"https_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 map[string]*Server `json:"servers,omitempty"`
|
||||||
|
|
||||||
servers []*http.Server
|
servers []*http.Server
|
||||||
|
|
||||||
ctx caddy2.Context
|
ctx caddy.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision sets up the app.
|
// Provision sets up the app.
|
||||||
func (app *App) Provision(ctx caddy2.Context) error {
|
func (app *App) Provision(ctx caddy.Context) error {
|
||||||
app.ctx = ctx
|
app.ctx = ctx
|
||||||
|
|
||||||
repl := caddy2.NewReplacer()
|
repl := caddy.NewReplacer()
|
||||||
|
|
||||||
for _, srv := range app.Servers {
|
for _, srv := range app.Servers {
|
||||||
// TODO: Test this function to ensure these replacements are performed
|
// 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)
|
return fmt.Errorf("%s: parsing listen address '%s': %v", srvName, lnAddr, err)
|
||||||
}
|
}
|
||||||
for _, addr := range addrs {
|
for _, addr := range addrs {
|
||||||
ln, err := caddy2.Listen(network, addr)
|
ln, err := caddy.Listen(network, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("%s: listening on %s: %v", network, addr, err)
|
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
|
// If any handler encounters an error, it should be returned for proper
|
||||||
// handling. Return values should be propagated down the middleware chain
|
// 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 {
|
type Handler interface {
|
||||||
ServeHTTP(http.ResponseWriter, *http.Request) error
|
ServeHTTP(http.ResponseWriter, *http.Request) error
|
||||||
}
|
}
|
||||||
|
@ -455,4 +455,4 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Interface guard
|
// Interface guard
|
||||||
var _ caddy2.App = (*App)(nil)
|
var _ caddy.App = (*App)(nil)
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.log",
|
Name: "http.middleware.log",
|
||||||
New: func() interface{} { return new(Log) },
|
New: func() interface{} { return new(Log) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/andybalholm/brotli"
|
"github.com/andybalholm/brotli"
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp/encode"
|
"github.com/caddyserver/caddy/modules/caddyhttp/encode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.encoders.brotli",
|
Name: "http.encoders.brotli",
|
||||||
New: func() interface{} { return new(Brotli) },
|
New: func() interface{} { return new(Brotli) },
|
||||||
})
|
})
|
||||||
|
@ -47,5 +47,5 @@ func (b Brotli) NewEncoder() encode.Encoder {
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ encode.Encoding = (*Brotli)(nil)
|
_ encode.Encoding = (*Brotli)(nil)
|
||||||
_ caddy2.Validator = (*Brotli)(nil)
|
_ caddy.Validator = (*Brotli)(nil)
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,12 +16,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.encode",
|
Name: "http.middleware.encode",
|
||||||
New: func() interface{} { return new(Encode) },
|
New: func() interface{} { return new(Encode) },
|
||||||
})
|
})
|
||||||
|
@ -39,7 +39,7 @@ type Encode struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision provisions enc.
|
// 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.Encodings = make(map[string]Encoding)
|
||||||
enc.writerPools = make(map[string]*sync.Pool)
|
enc.writerPools = make(map[string]*sync.Pool)
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ const defaultMinLength = 512
|
||||||
|
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ caddy2.Provisioner = (*Encode)(nil)
|
_ caddy.Provisioner = (*Encode)(nil)
|
||||||
_ caddyhttp.MiddlewareHandler = (*Encode)(nil)
|
_ caddyhttp.MiddlewareHandler = (*Encode)(nil)
|
||||||
_ caddyhttp.HTTPInterfaces = (*responseWriter)(nil)
|
_ caddyhttp.HTTPInterfaces = (*responseWriter)(nil)
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"compress/gzip" // TODO: consider using https://github.com/klauspost/compress/gzip
|
"compress/gzip" // TODO: consider using https://github.com/klauspost/compress/gzip
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp/encode"
|
"github.com/caddyserver/caddy/modules/caddyhttp/encode"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.encoders.gzip",
|
Name: "http.encoders.gzip",
|
||||||
New: func() interface{} { return new(Gzip) },
|
New: func() interface{} { return new(Gzip) },
|
||||||
})
|
})
|
||||||
|
@ -22,7 +22,7 @@ type Gzip struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision provisions g's configuration.
|
// 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 {
|
if g.Level == 0 {
|
||||||
g.Level = defaultGzipLevel
|
g.Level = defaultGzipLevel
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,6 @@ var defaultGzipLevel = 5
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ encode.Encoding = (*Gzip)(nil)
|
_ encode.Encoding = (*Gzip)(nil)
|
||||||
_ caddy2.Provisioner = (*Gzip)(nil)
|
_ caddy.Provisioner = (*Gzip)(nil)
|
||||||
_ caddy2.Validator = (*Gzip)(nil)
|
_ caddy.Validator = (*Gzip)(nil)
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
package caddyzstd
|
package caddyzstd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp/encode"
|
"github.com/caddyserver/caddy/modules/caddyhttp/encode"
|
||||||
"github.com/klauspost/compress/zstd"
|
"github.com/klauspost/compress/zstd"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.encoders.zstd",
|
Name: "http.encoders.zstd",
|
||||||
New: func() interface{} { return new(Zstd) },
|
New: func() interface{} { return new(Zstd) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error is a convenient way for a Handler to populate the
|
// 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
|
// ErrorCtxKey is the context key to use when storing
|
||||||
// an error (for use with context.Context).
|
// an error (for use with context.Context).
|
||||||
const ErrorCtxKey = caddy2.CtxKey("handler_chain_error")
|
const ErrorCtxKey = caddy.CtxKey("handler_chain_error")
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Browse configures directory browsing.
|
// Browse configures directory browsing.
|
||||||
|
@ -37,7 +37,7 @@ func (fsrv *FileServer) serveBrowse(dirPath string, w http.ResponseWriter, r *ht
|
||||||
}
|
}
|
||||||
defer dir.Close()
|
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
|
// 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)
|
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
|
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)
|
files, err := dir.Readdir(-1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return browseListing{}, err
|
return browseListing{}, err
|
||||||
|
|
|
@ -9,11 +9,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/dustin/go-humanize"
|
"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)
|
filesToHide := fsrv.transformHidePaths(repl)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.file",
|
Name: "http.matchers.file",
|
||||||
New: func() interface{} { return new(FileMatcher) },
|
New: func() interface{} { return new(FileMatcher) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -12,14 +12,14 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
weakrand.Seed(time.Now().UnixNano())
|
weakrand.Seed(time.Now().UnixNano())
|
||||||
|
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.responders.file_server",
|
Name: "http.responders.file_server",
|
||||||
New: func() interface{} { return new(FileServer) },
|
New: func() interface{} { return new(FileServer) },
|
||||||
})
|
})
|
||||||
|
@ -40,7 +40,7 @@ type FileServer struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision sets up the static files responder.
|
// 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 {
|
if fsrv.Fallback != nil {
|
||||||
err := fsrv.Fallback.Provision(ctx)
|
err := fsrv.Fallback.Provision(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,7 +94,7 @@ func (fsrv *FileServer) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fsrv *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) 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)
|
filesToHide := fsrv.transformHidePaths(repl)
|
||||||
|
|
||||||
|
@ -251,7 +251,7 @@ func mapDirOpenError(originalErr error, name string) error {
|
||||||
|
|
||||||
// transformHidePaths performs replacements for all the elements of
|
// transformHidePaths performs replacements for all the elements of
|
||||||
// fsrv.Hide and returns a new list of the transformed values.
|
// 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))
|
hide := make([]string, len(fsrv.Hide))
|
||||||
for i := range fsrv.Hide {
|
for i := range fsrv.Hide {
|
||||||
hide[i] = repl.ReplaceAll(fsrv.Hide[i], "")
|
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
|
// 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
|
// the file is returned if one is found; otherwise, an empty string
|
||||||
// is returned.
|
// 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, "")
|
root := repl.ReplaceAll(fsrv.Root, "")
|
||||||
|
|
||||||
if fsrv.Files == nil {
|
if fsrv.Files == nil {
|
||||||
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.headers",
|
Name: "http.middleware.headers",
|
||||||
New: func() interface{} { return new(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 {
|
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)
|
apply(h.Request, r.Header, repl)
|
||||||
if h.Response.Deferred || h.Response.Require != nil {
|
if h.Response.Deferred || h.Response.Require != nil {
|
||||||
w = &responseWriterWrapper{
|
w = &responseWriterWrapper{
|
||||||
|
@ -53,7 +53,7 @@ func (h Headers) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhtt
|
||||||
return next.ServeHTTP(w, r)
|
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 {
|
for fieldName, vals := range ops.Add {
|
||||||
fieldName = repl.ReplaceAll(fieldName, "")
|
fieldName = repl.ReplaceAll(fieldName, "")
|
||||||
for _, v := range vals {
|
for _, v := range vals {
|
||||||
|
@ -76,19 +76,12 @@ func apply(ops *HeaderOps, hdr http.Header, repl caddy2.Replacer) {
|
||||||
// operations until WriteHeader is called.
|
// operations until WriteHeader is called.
|
||||||
type responseWriterWrapper struct {
|
type responseWriterWrapper struct {
|
||||||
*caddyhttp.ResponseWriterWrapper
|
*caddyhttp.ResponseWriterWrapper
|
||||||
replacer caddy2.Replacer
|
replacer caddy.Replacer
|
||||||
require *caddyhttp.ResponseMatcher
|
require *caddyhttp.ResponseMatcher
|
||||||
headerOps *HeaderOps
|
headerOps *HeaderOps
|
||||||
wroteHeader bool
|
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) {
|
func (rww *responseWriterWrapper) WriteHeader(status int) {
|
||||||
if rww.wroteHeader {
|
if rww.wroteHeader {
|
||||||
return
|
return
|
||||||
|
@ -100,6 +93,13 @@ func (rww *responseWriterWrapper) WriteHeader(status int) {
|
||||||
rww.ResponseWriterWrapper.WriteHeader(status)
|
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
|
// Interface guards
|
||||||
var (
|
var (
|
||||||
_ caddyhttp.MiddlewareHandler = (*Headers)(nil)
|
_ caddyhttp.MiddlewareHandler = (*Headers)(nil)
|
||||||
|
|
|
@ -6,12 +6,12 @@ import (
|
||||||
|
|
||||||
"gopkg.in/russross/blackfriday.v2"
|
"gopkg.in/russross/blackfriday.v2"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.markdown",
|
Name: "http.middleware.markdown",
|
||||||
New: func() interface{} { return new(Markdown) },
|
New: func() interface{} { return new(Markdown) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -13,8 +13,8 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/pkg/caddyscript"
|
"github.com/caddyserver/caddy/pkg/caddyscript"
|
||||||
"go.starlark.net/starlark"
|
"go.starlark.net/starlark"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -65,47 +65,47 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.host",
|
Name: "http.matchers.host",
|
||||||
New: func() interface{} { return new(MatchHost) },
|
New: func() interface{} { return new(MatchHost) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.path",
|
Name: "http.matchers.path",
|
||||||
New: func() interface{} { return new(MatchPath) },
|
New: func() interface{} { return new(MatchPath) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.path_regexp",
|
Name: "http.matchers.path_regexp",
|
||||||
New: func() interface{} { return new(MatchPathRE) },
|
New: func() interface{} { return new(MatchPathRE) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.method",
|
Name: "http.matchers.method",
|
||||||
New: func() interface{} { return new(MatchMethod) },
|
New: func() interface{} { return new(MatchMethod) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.query",
|
Name: "http.matchers.query",
|
||||||
New: func() interface{} { return new(MatchQuery) },
|
New: func() interface{} { return new(MatchQuery) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.header",
|
Name: "http.matchers.header",
|
||||||
New: func() interface{} { return new(MatchHeader) },
|
New: func() interface{} { return new(MatchHeader) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.header_regexp",
|
Name: "http.matchers.header_regexp",
|
||||||
New: func() interface{} { return new(MatchHeaderRE) },
|
New: func() interface{} { return new(MatchHeaderRE) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.protocol",
|
Name: "http.matchers.protocol",
|
||||||
New: func() interface{} { return new(MatchProtocol) },
|
New: func() interface{} { return new(MatchProtocol) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.remote_ip",
|
Name: "http.matchers.remote_ip",
|
||||||
New: func() interface{} { return new(MatchRemoteIP) },
|
New: func() interface{} { return new(MatchRemoteIP) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.not",
|
Name: "http.matchers.not",
|
||||||
New: func() interface{} { return new(MatchNegate) },
|
New: func() interface{} { return new(MatchNegate) },
|
||||||
})
|
})
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.starlark_expr",
|
Name: "http.matchers.starlark_expr",
|
||||||
New: func() interface{} { return new(MatchStarlarkExpr) },
|
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.
|
// Match returns true if r matches m.
|
||||||
func (m MatchPathRE) Match(r *http.Request) bool {
|
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")
|
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.
|
// Match returns true if r matches m.
|
||||||
func (m MatchHeaderRE) Match(r *http.Request) bool {
|
func (m MatchHeaderRE) Match(r *http.Request) bool {
|
||||||
for field, rm := range m {
|
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")
|
match := rm.Match(r.Header.Get(field), repl, "header_regexp")
|
||||||
if !match {
|
if !match {
|
||||||
return false
|
return false
|
||||||
|
@ -262,7 +262,7 @@ func (m *MatchNegate) UnmarshalJSON(data []byte) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision loads the matcher modules to be negated.
|
// 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 {
|
for modName, rawMsg := range m.matchersRaw {
|
||||||
val, err := ctx.LoadModule("http.matchers."+modName, rawMsg)
|
val, err := ctx.LoadModule("http.matchers."+modName, rawMsg)
|
||||||
if err != nil {
|
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.
|
// 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 {
|
for _, str := range m.Ranges {
|
||||||
if strings.Contains(str, "/") {
|
if strings.Contains(str, "/") {
|
||||||
_, ipNet, err := net.ParseCIDR(str)
|
_, ipNet, err := net.ParseCIDR(str)
|
||||||
|
@ -387,7 +387,7 @@ func (mre *MatchRegexp) Validate() error {
|
||||||
// (namespace). Capture groups stored to repl will take on
|
// (namespace). Capture groups stored to repl will take on
|
||||||
// the name "http.matchers.<scope>.<mre.Name>.<N>" where
|
// the name "http.matchers.<scope>.<mre.Name>.<N>" where
|
||||||
// <N> is the name or number of the capture group.
|
// <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)
|
matches := mre.compiled.FindStringSubmatch(input)
|
||||||
if matches == nil {
|
if matches == nil {
|
||||||
return false
|
return false
|
||||||
|
@ -478,8 +478,8 @@ var (
|
||||||
_ RequestMatcher = (*MatchHeaderRE)(nil)
|
_ RequestMatcher = (*MatchHeaderRE)(nil)
|
||||||
_ RequestMatcher = (*MatchProtocol)(nil)
|
_ RequestMatcher = (*MatchProtocol)(nil)
|
||||||
_ RequestMatcher = (*MatchRemoteIP)(nil)
|
_ RequestMatcher = (*MatchRemoteIP)(nil)
|
||||||
_ caddy2.Provisioner = (*MatchRemoteIP)(nil)
|
_ caddy.Provisioner = (*MatchRemoteIP)(nil)
|
||||||
_ RequestMatcher = (*MatchNegate)(nil)
|
_ RequestMatcher = (*MatchNegate)(nil)
|
||||||
_ caddy2.Provisioner = (*MatchNegate)(nil)
|
_ caddy.Provisioner = (*MatchNegate)(nil)
|
||||||
_ RequestMatcher = (*MatchStarlarkExpr)(nil)
|
_ RequestMatcher = (*MatchStarlarkExpr)(nil)
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHostMatcher(t *testing.T) {
|
func TestHostMatcher(t *testing.T) {
|
||||||
|
@ -227,8 +227,8 @@ func TestPathREMatcher(t *testing.T) {
|
||||||
|
|
||||||
// set up the fake request and its Replacer
|
// set up the fake request and its Replacer
|
||||||
req := &http.Request{URL: &url.URL{Path: tc.input}}
|
req := &http.Request{URL: &url.URL{Path: tc.input}}
|
||||||
repl := caddy2.NewReplacer()
|
repl := caddy.NewReplacer()
|
||||||
ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl)
|
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
|
addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
|
||||||
|
|
||||||
|
@ -345,8 +345,8 @@ func TestHeaderREMatcher(t *testing.T) {
|
||||||
|
|
||||||
// set up the fake request and its Replacer
|
// set up the fake request and its Replacer
|
||||||
req := &http.Request{Header: tc.input, URL: new(url.URL)}
|
req := &http.Request{Header: tc.input, URL: new(url.URL)}
|
||||||
repl := caddy2.NewReplacer()
|
repl := caddy.NewReplacer()
|
||||||
ctx := context.WithValue(req.Context(), caddy2.ReplacerCtxKey, repl)
|
ctx := context.WithValue(req.Context(), caddy.ReplacerCtxKey, repl)
|
||||||
req = req.WithContext(ctx)
|
req = req.WithContext(ctx)
|
||||||
addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
|
addHTTPVarsToReplacer(repl, req, httptest.NewRecorder())
|
||||||
|
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"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: A simple way to format or escape or encode each value would be nice
|
||||||
// ... TODO: Should we just use templates? :-/ yeesh...
|
// ... 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 {
|
httpVars := func() map[string]string {
|
||||||
m := make(map[string]string)
|
m := make(map[string]string)
|
||||||
if req != nil {
|
if req != nil {
|
||||||
|
|
|
@ -3,12 +3,12 @@ package requestbody
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.request_body",
|
Name: "http.middleware.request_body",
|
||||||
New: func() interface{} { return new(RequestBody) },
|
New: func() interface{} { return new(RequestBody) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,31 +19,31 @@ type ResponseWriterWrapper struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hijack implements http.Hijacker. It simply calls the underlying
|
// 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) {
|
func (rww *ResponseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
if hj, ok := rww.ResponseWriter.(http.Hijacker); ok {
|
if hj, ok := rww.ResponseWriter.(http.Hijacker); ok {
|
||||||
return hj.Hijack()
|
return hj.Hijack()
|
||||||
}
|
}
|
||||||
return nil, nil, fmt.Errorf("not a hijacker")
|
return nil, nil, ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush implements http.Flusher. It simply calls the underlying
|
// 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() {
|
func (rww *ResponseWriterWrapper) Flush() {
|
||||||
if f, ok := rww.ResponseWriter.(http.Flusher); ok {
|
if f, ok := rww.ResponseWriter.(http.Flusher); ok {
|
||||||
f.Flush()
|
f.Flush()
|
||||||
} else {
|
|
||||||
panic("not a flusher")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Push implements http.Pusher. It simply calls the underlying
|
// 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 {
|
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 pusher.Push(target, opts)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("not a pusher")
|
return ErrNotImplemented
|
||||||
}
|
}
|
||||||
|
|
||||||
// HTTPInterfaces mix all the interfaces that middleware ResponseWriters need to support.
|
// HTTPInterfaces mix all the interfaces that middleware ResponseWriters need to support.
|
||||||
|
@ -54,5 +54,9 @@ type HTTPInterfaces interface {
|
||||||
http.Hijacker
|
http.Hijacker
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrNotImplemented is returned when an underlying
|
||||||
|
// ResponseWriter does not implement the required method.
|
||||||
|
var ErrNotImplemented = fmt.Errorf("method not implemented")
|
||||||
|
|
||||||
// Interface guards
|
// Interface guards
|
||||||
var _ HTTPInterfaces = (*ResponseWriterWrapper)(nil)
|
var _ HTTPInterfaces = (*ResponseWriterWrapper)(nil)
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package reverseproxy
|
package reverseproxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register caddy module.
|
// Register caddy module.
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.responders.reverse_proxy",
|
Name: "http.responders.reverse_proxy",
|
||||||
New: func() interface{} { return new(LoadBalanced) },
|
New: func() interface{} { return new(LoadBalanced) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CircuitBreaker defines the functionality of a circuit breaker module.
|
// 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.
|
// 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
|
// set defaults
|
||||||
if lb.NoHealthyUpstreamsMessage == "" {
|
if lb.NoHealthyUpstreamsMessage == "" {
|
||||||
lb.NoHealthyUpstreamsMessage = msgNoHealthyUpstreams
|
lb.NoHealthyUpstreamsMessage = msgNoHealthyUpstreams
|
||||||
|
@ -110,7 +110,7 @@ func NewLoadBalancedReverseProxy(lb *LoadBalanced, ctx caddy2.Context) error {
|
||||||
var cb CircuitBreaker
|
var cb CircuitBreaker
|
||||||
|
|
||||||
if uc.CircuitBreaker != nil {
|
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)
|
val, err := ctx.LoadModule(cbModule, uc.CircuitBreaker)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
cbv, ok := val.(CircuitBreaker)
|
cbv, ok := val.(CircuitBreaker)
|
||||||
|
@ -191,7 +191,7 @@ func (lb *LoadBalanced) Cleanup() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision sets up a new loadbalanced reverse proxy.
|
// 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)
|
return NewLoadBalancedReverseProxy(lb, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddyhttp"
|
"github.com/caddyserver/caddy/modules/caddyhttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.rewrite",
|
Name: "http.middleware.rewrite",
|
||||||
New: func() interface{} { return new(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 {
|
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
|
var rehandleNeeded bool
|
||||||
|
|
||||||
if rewr.Method != "" {
|
if rewr.Method != "" {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServerRoute represents a set of matching rules,
|
// ServerRoute represents a set of matching rules,
|
||||||
|
@ -56,7 +56,7 @@ func (mset MatcherSet) Match(r *http.Request) bool {
|
||||||
type RouteList []ServerRoute
|
type RouteList []ServerRoute
|
||||||
|
|
||||||
// Provision sets up all the routes by loading the modules.
|
// 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 {
|
for i, route := range routes {
|
||||||
// matchers
|
// matchers
|
||||||
for _, matcherSet := range route.MatcherSets {
|
for _, matcherSet := range route.MatcherSets {
|
||||||
|
|
|
@ -8,17 +8,17 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddytls"
|
"github.com/caddyserver/caddy/modules/caddytls"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Server is an HTTP server.
|
// Server is an HTTP server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Listen []string `json:"listen,omitempty"`
|
Listen []string `json:"listen,omitempty"`
|
||||||
ReadTimeout caddy2.Duration `json:"read_timeout,omitempty"`
|
ReadTimeout caddy.Duration `json:"read_timeout,omitempty"`
|
||||||
ReadHeaderTimeout caddy2.Duration `json:"read_header_timeout,omitempty"`
|
ReadHeaderTimeout caddy.Duration `json:"read_header_timeout,omitempty"`
|
||||||
WriteTimeout caddy2.Duration `json:"write_timeout,omitempty"`
|
WriteTimeout caddy.Duration `json:"write_timeout,omitempty"`
|
||||||
IdleTimeout caddy2.Duration `json:"idle_timeout,omitempty"`
|
IdleTimeout caddy.Duration `json:"idle_timeout,omitempty"`
|
||||||
MaxHeaderBytes int `json:"max_header_bytes,omitempty"`
|
MaxHeaderBytes int `json:"max_header_bytes,omitempty"`
|
||||||
Routes RouteList `json:"routes,omitempty"`
|
Routes RouteList `json:"routes,omitempty"`
|
||||||
Errors *httpErrorConfig `json:"errors,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
|
// set up the context for the request
|
||||||
repl := caddy2.NewReplacer()
|
repl := caddy.NewReplacer()
|
||||||
ctx := context.WithValue(r.Context(), caddy2.ReplacerCtxKey, repl)
|
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
|
||||||
ctx = context.WithValue(ctx, TableCtxKey, make(map[string]interface{})) // TODO: Implement this
|
ctx = context.WithValue(ctx, TableCtxKey, make(map[string]interface{})) // TODO: Implement this
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
|
|
||||||
|
@ -127,4 +127,4 @@ type httpErrorConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableCtxKey is the context key for the request's variable table.
|
// TableCtxKey is the context key for the request's variable table.
|
||||||
const TableCtxKey caddy2.CtxKey = "table"
|
const TableCtxKey caddy.CtxKey = "table"
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.responders.static",
|
Name: "http.responders.static",
|
||||||
New: func() interface{} { return new(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 {
|
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
|
// close the connection after responding
|
||||||
r.Close = s.Close
|
r.Close = s.Close
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStaticResponseHandler(t *testing.T) {
|
func TestStaticResponseHandler(t *testing.T) {
|
||||||
|
@ -44,8 +44,8 @@ func TestStaticResponseHandler(t *testing.T) {
|
||||||
|
|
||||||
func fakeRequest() *http.Request {
|
func fakeRequest() *http.Request {
|
||||||
r, _ := http.NewRequest("GET", "/", nil)
|
r, _ := http.NewRequest("GET", "/", nil)
|
||||||
repl := caddy2.NewReplacer()
|
repl := caddy.NewReplacer()
|
||||||
ctx := context.WithValue(r.Context(), caddy2.ReplacerCtxKey, repl)
|
ctx := context.WithValue(r.Context(), caddy.ReplacerCtxKey, repl)
|
||||||
r = r.WithContext(ctx)
|
r = r.WithContext(ctx)
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,16 +3,16 @@ package caddyhttp
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.middleware.table",
|
Name: "http.middleware.table",
|
||||||
New: func() interface{} { return new(tableMiddleware) },
|
New: func() interface{} { return new(tableMiddleware) },
|
||||||
})
|
})
|
||||||
|
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "http.matchers.table",
|
Name: "http.matchers.table",
|
||||||
New: func() interface{} { return new(tableMatcher) },
|
New: func() interface{} { return new(tableMatcher) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
|
|
||||||
"github.com/go-acme/lego/certcrypto"
|
"github.com/go-acme/lego/certcrypto"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/go-acme/lego/challenge"
|
"github.com/go-acme/lego/challenge"
|
||||||
"github.com/mholt/certmagic"
|
"github.com/mholt/certmagic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls.management.acme",
|
Name: "tls.management.acme",
|
||||||
New: func() interface{} { return new(ACMEManagerMaker) },
|
New: func() interface{} { return new(ACMEManagerMaker) },
|
||||||
})
|
})
|
||||||
|
@ -30,9 +30,9 @@ func init() {
|
||||||
type ACMEManagerMaker struct {
|
type ACMEManagerMaker struct {
|
||||||
CA string `json:"ca,omitempty"`
|
CA string `json:"ca,omitempty"`
|
||||||
Email string `json:"email,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"`
|
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"`
|
MustStaple bool `json:"must_staple,omitempty"`
|
||||||
Challenges ChallengesConfig `json:"challenges"`
|
Challenges ChallengesConfig `json:"challenges"`
|
||||||
OnDemand *OnDemandConfig `json:"on_demand,omitempty"`
|
OnDemand *OnDemandConfig `json:"on_demand,omitempty"`
|
||||||
|
@ -49,7 +49,7 @@ func (m *ACMEManagerMaker) newManager(interactive bool) (certmagic.Manager, erro
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision sets up m.
|
// Provision sets up m.
|
||||||
func (m *ACMEManagerMaker) Provision(ctx caddy2.Context) error {
|
func (m *ACMEManagerMaker) Provision(ctx caddy.Context) error {
|
||||||
// DNS providers
|
// DNS providers
|
||||||
if m.Challenges.DNS != nil {
|
if m.Challenges.DNS != nil {
|
||||||
val, err := ctx.LoadModuleInline("provider", "tls.dns", m.Challenges.DNSRaw)
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("loading TLS storage module: %s", err)
|
return fmt.Errorf("loading TLS storage module: %s", err)
|
||||||
}
|
}
|
||||||
cmStorage, err := val.(caddy2.StorageConverter).CertMagicStorage()
|
cmStorage, err := val.(caddy.StorageConverter).CertMagicStorage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("creating TLS storage configuration: %v", err)
|
return fmt.Errorf("creating TLS storage configuration: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ func (m *ACMEManagerMaker) SetDefaults() {
|
||||||
m.Email = certmagic.Default.Email
|
m.Email = certmagic.Default.Email
|
||||||
}
|
}
|
||||||
if m.RenewAhead == 0 {
|
if m.RenewAhead == 0 {
|
||||||
m.RenewAhead = caddy2.Duration(certmagic.Default.RenewDurationBefore)
|
m.RenewAhead = caddy.Duration(certmagic.Default.RenewDurationBefore)
|
||||||
}
|
}
|
||||||
if m.keyType == "" {
|
if m.keyType == "" {
|
||||||
m.keyType = certmagic.Default.KeyType
|
m.keyType = certmagic.Default.KeyType
|
||||||
|
@ -102,7 +102,7 @@ func (m *ACMEManagerMaker) SetDefaults() {
|
||||||
// makeCertMagicConfig converts m into a certmagic.Config, because
|
// makeCertMagicConfig converts m into a certmagic.Config, because
|
||||||
// this is a special case where the default manager is the certmagic
|
// this is a special case where the default manager is the certmagic
|
||||||
// Config and not a separate manager.
|
// 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
|
storage := m.storage
|
||||||
if storage == nil {
|
if storage == nil {
|
||||||
storage = ctx.Storage()
|
storage = ctx.Storage()
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/go-acme/lego/challenge/tlsalpn01"
|
"github.com/go-acme/lego/challenge/tlsalpn01"
|
||||||
"github.com/mholt/certmagic"
|
"github.com/mholt/certmagic"
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ type ConnectionPolicies []*ConnectionPolicy
|
||||||
// TLSConfig converts the group of policies to a standard-lib-compatible
|
// TLSConfig converts the group of policies to a standard-lib-compatible
|
||||||
// TLS configuration which selects the first matching policy based on
|
// TLS configuration which selects the first matching policy based on
|
||||||
// the ClientHello.
|
// 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
|
// set up each of the connection policies
|
||||||
for i, pol := range cp {
|
for i, pol := range cp {
|
||||||
// matchers
|
// matchers
|
||||||
|
@ -110,7 +110,7 @@ type ConnectionPolicy struct {
|
||||||
stdTLSConfig *tls.Config
|
stdTLSConfig *tls.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy2.Context) error {
|
func (p *ConnectionPolicy) buildStandardTLSConfig(ctx caddy.Context) error {
|
||||||
tlsAppIface, err := ctx.App("tls")
|
tlsAppIface, err := ctx.App("tls")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("getting tls app: %v", err)
|
return fmt.Errorf("getting tls app: %v", err)
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls.certificates.load_files",
|
Name: "tls.certificates.load_files",
|
||||||
New: func() interface{} { return fileLoader{} },
|
New: func() interface{} { return fileLoader{} },
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,11 +10,11 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls.certificates.load_folders",
|
Name: "tls.certificates.load_folders",
|
||||||
New: func() interface{} { return folderLoader{} },
|
New: func() interface{} { return folderLoader{} },
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,14 +3,14 @@ package caddytls
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MatchServerName matches based on SNI.
|
// MatchServerName matches based on SNI.
|
||||||
type MatchServerName []string
|
type MatchServerName []string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls.handshake_match.sni",
|
Name: "tls.handshake_match.sni",
|
||||||
New: func() interface{} { return MatchServerName{} },
|
New: func() interface{} { return MatchServerName{} },
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,13 +9,13 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SessionTicketService configures and manages TLS session tickets.
|
// SessionTicketService configures and manages TLS session tickets.
|
||||||
type SessionTicketService struct {
|
type SessionTicketService struct {
|
||||||
KeySource json.RawMessage `json:"key_source,omitempty"`
|
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"`
|
MaxKeys int `json:"max_keys,omitempty"`
|
||||||
DisableRotation bool `json:"disable_rotation,omitempty"`
|
DisableRotation bool `json:"disable_rotation,omitempty"`
|
||||||
Disabled bool `json:"disabled,omitempty"`
|
Disabled bool `json:"disabled,omitempty"`
|
||||||
|
@ -27,13 +27,13 @@ type SessionTicketService struct {
|
||||||
mu *sync.Mutex
|
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.configs = make(map[*tls.Config]struct{})
|
||||||
s.mu = new(sync.Mutex)
|
s.mu = new(sync.Mutex)
|
||||||
|
|
||||||
// establish sane defaults
|
// establish sane defaults
|
||||||
if s.RotationInterval == 0 {
|
if s.RotationInterval == 0 {
|
||||||
s.RotationInterval = caddy2.Duration(defaultSTEKRotationInterval)
|
s.RotationInterval = caddy.Duration(defaultSTEKRotationInterval)
|
||||||
}
|
}
|
||||||
if s.MaxKeys <= 0 {
|
if s.MaxKeys <= 0 {
|
||||||
s.MaxKeys = defaultMaxSTEKs
|
s.MaxKeys = defaultMaxSTEKs
|
||||||
|
|
|
@ -5,12 +5,12 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/caddyserver/caddy2/modules/caddytls"
|
"github.com/caddyserver/caddy/modules/caddytls"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls.stek.standard",
|
Name: "tls.stek.standard",
|
||||||
New: func() interface{} { return new(standardSTEKProvider) },
|
New: func() interface{} { return new(standardSTEKProvider) },
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,13 +6,13 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/caddyserver/caddy2"
|
"github.com/caddyserver/caddy"
|
||||||
"github.com/go-acme/lego/challenge"
|
"github.com/go-acme/lego/challenge"
|
||||||
"github.com/mholt/certmagic"
|
"github.com/mholt/certmagic"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
caddy2.RegisterModule(caddy2.Module{
|
caddy.RegisterModule(caddy.Module{
|
||||||
Name: "tls",
|
Name: "tls",
|
||||||
New: func() interface{} { return new(TLS) },
|
New: func() interface{} { return new(TLS) },
|
||||||
})
|
})
|
||||||
|
@ -26,11 +26,11 @@ type TLS struct {
|
||||||
|
|
||||||
certificateLoaders []CertificateLoader
|
certificateLoaders []CertificateLoader
|
||||||
certCache *certmagic.Cache
|
certCache *certmagic.Cache
|
||||||
ctx caddy2.Context
|
ctx caddy.Context
|
||||||
}
|
}
|
||||||
|
|
||||||
// Provision sets up the configuration for the TLS app.
|
// 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
|
t.ctx = ctx
|
||||||
|
|
||||||
// set up the certificate cache
|
// set up the certificate cache
|
||||||
|
@ -189,7 +189,7 @@ type AutomationPolicy struct {
|
||||||
Management managerMaker `json:"-"`
|
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
|
// 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
|
// 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...
|
// its config fields out of the certmagic.Config struct, or something...
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
|
@ -3,7 +3,7 @@ package caddyscript
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
caddyscript "github.com/caddyserver/caddy2/pkg/caddyscript/lib"
|
caddyscript "github.com/caddyserver/caddy/pkg/caddyscript/lib"
|
||||||
"go.starlark.net/starlark"
|
"go.starlark.net/starlark"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package caddy2
|
package caddy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
Loading…
Reference in a new issue