script/fmt now runs golines -m 77 after gofmt, repeating golines until it changes nothing, since one pass can leave a line the next splits. script/fmt-check fails when either would change a file. script/bootstrap installs golines v0.13.0 with go install, pinned to its commit, and checks the installed version with go version -m. The tree is reformatted. The longer lines this makes are fixed by hand: nolint directives moved onto their own line above the statement, one string split, and 20 functions over funlen's 80 lines shortened or split, RunWAF and limitPercentages among them. Model: opus-5-5
This commit is contained in:
1 parent
63e58e326b
commit
7f8a59de04
118 files changed
+9447
-2670
No files matched your search
+24
-7
@@ -23,7 +23,9 @@ const answerBodyMaxBytes = 1 << 20
|
||||
const reportAnswerMaxBytes = 4 << 10
|
||||
|
||||
var (
|
||||
errCannotPassOn = errors.New("the answer cannot be passed to the visitor")
|
||||
errCannotPassOn = errors.New(
|
||||
"the answer cannot be passed to the visitor",
|
||||
)
|
||||
errReportRefused = errors.New("the report was answered")
|
||||
)
|
||||
|
||||
@@ -108,7 +110,11 @@ func (rq *request) ask(ctx context.Context) (*wafAnswer, error) {
|
||||
// a read of that. Go's client also takes a status below 100, which Go's server
|
||||
// panics when asked to send.
|
||||
if res.StatusCode < http.StatusOK {
|
||||
return nil, fmt.Errorf("%w: its status is %d", errCannotPassOn, res.StatusCode)
|
||||
return nil, fmt.Errorf(
|
||||
"%w: its status is %d",
|
||||
errCannotPassOn,
|
||||
res.StatusCode,
|
||||
)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(io.LimitReader(res.Body, answerBodyMaxBytes+1))
|
||||
@@ -133,10 +139,14 @@ func (rq *request) ask(ctx context.Context) (*wafAnswer, error) {
|
||||
// waf.
|
||||
func canBeAsked(r *http.Request) bool {
|
||||
target, host := r.RequestURI, r.Host
|
||||
hostHasZone := strings.HasPrefix(host, "[") && strings.Contains(host, "%")
|
||||
hostHasZone := strings.HasPrefix(host, "[") &&
|
||||
strings.Contains(host, "%")
|
||||
|
||||
return strings.HasPrefix(target, "/") && !strings.HasPrefix(target, "//") &&
|
||||
host != "" && !hostHasZone && len(r.Header.Values("User-Agent")) <= 1
|
||||
return strings.HasPrefix(target, "/") &&
|
||||
!strings.HasPrefix(target, "//") &&
|
||||
host != "" &&
|
||||
!hostHasZone &&
|
||||
len(r.Header.Values("User-Agent")) <= 1
|
||||
}
|
||||
|
||||
// newQuestion returns the question about the request, as "The question" in
|
||||
@@ -151,7 +161,11 @@ func (rq *request) newQuestion(ctx context.Context) (*http.Request, error) {
|
||||
}
|
||||
|
||||
question, err := http.NewRequestWithContext( //nolint:gosec // a setting's URL
|
||||
ctx, in.Method, rq.h.config.WAFBackend.String(), bytes.NewReader(held))
|
||||
ctx,
|
||||
in.Method,
|
||||
rq.h.config.WAFBackend.String(),
|
||||
bytes.NewReader(held),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("make the question: %w", err)
|
||||
}
|
||||
@@ -254,7 +268,10 @@ func (h *handler) postReport(ctx context.Context, report *waf.Report) error {
|
||||
// The body of a 101 is the connection itself, and the time limit does not end
|
||||
// a read of that.
|
||||
if res.StatusCode >= http.StatusOK {
|
||||
_, _ = io.Copy(io.Discard, io.LimitReader(res.Body, reportAnswerMaxBytes))
|
||||
_, _ = io.Copy(
|
||||
io.Discard,
|
||||
io.LimitReader(res.Body, reportAnswerMaxBytes),
|
||||
)
|
||||
}
|
||||
|
||||
_ = res.Body.Close()
|
||||
|
||||
Reference in new issue
Block a user