mirror of
https://github.com/tarampampam/error-pages.git
synced 2024-08-30 18:22:40 +00:00
fix: "Too big request header" (#244)
* Added environment variable and CLI parameter for adjusting the read buffer size * Changed readBufferSize to int and some bugfixing * Small fixes * ci: 👷 CI system updated * ci: 👷 CI system updated --------- Co-authored-by: Paramtamtam <7326800+tarampampam@users.noreply.github.com>
This commit is contained in:
parent
2c8ba9c0f3
commit
8e7570eee3
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@ -30,7 +30,7 @@ jobs: # Docs: <https://git.io/JvxXE>
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- uses: gacts/setup-go-with-cache@v1
|
||||
with: {go-version: 1.19}
|
||||
with: {go-version-file: go.mod}
|
||||
|
||||
- uses: golangci/golangci-lint-action@v3
|
||||
with: {skip-pkg-cache: true, skip-build-cache: true}
|
||||
|
@ -9,8 +9,11 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher
|
||||
### Added
|
||||
|
||||
- Error pages now translated into 🇵🇱 [#226]
|
||||
- Possibility to set custom read buffer size (using `--read-buffer-size` flag or environment variable `READ_BUFFER_SIZE`) [#238], [#244]
|
||||
|
||||
[#226]:https://github.com/tarampampam/error-pages/pull/226
|
||||
[#238]:https://github.com/tarampampam/error-pages/issues/238
|
||||
[#244]:https://github.com/tarampampam/error-pages/pull/244
|
||||
|
||||
## v2.25.0
|
||||
|
||||
|
@ -79,7 +79,8 @@ ENV LISTEN_PORT="8080" \
|
||||
DEFAULT_ERROR_PAGE="404" \
|
||||
DEFAULT_HTTP_CODE="404" \
|
||||
SHOW_DETAILS="false" \
|
||||
DISABLE_L10N="false"
|
||||
DISABLE_L10N="false" \
|
||||
READ_BUFFER_SIZE="2048"
|
||||
|
||||
# Docs: <https://docs.docker.com/engine/reference/builder/#healthcheck>
|
||||
HEALTHCHECK --interval=7s --timeout=2s CMD ["/bin/error-pages", "--log-json", "healthcheck"]
|
||||
|
@ -33,6 +33,7 @@ const (
|
||||
proxyHTTPHeadersFlagName = "proxy-headers"
|
||||
disableL10nFlagName = "disable-l10n"
|
||||
catchAllFlagName = "catch-all"
|
||||
readBufferSizeFlagName = "read-buffer-size"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -107,7 +108,7 @@ func NewCommand(log *zap.Logger) *cli.Command { //nolint:funlen
|
||||
return fmt.Errorf("wrong default HTTP response code [%d]", o.Default.HTTPCode)
|
||||
}
|
||||
|
||||
return cmd.Run(c.Context, log, cfg, ip, port, o)
|
||||
return cmd.Run(c.Context, log, cfg, ip, port, c.Uint(readBufferSizeFlagName), o)
|
||||
},
|
||||
Flags: []cli.Flag{
|
||||
shared.ConfigFileFlag,
|
||||
@ -158,6 +159,11 @@ func NewCommand(log *zap.Logger) *cli.Command { //nolint:funlen
|
||||
Usage: "catch all pages",
|
||||
EnvVars: []string{env.CatchAll.String()},
|
||||
},
|
||||
&cli.UintFlag{
|
||||
Name: readBufferSizeFlagName,
|
||||
Usage: "read buffer size (0 = use default value)",
|
||||
EnvVars: []string{env.ReadBufferSize.String()},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -166,7 +172,13 @@ func NewCommand(log *zap.Logger) *cli.Command { //nolint:funlen
|
||||
|
||||
// Run current command.
|
||||
func (cmd *command) Run( //nolint:funlen
|
||||
parentCtx context.Context, log *zap.Logger, cfg *config.Config, ip string, port uint16, opt options.ErrorPage,
|
||||
parentCtx context.Context,
|
||||
log *zap.Logger,
|
||||
cfg *config.Config,
|
||||
ip string,
|
||||
port uint16,
|
||||
readBufferSize uint,
|
||||
opt options.ErrorPage,
|
||||
) error {
|
||||
var (
|
||||
ctx, cancel = context.WithCancel(parentCtx) // serve context creation
|
||||
@ -226,7 +238,7 @@ func (cmd *command) Run( //nolint:funlen
|
||||
}
|
||||
|
||||
// create HTTP server
|
||||
server := appHttp.NewServer(log)
|
||||
server := appHttp.NewServer(log, readBufferSize)
|
||||
|
||||
// register server routes, middlewares, etc.
|
||||
if err := server.Register(cfg, picker, opt); err != nil {
|
||||
@ -239,7 +251,7 @@ func (cmd *command) Run( //nolint:funlen
|
||||
go func(errCh chan<- error) {
|
||||
defer close(errCh)
|
||||
|
||||
log.Info("Server starting",
|
||||
var fields = []zap.Field{
|
||||
zap.String("addr", ip),
|
||||
zap.Uint16("port", port),
|
||||
zap.String("default error page", opt.Default.PageCode),
|
||||
@ -248,7 +260,13 @@ func (cmd *command) Run( //nolint:funlen
|
||||
zap.Bool("show request details", opt.ShowDetails),
|
||||
zap.Bool("localization disabled", opt.L10n.Disabled),
|
||||
zap.Bool("catch all enabled", opt.CatchAll),
|
||||
)
|
||||
}
|
||||
|
||||
if readBufferSize > 0 {
|
||||
fields = append(fields, zap.Uint("read buffer size", readBufferSize))
|
||||
}
|
||||
|
||||
log.Info("Server starting", fields...)
|
||||
|
||||
if err := server.Start(ip, port); err != nil {
|
||||
errCh <- err
|
||||
|
1
internal/env/env.go
vendored
1
internal/env/env.go
vendored
@ -19,6 +19,7 @@ const (
|
||||
ProxyHTTPHeaders envVariable = "PROXY_HTTP_HEADERS" // proxy HTTP request headers list (request -> response)
|
||||
DisableL10n envVariable = "DISABLE_L10N" // disable pages localization
|
||||
CatchAll envVariable = "CATCH_ALL" // catch all pages
|
||||
ReadBufferSize envVariable = "READ_BUFFER_SIZE" // https://github.com/tarampampam/error-pages/issues/238
|
||||
)
|
||||
|
||||
// String returns environment variable name in the string representation.
|
||||
|
2
internal/env/env_test.go
vendored
2
internal/env/env_test.go
vendored
@ -18,6 +18,7 @@ func TestConstants(t *testing.T) {
|
||||
assert.Equal(t, "PROXY_HTTP_HEADERS", string(ProxyHTTPHeaders))
|
||||
assert.Equal(t, "DISABLE_L10N", string(DisableL10n))
|
||||
assert.Equal(t, "CATCH_ALL", string(CatchAll))
|
||||
assert.Equal(t, "READ_BUFFER_SIZE", string(ReadBufferSize))
|
||||
}
|
||||
|
||||
func TestEnvVariable_Lookup(t *testing.T) {
|
||||
@ -34,6 +35,7 @@ func TestEnvVariable_Lookup(t *testing.T) {
|
||||
{giveEnv: ProxyHTTPHeaders},
|
||||
{giveEnv: DisableL10n},
|
||||
{giveEnv: CatchAll},
|
||||
{giveEnv: ReadBufferSize},
|
||||
}
|
||||
|
||||
for _, tt := range cases {
|
||||
|
@ -39,13 +39,14 @@ const (
|
||||
defaultIdleTimeout = time.Second * 6
|
||||
)
|
||||
|
||||
func NewServer(log *zap.Logger) Server {
|
||||
func NewServer(log *zap.Logger, readBufferSize uint) Server {
|
||||
rdr := tpl.NewTemplateRenderer()
|
||||
|
||||
return Server{
|
||||
// fasthttp docs: <https://github.com/valyala/fasthttp>
|
||||
fast: &fasthttp.Server{
|
||||
WriteTimeout: defaultWriteTimeout,
|
||||
ReadBufferSize: int(readBufferSize),
|
||||
ReadTimeout: defaultReadTimeout,
|
||||
IdleTimeout: defaultIdleTimeout,
|
||||
NoDefaultServerHeader: true,
|
||||
|
Loading…
Reference in New Issue
Block a user