mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-16 12:22:17 +01:00
Merge branch 'main' of github.com:gotenberg/gotenberg
This commit is contained in:
@@ -3,6 +3,7 @@ package webhook
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -78,6 +79,10 @@ func (c client) send(body io.Reader, headers map[string]string, erroed bool) err
|
|||||||
return fmt.Errorf("send '%s' request to '%s': %w", method, URL, err)
|
return fmt.Errorf("send '%s' request to '%s': %w", method, URL, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if resp.StatusCode >= http.StatusBadRequest {
|
||||||
|
return fmt.Errorf("send '%s' request to '%s': got status: '%s'", method, URL, resp.Status)
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err := resp.Body.Close()
|
err := resp.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -339,6 +339,7 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
expectWebhookFilename string
|
expectWebhookFilename string
|
||||||
expectWebhookErrorStatus int
|
expectWebhookErrorStatus int
|
||||||
expectWebhookErrorMessage string
|
expectWebhookErrorMessage string
|
||||||
|
returnedError *echo.HTTPError
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
request: buildMultipartFormDataRequest(),
|
request: buildMultipartFormDataRequest(),
|
||||||
@@ -363,8 +364,8 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
}(),
|
}(),
|
||||||
expectWebhookContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
expectWebhookContentType: echo.MIMEApplicationJSONCharsetUTF8,
|
||||||
expectWebhookMethod: http.MethodPost,
|
expectWebhookMethod: http.MethodPost,
|
||||||
expectWebhookErrorStatus: http.StatusInternalServerError,
|
expectWebhookErrorStatus: http.StatusBadRequest,
|
||||||
expectWebhookErrorMessage: http.StatusText(http.StatusInternalServerError),
|
expectWebhookErrorMessage: http.StatusText(http.StatusBadRequest),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
request: func() *http.Request {
|
request: func() *http.Request {
|
||||||
@@ -387,6 +388,27 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
expectWebhookFilename: "foo",
|
expectWebhookFilename: "foo",
|
||||||
expectWebhookExtraHTTPHeaders: map[string]string{"foo": "bar"},
|
expectWebhookExtraHTTPHeaders: map[string]string{"foo": "bar"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
request: func() *http.Request {
|
||||||
|
req := buildMultipartFormDataRequest()
|
||||||
|
req.Header.Set("Gotenberg-Output-Filename", "foo")
|
||||||
|
|
||||||
|
return req
|
||||||
|
}(),
|
||||||
|
mod: buildWebhookModule(),
|
||||||
|
next: func() echo.HandlerFunc {
|
||||||
|
return func(c echo.Context) error {
|
||||||
|
ctx := c.Get("context").(*api.Context)
|
||||||
|
|
||||||
|
return ctx.AddOutputPaths("/tests/test/testdata/api/sample3.pdf")
|
||||||
|
}
|
||||||
|
}(),
|
||||||
|
returnedError: echo.ErrInternalServerError,
|
||||||
|
// Even though an error is returned the expected response is still a pdf, since the webhook error is only logged
|
||||||
|
expectWebhookContentType: "application/pdf",
|
||||||
|
expectWebhookMethod: http.MethodPost,
|
||||||
|
expectWebhookFilename: "foo",
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
func() {
|
func() {
|
||||||
srv := echo.New()
|
srv := echo.New()
|
||||||
@@ -500,6 +522,11 @@ func TestWebhookMiddlewareAsynchronousProcess(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
errChan <- nil
|
errChan <- nil
|
||||||
|
|
||||||
|
if tc.returnedError != nil {
|
||||||
|
return tc.returnedError
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}(),
|
}(),
|
||||||
|
|||||||
Reference in New Issue
Block a user