Skip to content

Commit

Permalink
feat: add failOnResourceLoadingFailed and failOnResourceHttpStatusCod…
Browse files Browse the repository at this point in the history
…es form fields (#22)

Co-authored-by: Alexander Pikeev <[email protected]>
  • Loading branch information
runatal and Alexander Pikeev authored Nov 17, 2024
1 parent 2a48382 commit afadebd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
12 changes: 12 additions & 0 deletions chromium.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,24 @@ func (req *chromiumRequest) FailOnHTTPStatusCodes(statusCodes []byte) {
req.fields[fieldChromiumFailOnHTTPStatusCodes] = string(statusCodes)
}

// FailOnResourceHTTPStatusCodes forces Gotenberg to return a 409 Conflict response
// if the HTTP status code from at least one resource is not acceptable.
func (req *chromiumRequest) FailOnResourceHTTPStatusCodes(statusCodes []byte) {
req.fields[fieldChromiumFailOnResourceHTTPStatusCodes] = string(statusCodes)
}

// FailOnConsoleExceptions forces Gotenberg to return a 409 Conflict response
// if there are exceptions in the Chromium console.
func (req *chromiumRequest) FailOnConsoleExceptions() {
req.fields[fieldChromiumFailOnConsoleExceptions] = strconv.FormatBool(true)
}

// FailOnResourceLoadingFailed forces Gotenberg to return a 409 Conflict if Chromium
// fails to load at least one resource.
func (req *chromiumRequest) FailOnResourceLoadingFailed() {
req.fields[fieldChromiumFailOnResourceLoadingFailed] = strconv.FormatBool(true)
}

// SkipNetworkIdleEvent specifies whether Chromium have to wait or not for its network to be idle.
// Enabled by default in Gotenberg >= 8.11.0.
func (req *chromiumRequest) SkipNetworkIdleEvent() {
Expand Down
20 changes: 11 additions & 9 deletions fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ const (

// Chromium request configuration.
const (
fieldChromiumWaitDelay formField = "waitDelay"
fieldChromiumWaitForExpression formField = "waitForExpression"
fieldChromiumEmulatedMediaType formField = "emulatedMediaType"
fieldChromiumCookies formField = "cookies"
fieldChromiumUserAgent formField = "userAgent"
fieldChromiumExtraHTTPHeaders formField = "extraHttpHeaders"
fieldChromiumFailOnHTTPStatusCodes formField = "failOnHttpStatusCodes"
fieldChromiumFailOnConsoleExceptions formField = "failOnConsoleExceptions"
fieldChromiumSkipNetworkIdleEvent formField = "skipNetworkIdleEvent"
fieldChromiumWaitDelay formField = "waitDelay"
fieldChromiumWaitForExpression formField = "waitForExpression"
fieldChromiumEmulatedMediaType formField = "emulatedMediaType"
fieldChromiumCookies formField = "cookies"
fieldChromiumUserAgent formField = "userAgent"
fieldChromiumExtraHTTPHeaders formField = "extraHttpHeaders"
fieldChromiumFailOnHTTPStatusCodes formField = "failOnHttpStatusCodes"
fieldChromiumFailOnResourceHTTPStatusCodes formField = "failOnResourceHttpStatusCodes"
fieldChromiumFailOnConsoleExceptions formField = "failOnConsoleExceptions"
fieldChromiumFailOnResourceLoadingFailed formField = "failOnResourceLoadingFailed"
fieldChromiumSkipNetworkIdleEvent formField = "skipNetworkIdleEvent"
)

// PDF page property.
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down

0 comments on commit afadebd

Please sign in to comment.