diff --git a/Makefile b/Makefile index d21a286a..70a8ce06 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ CHROMIUM_USER_AGENT= CHROMIUM_INCOGNITO=false CHROMIUM_IGNORE_CERTIFICATE_ERRORS=false CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES=false +CHROMIUM_PROXY_SERVER= CHROMIUM_ALLOW_LIST= CHROMIUM_DENY_LIST="^file:///[^tmp].*" CHROMIUM_DISABLE_ROUTES=false @@ -79,6 +80,7 @@ run: ## Start a Gotenberg container --chromium-incognito=$(CHROMIUM_INCOGNITO) \ --chromium-ignore-certificate-errors=$(CHROMIUM_IGNORE_CERTIFICATE_ERRORS) \ --chromium-allow-file-access-from-files=$(CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES) \ + --chromium-proxy-server=$(CHROMIUM_PROXY_SERVER) \ --chromium-allow-list=$(CHROMIUM_ALLOW_LIST) \ --chromium-deny-list=$(CHROMIUM_DENY_LIST) \ --chromium-disable-routes=$(CHROMIUM_DISABLE_ROUTES) \ diff --git a/pkg/modules/chromium/chromium.go b/pkg/modules/chromium/chromium.go index 0ed0d818..5622c8be 100644 --- a/pkg/modules/chromium/chromium.go +++ b/pkg/modules/chromium/chromium.go @@ -52,6 +52,7 @@ type Chromium struct { incognito bool ignoreCertificateErrors bool allowFileAccessFromFiles bool + proxyServer string allowList *regexp.Regexp denyList *regexp.Regexp disableRoutes bool @@ -186,6 +187,7 @@ func (mod Chromium) Descriptor() gotenberg.ModuleDescriptor { fs.Bool("chromium-incognito", false, "Start Chromium with incognito mode") fs.Bool("chromium-ignore-certificate-errors", false, "Ignore the certificate errors") fs.Bool("chromium-allow-file-access-from-files", false, "Allow file:// URIs to read other file:// URIs") + fs.String("chromium-proxy-server", "", "Set the outbound proxy server; this switch only affects HTTP and HTTPS requests") fs.String("chromium-allow-list", "", "Set the allowed URLs for Chromium using a regular expression") fs.String("chromium-deny-list", "^file:///[^tmp].*", "Set the denied URLs for Chromium using a regular expression") fs.Bool("chromium-disable-routes", false, "Disable the routes") @@ -199,8 +201,10 @@ func (mod Chromium) Descriptor() gotenberg.ModuleDescriptor { // Provision sets the module properties. func (mod *Chromium) Provision(ctx *gotenberg.Context) error { flags := ctx.ParsedFlags() + mod.userAgent = flags.MustString("chromium-user-agent") mod.ignoreCertificateErrors = flags.MustBool("chromium-ignore-certificate-errors") mod.allowFileAccessFromFiles = flags.MustBool("chromium-allow-file-access-from-files") + mod.proxyServer = flags.MustString("chromium-proxy-server") mod.allowList = flags.MustRegexp("chromium-allow-list") mod.denyList = flags.MustRegexp("chromium-deny-list") mod.disableRoutes = flags.MustBool("chromium-disable-routes") @@ -312,6 +316,11 @@ func (mod Chromium) PDF(ctx context.Context, logger *zap.Logger, URL, outputPath args = append(args, chromedp.Flag("allow-file-access-from-files", true)) } + if mod.proxyServer != "" { + // See https://github.com/gotenberg/gotenberg/issues/376. + args = append(args, chromedp.ProxyServer(mod.proxyServer)) + } + allocatorCtx, cancel := chromedp.NewExecAllocator(ctx, args...) defer cancel() diff --git a/pkg/modules/chromium/chromium_test.go b/pkg/modules/chromium/chromium_test.go index 49521ba9..12bc4fe4 100644 --- a/pkg/modules/chromium/chromium_test.go +++ b/pkg/modules/chromium/chromium_test.go @@ -234,6 +234,7 @@ func TestChromium_PDF(t *testing.T) { incognito bool ignoreCertificateErrors bool allowFileAccessFromFiles bool + proxyServer string allowList *regexp.Regexp denyList *regexp.Regexp expectErr bool @@ -297,6 +298,7 @@ func TestChromium_PDF(t *testing.T) { incognito: true, ignoreCertificateErrors: true, allowFileAccessFromFiles: true, + proxyServer: "foo", }, { URL: "file:///tests/test/testdata/chromium/html/sample1/index.html", @@ -348,6 +350,7 @@ func TestChromium_PDF(t *testing.T) { mod.incognito = tc.incognito mod.ignoreCertificateErrors = tc.ignoreCertificateErrors mod.allowFileAccessFromFiles = tc.allowFileAccessFromFiles + mod.proxyServer = tc.proxyServer if tc.allowList == nil { tc.allowList = regexp.MustCompile("")