p2: 120s write timeout and flags after the URL
WriteTimeout 30s was cutting digest mid-flight (queue+fetch+digest) and tailscale then 502'd. 120s write, 90s handler deadline. sift fetch URL --question now parses; extra positionals error.
This commit is contained in:
+13
-2
@@ -1,6 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
@@ -24,7 +25,11 @@ import (
|
||||
"git.wntrmute.dev/kyle/sift/internal/selfip"
|
||||
)
|
||||
|
||||
const maxReqBody = 64 << 10
|
||||
const (
|
||||
maxReqBody = 64 << 10
|
||||
writeTimeout = 120 * time.Second
|
||||
requestDeadline = 90 * time.Second
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
Version string
|
||||
@@ -74,7 +79,7 @@ func (s *Server) HTTPServer(addr string) *http.Server {
|
||||
Handler: s,
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
WriteTimeout: writeTimeout,
|
||||
IdleTimeout: 30 * time.Second,
|
||||
MaxHeaderBytes: 16 << 10,
|
||||
}
|
||||
@@ -82,6 +87,12 @@ func (s *Server) HTTPServer(addr string) *http.Server {
|
||||
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxReqBody)
|
||||
switch r.URL.Path {
|
||||
case "/v1/fetch", "/v2/scrape":
|
||||
ctx, cancel := context.WithTimeout(r.Context(), requestDeadline)
|
||||
defer cancel()
|
||||
r = r.WithContext(ctx)
|
||||
}
|
||||
s.Mux.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user