mirror of
https://github.com/vee1e/subidx.git
synced 2026-09-01 09:50:18 +00:00
serve: add HTTP timeouts and bind localhost by default
The server had no read/write/idle timeouts, so slowloris connections held goroutines and file descriptors forever, and the default address bound all interfaces, exposing the API to the network unintentionally. Defaults now match the tool's local-search use case; add timeouts and cap header size.
This commit is contained in:
parent
2be376e728
commit
c8207996d1
2 changed files with 11 additions and 3 deletions
|
|
@ -41,7 +41,7 @@ Useful flags:
|
|||
| Flag | Default | Meaning |
|
||||
|---|---|---|
|
||||
| `-store` | `./data` | Where the database lives |
|
||||
| `-addr` | `:8080` | Listen address for `serve` |
|
||||
| `-addr` | `127.0.0.1:8080` | Listen address for `serve` (binds localhost by default; use `:8080` to expose) |
|
||||
| `-poll-interval` | `3s` | How often each log is checked for new entries |
|
||||
| `-window` | `512` | Entries fetched per request while catching up |
|
||||
| `-no-drain` | off | Skip old and rejected logs (they hold years of history, terabytes) |
|
||||
|
|
|
|||
12
main.go
12
main.go
|
|
@ -96,7 +96,7 @@ func addCommon(fs *flag.FlagSet) *commonConfig {
|
|||
func cmdServe(args []string) error {
|
||||
fs := flag.NewFlagSet("serve", flag.ExitOnError)
|
||||
c := addCommon(fs)
|
||||
addr := fs.String("addr", ":8080", "listen address")
|
||||
addr := fs.String("addr", "127.0.0.1:8080", "listen address")
|
||||
noTail := fs.Bool("no-tail", false, "disable CT tailers")
|
||||
rateLimit := fs.Int64("rate-limit", 1000, "requests per rolling 24h per IP")
|
||||
maxResults := fs.Int("max-results", store.DefaultScanLimit, "max results buffered per search query")
|
||||
|
|
@ -137,7 +137,15 @@ func cmdServe(args []string) error {
|
|||
}
|
||||
srv.Limiter.StartSweeper(ctx.Done())
|
||||
|
||||
httpSrv := &http.Server{Addr: *addr, Handler: srv.Handler()}
|
||||
httpSrv := &http.Server{
|
||||
Addr: *addr,
|
||||
Handler: srv.Handler(),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 30 * time.Second,
|
||||
WriteTimeout: 60 * time.Second,
|
||||
IdleTimeout: 120 * time.Second,
|
||||
MaxHeaderBytes: 8192,
|
||||
}
|
||||
errCh := make(chan error, 1)
|
||||
go func() { errCh <- httpSrv.ListenAndServe() }()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue