mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-18 13:12:17 +01:00
feat(webhook): switch to --webhook-enable-sync-mode flag instead of header
This commit is contained in:
2
Makefile
2
Makefile
@@ -66,6 +66,7 @@ PROMETHEUS_NAMESPACE=gotenberg
|
|||||||
PROMETHEUS_COLLECT_INTERVAL=1s
|
PROMETHEUS_COLLECT_INTERVAL=1s
|
||||||
PROMETHEUS_DISABLE_ROUTE_LOGGING=false
|
PROMETHEUS_DISABLE_ROUTE_LOGGING=false
|
||||||
PROMETHEUS_DISABLE_COLLECT=false
|
PROMETHEUS_DISABLE_COLLECT=false
|
||||||
|
WEBHOOK_ENABLE_SYNC_MODE=false
|
||||||
WEBHOOK_ALLOW_LIST=
|
WEBHOOK_ALLOW_LIST=
|
||||||
WEBHOOK_DENY_LIST=
|
WEBHOOK_DENY_LIST=
|
||||||
WEBHOOK_ERROR_ALLOW_LIST=
|
WEBHOOK_ERROR_ALLOW_LIST=
|
||||||
@@ -138,6 +139,7 @@ run: ## Start a Gotenberg container
|
|||||||
--prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \
|
--prometheus-collect-interval=$(PROMETHEUS_COLLECT_INTERVAL) \
|
||||||
--prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \
|
--prometheus-disable-route-logging=$(PROMETHEUS_DISABLE_ROUTE_LOGGING) \
|
||||||
--prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \
|
--prometheus-disable-collect=$(PROMETHEUS_DISABLE_COLLECT) \
|
||||||
|
--webhook-enable-sync-mode="$(WEBHOOK_ENABLE_SYNC_MODE)" \
|
||||||
--webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \
|
--webhook-allow-list="$(WEBHOOK_ALLOW_LIST)" \
|
||||||
--webhook-deny-list="$(WEBHOOK_DENY_LIST)" \
|
--webhook-deny-list="$(WEBHOOK_DENY_LIST)" \
|
||||||
--webhook-error-allow-list=$(WEBHOOK_ERROR_ALLOW_LIST) \
|
--webhook-error-allow-list=$(WEBHOOK_ERROR_ALLOW_LIST) \
|
||||||
|
|||||||
@@ -235,18 +235,7 @@ func webhookMiddleware(w *Webhook) api.Middleware {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
webhookSyncHeader := c.Request().Header.Get("Gotenberg-Webhook-Sync")
|
if w.enableSyncMode {
|
||||||
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.
|
|
||||||
err := next(c)
|
err := next(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, api.ErrNoOutputFile) {
|
if errors.Is(err, api.ErrNoOutputFile) {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ func init() {
|
|||||||
// Webhook is a module that provides a middleware for uploading output files
|
// Webhook is a module that provides a middleware for uploading output files
|
||||||
// to any destinations in an asynchronous fashion.
|
// to any destinations in an asynchronous fashion.
|
||||||
type Webhook struct {
|
type Webhook struct {
|
||||||
|
enableSyncMode bool
|
||||||
allowList *regexp2.Regexp
|
allowList *regexp2.Regexp
|
||||||
denyList *regexp2.Regexp
|
denyList *regexp2.Regexp
|
||||||
errorAllowList *regexp2.Regexp
|
errorAllowList *regexp2.Regexp
|
||||||
@@ -36,6 +37,7 @@ func (w *Webhook) Descriptor() gotenberg.ModuleDescriptor {
|
|||||||
ID: "webhook",
|
ID: "webhook",
|
||||||
FlagSet: func() *flag.FlagSet {
|
FlagSet: func() *flag.FlagSet {
|
||||||
fs := flag.NewFlagSet("webhook", flag.ExitOnError)
|
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-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-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")
|
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.
|
// Provision sets the module properties.
|
||||||
func (w *Webhook) Provision(ctx *gotenberg.Context) error {
|
func (w *Webhook) Provision(ctx *gotenberg.Context) error {
|
||||||
flags := ctx.ParsedFlags()
|
flags := ctx.ParsedFlags()
|
||||||
|
w.enableSyncMode = flags.MustBool("webhook-enable-sync-mode")
|
||||||
w.allowList = flags.MustRegexp("webhook-allow-list")
|
w.allowList = flags.MustRegexp("webhook-allow-list")
|
||||||
w.denyList = flags.MustRegexp("webhook-deny-list")
|
w.denyList = flags.MustRegexp("webhook-deny-list")
|
||||||
w.errorAllowList = flags.MustRegexp("webhook-error-allow-list")
|
w.errorAllowList = flags.MustRegexp("webhook-error-allow-list")
|
||||||
|
|||||||
@@ -32,14 +32,14 @@ Feature: Webhook
|
|||||||
Then the webhook request header "Content-Disposition" should be "inline"
|
Then the webhook request header "Content-Disposition" should be "inline"
|
||||||
Then there should be 1 PDF(s) in the webhook request
|
Then there should be 1 PDF(s) in the webhook request
|
||||||
|
|
||||||
Scenario: Synchronous webhook processing with Gotenberg-Webhook-Sync header
|
Scenario: Synchronous
|
||||||
Given I have a default Gotenberg container
|
Given I have a Gotenberg container with the following environment variable(s):
|
||||||
|
| WEBHOOK_ENABLE_SYNC_MODE | true |
|
||||||
Given I have a webhook server
|
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):
|
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 |
|
| files | testdata/page_1.pdf | file |
|
||||||
| Gotenberg-Webhook-Url | http://host.docker.internal:%d/webhook | header |
|
| Gotenberg-Webhook-Url | http://host.docker.internal:%d/webhook | header |
|
||||||
| Gotenberg-Webhook-Error-Url | http://host.docker.internal:%d/webhook/error | 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 response status code should be 204
|
||||||
Then the webhook request header "Content-Type" should be "application/pdf"
|
Then the webhook request header "Content-Type" should be "application/pdf"
|
||||||
Then there should be 1 PDF(s) in the webhook request
|
Then there should be 1 PDF(s) in the webhook request
|
||||||
|
|||||||
Reference in New Issue
Block a user