Skip to content

Commit 0fd9649

Browse files
committed
fix(config): remove dead read_header_timeout setting (fasthttp has no such field)
fasthttp uses a single ReadTimeout covering the full read phase (headers + body). The separate read_header_timeout config field was parsed and defaulted but never applied to the server — dead code since the fasthttp migration. - Remove struct field, default, and env override from config.go - Remove assertion from config_test.go - Remove from both config.toml.example files - Update README.md, USER_GUIDE.md, docs/index.html: remove setting from config tables and env vars tables, note ReadTimeout provides Slowloris protection
1 parent 65cfb13 commit 0fd9649

7 files changed

Lines changed: 10 additions & 33 deletions

File tree

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Only `GET`, `HEAD`, and `OPTIONS` are accepted. All other methods (including `TR
211211

212212
| Mitigation | Value |
213213
|------------|-------|
214-
| `ReadTimeout` | 10 s |
214+
| `ReadTimeout` | 10 s (covers full read phase including headers — Slowloris protection) |
215215
| `WriteTimeout` | 10 s |
216216
| `IdleTimeout` | 75 s (keep-alive) |
217217
| `MaxRequestBodySize` | 0 (no body accepted — static server) |
@@ -231,8 +231,7 @@ Copy `config.toml.example` to `config.toml` and edit as needed. The server start
231231
| `redirect_host` | string || Canonical host used for HTTP→HTTPS redirects |
232232
| `tls_cert` | string || Path to TLS certificate (PEM) |
233233
| `tls_key` | string || Path to TLS private key (PEM) |
234-
| `read_header_timeout` | duration | `5s` | Slowloris protection |
235-
| `read_timeout` | duration | `10s` | Full request read deadline |
234+
| `read_timeout` | duration | `10s` | Full request read deadline (covers headers; Slowloris protection) |
236235
| `write_timeout` | duration | `10s` | Response write deadline |
237236
| `idle_timeout` | duration | `75s` | Keep-alive idle timeout |
238237
| `shutdown_timeout` | duration | `15s` | Graceful drain window |
@@ -299,7 +298,6 @@ All environment variables override the corresponding TOML setting. Useful for co
299298
| `STATIC_SERVER_REDIRECT_HOST` | `server.redirect_host` |
300299
| `STATIC_SERVER_TLS_CERT` | `server.tls_cert` |
301300
| `STATIC_SERVER_TLS_KEY` | `server.tls_key` |
302-
| `STATIC_SERVER_READ_HEADER_TIMEOUT` | `server.read_header_timeout` |
303301
| `STATIC_SERVER_READ_TIMEOUT` | `server.read_timeout` |
304302
| `STATIC_SERVER_WRITE_TIMEOUT` | `server.write_timeout` |
305303
| `STATIC_SERVER_IDLE_TIMEOUT` | `server.idle_timeout` |

USER_GUIDE.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ tls_addr = ":8443" # HTTPS listen address (requires tls_cert + tls
113113
redirect_host = "" # canonical host for HTTP→HTTPS redirects (recommended in production)
114114
tls_cert = "" # path to PEM certificate file
115115
tls_key = "" # path to PEM private key file
116-
read_header_timeout = "5s" # Slowloris protection
117-
read_timeout = "10s"
116+
read_timeout = "10s" # full read deadline (covers headers; Slowloris protection)
118117
write_timeout = "10s"
119118
idle_timeout = "75s"
120119
shutdown_timeout = "15s" # graceful drain window on SIGTERM/SIGINT
@@ -165,7 +164,6 @@ Every config field can also be set via an environment variable, which takes prec
165164
| `STATIC_SERVER_REDIRECT_HOST` | `server.redirect_host` |
166165
| `STATIC_SERVER_TLS_CERT` | `server.tls_cert` |
167166
| `STATIC_SERVER_TLS_KEY` | `server.tls_key` |
168-
| `STATIC_SERVER_READ_HEADER_TIMEOUT` | `server.read_header_timeout` |
169167
| `STATIC_SERVER_READ_TIMEOUT` | `server.read_timeout` |
170168
| `STATIC_SERVER_WRITE_TIMEOUT` | `server.write_timeout` |
171169
| `STATIC_SERVER_IDLE_TIMEOUT` | `server.idle_timeout` |

cmd/static-web/config.toml.example

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@ tls_cert = ""
1313
# Path to TLS private key file (PEM). Leave empty to disable HTTPS.
1414
tls_key = ""
1515

16-
# Maximum time to read request headers from the client.
17-
# Protects against Slowloris DoS attacks. Default 5s.
18-
read_header_timeout = "5s"
19-
2016
# Maximum time to read an HTTP request from the client (headers + body).
17+
# With fasthttp, this single timeout covers the full read phase including
18+
# headers, providing Slowloris protection. Default 10s.
2119
read_timeout = "10s"
2220

2321
# Maximum time to write an HTTP response to the client.

config.toml.example

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ tls_cert = ""
1818
# Path to TLS private key file (PEM). Leave empty to disable HTTPS.
1919
tls_key = ""
2020

21-
# Maximum time to read request headers from the client.
22-
# Protects against Slowloris DoS attacks. Default 5s.
23-
read_header_timeout = "5s"
24-
2521
# Maximum time to read an HTTP request from the client (headers + body).
22+
# With fasthttp, this single timeout covers the full read phase including
23+
# headers, providing Slowloris protection. Default 10s.
2624
read_timeout = "10s"
2725

2826
# Maximum time to write an HTTP response to the client.

docs/index.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -751,15 +751,10 @@ <h2 class="section-title" id="configuration-heading">Configuration Reference</h2
751751
<td></td>
752752
<td>Path to TLS private key (PEM)</td>
753753
</tr>
754-
<tr>
755-
<td><code>read_header_timeout</code></td>
756-
<td><code>5s</code></td>
757-
<td>Slowloris protection</td>
758-
</tr>
759754
<tr>
760755
<td><code>read_timeout</code></td>
761756
<td><code>10s</code></td>
762-
<td>Full request read deadline</td>
757+
<td>Full request read deadline (Slowloris protection)</td>
763758
</tr>
764759
<tr>
765760
<td><code>write_timeout</code></td>

internal/config/config.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ type ServerConfig struct {
3535
TLSCert string `toml:"tls_cert"`
3636
// TLSKey is the path to the TLS private key file.
3737
TLSKey string `toml:"tls_key"`
38-
// ReadHeaderTimeout is the maximum duration for reading request headers.
39-
// Protects against slow-loris attacks. Default: 5s.
40-
ReadHeaderTimeout time.Duration `toml:"read_header_timeout"`
4138
// ReadTimeout is the maximum duration for reading the entire request (headers + body).
39+
// With fasthttp, this single timeout covers the full read phase (there is no
40+
// separate ReadHeaderTimeout). Default: 10s.
4241
ReadTimeout time.Duration `toml:"read_timeout"`
4342
// WriteTimeout is the maximum duration for writing a response.
4443
WriteTimeout time.Duration `toml:"write_timeout"`
@@ -146,7 +145,6 @@ func Load(path string) (*Config, error) {
146145
func applyDefaults(cfg *Config) {
147146
cfg.Server.Addr = ":8080"
148147
cfg.Server.TLSAddr = ":8443"
149-
cfg.Server.ReadHeaderTimeout = 5 * time.Second
150148
cfg.Server.ReadTimeout = 10 * time.Second
151149
cfg.Server.WriteTimeout = 10 * time.Second
152150
cfg.Server.IdleTimeout = 75 * time.Second
@@ -199,11 +197,6 @@ func applyEnvOverrides(cfg *Config) {
199197
cfg.Server.ReadTimeout = d
200198
}
201199
}
202-
if v := os.Getenv("STATIC_SERVER_READ_HEADER_TIMEOUT"); v != "" {
203-
if d, err := time.ParseDuration(v); err == nil {
204-
cfg.Server.ReadHeaderTimeout = d
205-
}
206-
}
207200
if v := os.Getenv("STATIC_SERVER_WRITE_TIMEOUT"); v != "" {
208201
if d, err := time.ParseDuration(v); err == nil {
209202
cfg.Server.WriteTimeout = d

internal/config/config_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ func TestLoadDefaults(t *testing.T) {
1818
if cfg.Server.Addr != ":8080" {
1919
t.Errorf("Server.Addr = %q, want %q", cfg.Server.Addr, ":8080")
2020
}
21-
if cfg.Server.ReadHeaderTimeout != 5*time.Second {
22-
t.Errorf("Server.ReadHeaderTimeout = %v, want 5s", cfg.Server.ReadHeaderTimeout)
23-
}
2421
if cfg.Server.RedirectHost != "" {
2522
t.Errorf("Server.RedirectHost = %q, want empty string", cfg.Server.RedirectHost)
2623
}

0 commit comments

Comments
 (0)