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
+52
-17
@@ -108,9 +108,12 @@ func New(params Params) *Server {
|
||||
|
||||
return &Server{
|
||||
Server: &http.Server{
|
||||
Addr: params.Config.ListenAddr,
|
||||
Handler: h,
|
||||
ErrorLog: slog.NewLogLogger(params.ProcessLog.Handler(), slog.LevelWarn),
|
||||
Addr: params.Config.ListenAddr,
|
||||
Handler: h,
|
||||
ErrorLog: slog.NewLogLogger(
|
||||
params.ProcessLog.Handler(),
|
||||
slog.LevelWarn,
|
||||
),
|
||||
ReadTimeout: wafTimeout,
|
||||
WriteTimeout: wafTimeout,
|
||||
IdleTimeout: wafIdleTimeout,
|
||||
@@ -153,7 +156,8 @@ func (rq *request) refusedWhateverTheAnswer(now time.Time) bool {
|
||||
|
||||
_, decided := rq.crowdSecDecisionInForce(now)
|
||||
|
||||
return decided || rq.refusedByBlocklists(rq.h.lists.ListedBy(rq.client)) ||
|
||||
return decided ||
|
||||
rq.refusedByBlocklists(rq.h.lists.ListedBy(rq.client)) ||
|
||||
rq.overAWholeRateLimit(now)
|
||||
}
|
||||
|
||||
@@ -169,8 +173,13 @@ func (h *handler) answerQuestion(w http.ResponseWriter, r *http.Request) {
|
||||
// One that cannot be read leaves the log line's peer_ip invalid.
|
||||
peer, _ := netip.ParseAddr(r.Header.Get(PeerHeader))
|
||||
|
||||
rq := h.startRequest(w, asTheVisitorSentIt(r, body), client.Unmap(), peer.Unmap(),
|
||||
true)
|
||||
rq := h.startRequest(
|
||||
w,
|
||||
asTheVisitorSentIt(r, body),
|
||||
client.Unmap(),
|
||||
peer.Unmap(),
|
||||
true,
|
||||
)
|
||||
// The last deferred runs first, so that what is held has the finished log
|
||||
// line. Go's server sends the answer only once this function has
|
||||
// returned, so the report cannot come before it is held.
|
||||
@@ -208,7 +217,11 @@ func (h *handler) answerQuestion(w http.ResponseWriter, r *http.Request) {
|
||||
// own address, so this answers as a path with no endpoint does.
|
||||
rq.line.Action = requestlog.ActionOwnEndpoint
|
||||
rq.out.Header().Set(DispositionHeader, DispositionDeny)
|
||||
http.Error(rq.out, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
http.Error(
|
||||
rq.out,
|
||||
http.StatusText(http.StatusNotFound),
|
||||
http.StatusNotFound,
|
||||
)
|
||||
}
|
||||
|
||||
// readQuestion returns the visitor's address and the body a question carries,
|
||||
@@ -238,7 +251,9 @@ func (h *handler) readQuestion(
|
||||
return netip.Addr{}, nil, false
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, QuestionBodyMaxBytes))
|
||||
body, err := io.ReadAll(
|
||||
http.MaxBytesReader(w, r.Body, QuestionBodyMaxBytes),
|
||||
)
|
||||
|
||||
if _, tooLarge := errors.AsType[*http.MaxBytesError](err); tooLarge {
|
||||
h.refuseQuestion(w, "the body is over 64 KiB")
|
||||
@@ -247,7 +262,11 @@ func (h *handler) readQuestion(
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
h.processLog.Warn("a question's body stopped arriving", "error", err.Error())
|
||||
h.processLog.Warn(
|
||||
"a question's body stopped arriving",
|
||||
"error",
|
||||
err.Error(),
|
||||
)
|
||||
// This panic has Go's server close the connection without an answer,
|
||||
// and log nothing.
|
||||
panic(http.ErrAbortHandler)
|
||||
@@ -255,7 +274,10 @@ func (h *handler) readQuestion(
|
||||
|
||||
held, _ := h.awaitingReport.ContainsOrAdd(id, nil)
|
||||
if held {
|
||||
h.refuseQuestion(w, requestIDHeader+" is the id of a request waf holds")
|
||||
h.refuseQuestion(
|
||||
w,
|
||||
requestIDHeader+" is the id of a request waf holds",
|
||||
)
|
||||
|
||||
return netip.Addr{}, nil, false
|
||||
}
|
||||
@@ -389,7 +411,9 @@ func (h *handler) takeReport(w http.ResponseWriter, r *http.Request) {
|
||||
func readReport(w http.ResponseWriter, r *http.Request) (Report, error) {
|
||||
var report Report
|
||||
|
||||
body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, reportBodyMaxBytes))
|
||||
body, err := io.ReadAll(
|
||||
http.MaxBytesReader(w, r.Body, reportBodyMaxBytes),
|
||||
)
|
||||
if err != nil {
|
||||
return report, fmt.Errorf("read the body: %w", err)
|
||||
}
|
||||
@@ -445,11 +469,18 @@ func (report *Report) checkRanges() error {
|
||||
// request to its client's history, the anomaly counters and the metrics, with
|
||||
// the status and bytes the report gives. A denied request's counting was
|
||||
// finished at its decision. ctx is the report's own context.
|
||||
func (h *handler) finishWith(ctx context.Context, held *decision, report Report) {
|
||||
func (h *handler) finishWith(
|
||||
ctx context.Context,
|
||||
held *decision,
|
||||
report Report,
|
||||
) {
|
||||
rq := &request{
|
||||
decision: *held,
|
||||
h: h,
|
||||
out: &responseWriter{status: report.Status, bytes: report.ResponseBytes},
|
||||
decision: *held,
|
||||
h: h,
|
||||
out: &responseWriter{
|
||||
status: report.Status,
|
||||
bytes: report.ResponseBytes,
|
||||
},
|
||||
requestBytes: report.RequestBytes,
|
||||
}
|
||||
|
||||
@@ -466,9 +497,13 @@ func (h *handler) finishWith(ctx context.Context, held *decision, report Report)
|
||||
rq.countAnomalies()
|
||||
rq.addToHistory()
|
||||
|
||||
rq.h.metrics.RequestReported(&rq.line,
|
||||
rq.h.metrics.RequestReported(
|
||||
&rq.line,
|
||||
time.Duration(report.DurationTotalMS*float64(time.Millisecond)),
|
||||
time.Duration(report.DurationUpstreamTotalMS*float64(time.Millisecond)))
|
||||
time.Duration(
|
||||
report.DurationUpstreamTotalMS*float64(time.Millisecond),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
rq.writeLine()
|
||||
|
||||
Reference in new issue
Block a user