Skip to content

Commit

Permalink
fix: configurable body size limit (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
raffis authored May 28, 2024
1 parent a8c409d commit a527437
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ kustomize: ## Download kustomize locally if necessary.
ENVTEST = $(GOBIN)/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@release-0.17)

# go-install-tool will 'go install' any package $2 and install it to $1
define go-install-tool
Expand Down
2 changes: 1 addition & 1 deletion internal/proxy/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (
)

const (
DefaultBodyLimit int64 = 2000000
DefaultBodyLimit int64 = 10000000
)

type RequestClone struct {
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,14 @@ var (
rateLimiterOptions helper.RateLimiterOptions
watchOptions helper.WatchOptions
otelOptions otelsetup.Options
bodySizeLimit int64
)

func main() {
flag.StringVar(&httpAddr, "http-addr", ":8080", "The address of http server binding to.")
flag.DurationVar(&proxyReadTimeout, "proxy-read-timeout", 10*time.Second, "Read timeout for proxy requests.")
flag.DurationVar(&proxyWriteTimeout, "proxy-write-timeout", 10*time.Second, "Write timeout for proxy requests.")
flag.Int64Var(&bodySizeLimit, "body-size-limit", proxy.DefaultBodyLimit, "Max size of body stream")
flag.StringVar(&metricsAddr, "metrics-addr", ":9556",
"The address the metric endpoint binds to.")
flag.StringVar(&healthAddr, "health-addr", ":9557",
Expand Down Expand Up @@ -164,11 +166,11 @@ func main() {
return http.ErrUseLastResponse
},
},
BodySizeLimit: proxy.DefaultBodyLimit,
BodySizeLimit: bodySizeLimit,
}

proxy := proxy.New(proxyOpts)
wrappedHandler := otelhttp.NewHandler(proxy, "req-duplicator")
wrappedHandler := otelhttp.NewHandler(proxy, "webhook-controller")

httpSrv := &http.Server{
Addr: httpAddr,
Expand Down

0 comments on commit a527437

Please sign in to comment.