Skip to content

Commit 6312101

Browse files
committed
Merge remote-tracking branch 'upstream/master' into otel-client
2 parents 21448b6 + 6ab9fb6 commit 6312101

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+883
-353
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- name: golangci-lint
5050
uses: golangci/golangci-lint-action@v6
5151
with:
52-
version: v1.60
52+
version: latest
5353

5454
# Windows times out frequently after about 5m50s if we don't set a longer timeout.
5555
args: --timeout 10m

.golangci.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ linters:
3535
- errcheck
3636
- errname
3737
- exhaustive
38-
- exportloopref
3938
- gci
4039
- gofmt
4140
- goimports
@@ -145,6 +144,9 @@ output:
145144

146145
issues:
147146
exclude-rules:
147+
- text: 'G115' # TODO: Either we should fix the issues or nuke the linter if it's bad
148+
linters:
149+
- gosec
148150
# we aren't calling unknown URL
149151
- text: 'G107' # G107: Url provided to HTTP request as taint input
150152
linters:

.goreleaser.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ before:
1212
- mkdir -p caddy-build
1313
- cp cmd/caddy/main.go caddy-build/main.go
1414
- /bin/sh -c 'cd ./caddy-build && go mod init caddy'
15+
# prepare syso files for windows embedding
16+
- go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
17+
- /bin/sh -c 'for a in amd64 arm arm64; do XCADDY_SKIP_BUILD=1 GOOS=windows GOARCH=$a $GOPATH/bin/xcaddy build {{.Env.TAG}}; done'
18+
- /bin/sh -c 'mv /tmp/buildenv_*/*.syso caddy-build'
1519
# GoReleaser doesn't seem to offer {{.Tag}} at this stage, so we have to embed it into the env
1620
# so we run: TAG=$(git describe --abbrev=0) goreleaser release --rm-dist --skip-publish --skip-validate
1721
- go mod edit -require=github.com/caddyserver/caddy/v2@{{.Env.TAG}} ./caddy-build/go.mod
@@ -31,7 +35,6 @@ builds:
3135
- env:
3236
- CGO_ENABLED=0
3337
- GO111MODULE=on
34-
main: main.go
3538
dir: ./caddy-build
3639
binary: caddy
3740
goos:

caddytest/integration/caddyfile_adapt/file_server_sort.caddyfiletest

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
:80
22

3-
file_server browse {
4-
sort size desc
3+
file_server {
4+
browse {
5+
sort size desc
6+
}
57
}
68
----------
79
{
@@ -16,14 +18,15 @@ file_server browse {
1618
{
1719
"handle": [
1820
{
19-
"browse": {},
21+
"browse": {
22+
"sort": [
23+
"size",
24+
"desc"
25+
]
26+
},
2027
"handler": "file_server",
2128
"hide": [
2229
"./Caddyfile"
23-
],
24-
"sort": [
25-
"size",
26-
"desc"
2730
]
2831
}
2932
]

cmd/caddy/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// The below line is required to enable post-quantum key agreement in Go 1.23
2+
// by default without insisting on setting a minimum version of 1.23 in go.mod.
3+
// See https://github.com/caddyserver/caddy/issues/6540#issuecomment-2313094905
4+
//go:debug tlskyber=1
5+
16
// Copyright 2015 Matthew Holt and The Caddy Authors
27
//
38
// Licensed under the Apache License, Version 2.0 (the "License");

modules/caddyhttp/caddyauth/caddyauth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net/http"
2020

2121
"go.uber.org/zap"
22+
"go.uber.org/zap/zapcore"
2223

2324
"github.com/caddyserver/caddy/v2"
2425
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
@@ -76,9 +77,9 @@ func (a Authentication) ServeHTTP(w http.ResponseWriter, r *http.Request, next c
7677
for provName, prov := range a.Providers {
7778
user, authed, err = prov.Authenticate(w, r)
7879
if err != nil {
79-
a.logger.Error("auth provider returned error",
80-
zap.String("provider", provName),
81-
zap.Error(err))
80+
if c := a.logger.Check(zapcore.ErrorLevel, "auth provider returned error"); c != nil {
81+
c.Write(zap.String("provider", provName), zap.Error(err))
82+
}
8283
continue
8384
}
8485
if authed {

modules/caddyhttp/fileserver/browse.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"time"
3434

3535
"go.uber.org/zap"
36+
"go.uber.org/zap/zapcore"
3637

3738
"github.com/caddyserver/caddy/v2"
3839
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
@@ -52,14 +53,25 @@ var BrowseTemplate string
5253
type Browse struct {
5354
// Filename of the template to use instead of the embedded browse template.
5455
TemplateFile string `json:"template_file,omitempty"`
56+
5557
// Determines whether or not targets of symlinks should be revealed.
5658
RevealSymlinks bool `json:"reveal_symlinks,omitempty"`
59+
60+
// Override the default sort.
61+
// It includes the following options:
62+
// - sort_by: name(default), namedirfirst, size, time
63+
// - order: asc(default), desc
64+
// eg.:
65+
// - `sort time desc` will sort by time in descending order
66+
// - `sort size` will sort by size in ascending order
67+
// The first option must be `sort_by` and the second option must be `order` (if exists).
68+
SortOptions []string `json:"sort,omitempty"`
5769
}
5870

5971
func (fsrv *FileServer) serveBrowse(fileSystem fs.FS, root, dirPath string, w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
60-
fsrv.logger.Debug("browse enabled; listing directory contents",
61-
zap.String("path", dirPath),
62-
zap.String("root", root))
72+
if c := fsrv.logger.Check(zapcore.DebugLevel, "browse enabled; listing directory contents"); c != nil {
73+
c.Write(zap.String("path", dirPath), zap.String("root", root))
74+
}
6375

6476
// Navigation on the client-side gets messed up if the
6577
// URL doesn't end in a trailing slash because hrefs to
@@ -81,7 +93,9 @@ func (fsrv *FileServer) serveBrowse(fileSystem fs.FS, root, dirPath string, w ht
8193
origReq := r.Context().Value(caddyhttp.OriginalRequestCtxKey).(http.Request)
8294
if r.URL.Path == "" || path.Base(origReq.URL.Path) == path.Base(r.URL.Path) {
8395
if !strings.HasSuffix(origReq.URL.Path, "/") {
84-
fsrv.logger.Debug("redirecting to trailing slash to preserve hrefs", zap.String("request_path", r.URL.Path))
96+
if c := fsrv.logger.Check(zapcore.DebugLevel, "redirecting to trailing slash to preserve hrefs"); c != nil {
97+
c.Write(zap.String("request_path", r.URL.Path))
98+
}
8599
return redirect(w, r, origReq.URL.Path+"/")
86100
}
87101
}
@@ -210,7 +224,7 @@ func (fsrv *FileServer) browseApplyQueryParams(w http.ResponseWriter, r *http.Re
210224

211225
// The configs in Caddyfile have lower priority than Query params,
212226
// so put it at first.
213-
for idx, item := range fsrv.SortOptions {
227+
for idx, item := range fsrv.Browse.SortOptions {
214228
// Only `sort` & `order`, 2 params are allowed
215229
if idx >= 2 {
216230
break

modules/caddyhttp/fileserver/browsetplcontext.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/dustin/go-humanize"
3030
"go.uber.org/zap"
31+
"go.uber.org/zap/zapcore"
3132

3233
"github.com/caddyserver/caddy/v2"
3334
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
@@ -57,9 +58,9 @@ func (fsrv *FileServer) directoryListing(ctx context.Context, fileSystem fs.FS,
5758

5859
info, err := entry.Info()
5960
if err != nil {
60-
fsrv.logger.Error("could not get info about directory entry",
61-
zap.String("name", entry.Name()),
62-
zap.String("root", root))
61+
if c := fsrv.logger.Check(zapcore.ErrorLevel, "could not get info about directory entry"); c != nil {
62+
c.Write(zap.String("name", entry.Name()), zap.String("root", root))
63+
}
6364
continue
6465
}
6566

modules/caddyhttp/fileserver/caddyfile.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
119119
return d.Err("Symlinks path reveal is already enabled")
120120
}
121121
fsrv.Browse.RevealSymlinks = true
122+
case "sort":
123+
for d.NextArg() {
124+
dVal := d.Val()
125+
switch dVal {
126+
case sortByName, sortByNameDirFirst, sortBySize, sortByTime, sortOrderAsc, sortOrderDesc:
127+
fsrv.Browse.SortOptions = append(fsrv.Browse.SortOptions, dVal)
128+
default:
129+
return d.Errf("unknown sort option '%s'", dVal)
130+
}
131+
}
122132
default:
123133
return d.Errf("unknown subdirective '%s'", d.Val())
124134
}
@@ -171,17 +181,6 @@ func (fsrv *FileServer) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
171181
}
172182
fsrv.EtagFileExtensions = etagFileExtensions
173183

174-
case "sort":
175-
for d.NextArg() {
176-
dVal := d.Val()
177-
switch dVal {
178-
case sortByName, sortBySize, sortByTime, sortOrderAsc, sortOrderDesc:
179-
fsrv.SortOptions = append(fsrv.SortOptions, dVal)
180-
default:
181-
return d.Errf("unknown sort option '%s'", dVal)
182-
}
183-
}
184-
185184
default:
186185
return d.Errf("unknown subdirective '%s'", d.Val())
187186
}

modules/caddyhttp/fileserver/matcher.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/google/cel-go/common/types/ref"
3434
"github.com/google/cel-go/parser"
3535
"go.uber.org/zap"
36+
"go.uber.org/zap/zapcore"
3637

3738
"github.com/caddyserver/caddy/v2"
3839
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
@@ -326,7 +327,9 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {
326327

327328
fileSystem, ok := m.fsmap.Get(fsName)
328329
if !ok {
329-
m.logger.Error("use of unregistered filesystem", zap.String("fs", fsName))
330+
if c := m.logger.Check(zapcore.ErrorLevel, "use of unregistered filesystem"); c != nil {
331+
c.Write(zap.String("fs", fsName))
332+
}
330333
return false
331334
}
332335
type matchCandidate struct {
@@ -356,7 +359,10 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {
356359
return val, nil
357360
})
358361
if err != nil {
359-
m.logger.Error("evaluating placeholders", zap.Error(err))
362+
if c := m.logger.Check(zapcore.ErrorLevel, "evaluating placeholders"); c != nil {
363+
c.Write(zap.Error(err))
364+
}
365+
360366
expandedFile = file // "oh well," I guess?
361367
}
362368

@@ -379,7 +385,9 @@ func (m MatchFile) selectFile(r *http.Request) (matched bool) {
379385
} else {
380386
globResults, err = fs.Glob(fileSystem, fullPattern)
381387
if err != nil {
382-
m.logger.Error("expanding glob", zap.Error(err))
388+
if c := m.logger.Check(zapcore.ErrorLevel, "expanding glob"); c != nil {
389+
c.Write(zap.Error(err))
390+
}
383391
}
384392
}
385393

0 commit comments

Comments
 (0)