mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-14 19:32:15 +01:00
feat(webhook): switch to --webhook-enable-sync-mode flag instead of header
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user