diff --git a/Makefile b/Makefile index c8af5593..41b39142 100644 --- a/Makefile +++ b/Makefile @@ -66,6 +66,7 @@ PROMETHEUS_NAMESPACE=gotenberg PROMETHEUS_COLLECT_INTERVAL=1s PROMETHEUS_DISABLE_ROUTE_LOGGING=false PROMETHEUS_DISABLE_COLLECT=false +WEBHOOK_ENABLE_SYNC_MODE=false WEBHOOK_ALLOW_LIST= WEBHOOK_DENY_LIST= WEBHOOK_ERROR_ALLOW_LIST= @@ -138,6 +139,7 @@ run: ## Start a Gotenberg container --prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \ --prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \ --prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \ + --webhook-enable-sync-mode="$(WEBHOOK_ENABLE_SYNC_MODE)" \ --webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \ --webhook-deny-list="$(WEBHOOK_DENY_LIST)" \ --webhook-error-allow-list=$(WEBHOOK_ERROR_ALLOW_LIST) \ diff --git a/pkg/modules/webhook/middleware.go b/pkg/modules/webhook/middleware.go index 6dbef99f..f5d870d3 100644 --- a/pkg/modules/webhook/middleware.go +++ b/pkg/modules/webhook/middleware.go @@ -235,18 +235,7 @@ func webhookMiddleware(w *Webhook) api.Middleware { } } - webhookSyncHeader := c.Request().Header.Get("Gotenberg-Webhook-Sync") - webhookSync := false - if webhookSyncHeader != "" { - var err error - webhookSync, err = strconv.ParseBool(webhookSyncHeader) - if err != nil { - return fmt.Errorf("parse webhook sync header: %w", err) - } - } - - if webhookSync { - // Synchronous mode has been requested. + if w.enableSyncMode { err := next(c) if err != nil { if errors.Is(err, api.ErrNoOutputFile) { diff --git a/pkg/modules/webhook/webhook.go b/pkg/modules/webhook/webhook.go index 0ff6f3f7..dd660ce8 100644 --- a/pkg/modules/webhook/webhook.go +++ b/pkg/modules/webhook/webhook.go @@ -18,6 +18,7 @@ func init() { // Webhook is a module that provides a middleware for uploading output files // to any destinations in an asynchronous fashion. type Webhook struct { + enableSyncMode bool allowList *regexp2.Regexp denyList *regexp2.Regexp errorAllowList *regexp2.Regexp @@ -36,6 +37,7 @@ func (w *Webhook) Descriptor() gotenberg.ModuleDescriptor { ID: "webhook", FlagSet: func() *flag.FlagSet { fs := flag.NewFlagSet("webhook", flag.ExitOnError) + fs.Bool("webhook-enable-sync-mode", false, "Enable synchronous mode for the webhook feature") fs.String("webhook-allow-list", "", "Set the allowed URLs for the webhook feature using a regular expression") fs.String("webhook-deny-list", "", "Set the denied URLs for the webhook feature using a regular expression") fs.String("webhook-error-allow-list", "", "Set the allowed URLs in case of an error for the webhook feature using a regular expression") @@ -55,6 +57,7 @@ func (w *Webhook) Descriptor() gotenberg.ModuleDescriptor { // Provision sets the module properties. func (w *Webhook) Provision(ctx *gotenberg.Context) error { flags := ctx.ParsedFlags() + w.enableSyncMode = flags.MustBool("webhook-enable-sync-mode") w.allowList = flags.MustRegexp("webhook-allow-list") w.denyList = flags.MustRegexp("webhook-deny-list") w.errorAllowList = flags.MustRegexp("webhook-error-allow-list") diff --git a/test/integration/features/webhook.feature b/test/integration/features/webhook.feature index ddd05624..fa9691c7 100644 --- a/test/integration/features/webhook.feature +++ b/test/integration/features/webhook.feature @@ -32,14 +32,14 @@ Feature: Webhook Then the webhook request header "Content-Disposition" should be "inline" Then there should be 1 PDF(s) in the webhook request - Scenario: Synchronous webhook processing with Gotenberg-Webhook-Sync header - Given I have a default Gotenberg container + Scenario: Synchronous + Given I have a Gotenberg container with the following environment variable(s): + | WEBHOOK_ENABLE_SYNC_MODE | true | Given I have a webhook server When I make a "POST" request to Gotenberg at the "/forms/pdfengines/flatten" endpoint with the following form data and header(s): | files | testdata/page_1.pdf | file | | Gotenberg-Webhook-Url | http://host.docker.internal:%d/webhook | header | | Gotenberg-Webhook-Error-Url | http://host.docker.internal:%d/webhook/error | header | - | Gotenberg-Webhook-Sync | true | header | Then the response status code should be 204 Then the webhook request header "Content-Type" should be "application/pdf" Then there should be 1 PDF(s) in the webhook request