mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-17 12:42:16 +01:00
feat: add module property --chromium-proxy-server
This commit is contained in:
2
Makefile
2
Makefile
@@ -39,6 +39,7 @@ CHROMIUM_USER_AGENT=
|
|||||||
CHROMIUM_INCOGNITO=false
|
CHROMIUM_INCOGNITO=false
|
||||||
CHROMIUM_IGNORE_CERTIFICATE_ERRORS=false
|
CHROMIUM_IGNORE_CERTIFICATE_ERRORS=false
|
||||||
CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES=false
|
CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES=false
|
||||||
|
CHROMIUM_PROXY_SERVER=
|
||||||
CHROMIUM_ALLOW_LIST=
|
CHROMIUM_ALLOW_LIST=
|
||||||
CHROMIUM_DENY_LIST="^file:///[^tmp].*"
|
CHROMIUM_DENY_LIST="^file:///[^tmp].*"
|
||||||
CHROMIUM_DISABLE_ROUTES=false
|
CHROMIUM_DISABLE_ROUTES=false
|
||||||
@@ -79,6 +80,7 @@ run: ## Start a Gotenberg container
|
|||||||
--chromium-incognito=$(CHROMIUM_INCOGNITO) \
|
--chromium-incognito=$(CHROMIUM_INCOGNITO) \
|
||||||
--chromium-ignore-certificate-errors=$(CHROMIUM_IGNORE_CERTIFICATE_ERRORS) \
|
--chromium-ignore-certificate-errors=$(CHROMIUM_IGNORE_CERTIFICATE_ERRORS) \
|
||||||
--chromium-allow-file-access-from-files=$(CHROMIUM_ALLOW_FILE_ACCESS_FROM_FILES) \
|
--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-allow-list=$(CHROMIUM_ALLOW_LIST) \
|
||||||
--chromium-deny-list=$(CHROMIUM_DENY_LIST) \
|
--chromium-deny-list=$(CHROMIUM_DENY_LIST) \
|
||||||
--chromium-disable-routes=$(CHROMIUM_DISABLE_ROUTES) \
|
--chromium-disable-routes=$(CHROMIUM_DISABLE_ROUTES) \
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ type Chromium struct {
|
|||||||
incognito bool
|
incognito bool
|
||||||
ignoreCertificateErrors bool
|
ignoreCertificateErrors bool
|
||||||
allowFileAccessFromFiles bool
|
allowFileAccessFromFiles bool
|
||||||
|
proxyServer string
|
||||||
allowList *regexp.Regexp
|
allowList *regexp.Regexp
|
||||||
denyList *regexp.Regexp
|
denyList *regexp.Regexp
|
||||||
disableRoutes bool
|
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-incognito", false, "Start Chromium with incognito mode")
|
||||||
fs.Bool("chromium-ignore-certificate-errors", false, "Ignore the certificate errors")
|
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.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-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.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")
|
fs.Bool("chromium-disable-routes", false, "Disable the routes")
|
||||||
@@ -199,8 +201,10 @@ func (mod Chromium) Descriptor() gotenberg.ModuleDescriptor {
|
|||||||
// Provision sets the module properties.
|
// Provision sets the module properties.
|
||||||
func (mod *Chromium) Provision(ctx *gotenberg.Context) error {
|
func (mod *Chromium) Provision(ctx *gotenberg.Context) error {
|
||||||
flags := ctx.ParsedFlags()
|
flags := ctx.ParsedFlags()
|
||||||
|
mod.userAgent = flags.MustString("chromium-user-agent")
|
||||||
mod.ignoreCertificateErrors = flags.MustBool("chromium-ignore-certificate-errors")
|
mod.ignoreCertificateErrors = flags.MustBool("chromium-ignore-certificate-errors")
|
||||||
mod.allowFileAccessFromFiles = flags.MustBool("chromium-allow-file-access-from-files")
|
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.allowList = flags.MustRegexp("chromium-allow-list")
|
||||||
mod.denyList = flags.MustRegexp("chromium-deny-list")
|
mod.denyList = flags.MustRegexp("chromium-deny-list")
|
||||||
mod.disableRoutes = flags.MustBool("chromium-disable-routes")
|
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))
|
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...)
|
allocatorCtx, cancel := chromedp.NewExecAllocator(ctx, args...)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
|
|||||||
@@ -234,6 +234,7 @@ func TestChromium_PDF(t *testing.T) {
|
|||||||
incognito bool
|
incognito bool
|
||||||
ignoreCertificateErrors bool
|
ignoreCertificateErrors bool
|
||||||
allowFileAccessFromFiles bool
|
allowFileAccessFromFiles bool
|
||||||
|
proxyServer string
|
||||||
allowList *regexp.Regexp
|
allowList *regexp.Regexp
|
||||||
denyList *regexp.Regexp
|
denyList *regexp.Regexp
|
||||||
expectErr bool
|
expectErr bool
|
||||||
@@ -297,6 +298,7 @@ func TestChromium_PDF(t *testing.T) {
|
|||||||
incognito: true,
|
incognito: true,
|
||||||
ignoreCertificateErrors: true,
|
ignoreCertificateErrors: true,
|
||||||
allowFileAccessFromFiles: true,
|
allowFileAccessFromFiles: true,
|
||||||
|
proxyServer: "foo",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
URL: "file:///tests/test/testdata/chromium/html/sample1/index.html",
|
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.incognito = tc.incognito
|
||||||
mod.ignoreCertificateErrors = tc.ignoreCertificateErrors
|
mod.ignoreCertificateErrors = tc.ignoreCertificateErrors
|
||||||
mod.allowFileAccessFromFiles = tc.allowFileAccessFromFiles
|
mod.allowFileAccessFromFiles = tc.allowFileAccessFromFiles
|
||||||
|
mod.proxyServer = tc.proxyServer
|
||||||
|
|
||||||
if tc.allowList == nil {
|
if tc.allowList == nil {
|
||||||
tc.allowList = regexp.MustCompile("")
|
tc.allowList = regexp.MustCompile("")
|
||||||
|
|||||||
Reference in New Issue
Block a user