Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gotenberg 7, WebHooks Headers and 204 response #47

Closed
thaoula opened this issue Jun 25, 2022 · 3 comments
Closed

Gotenberg 7, WebHooks Headers and 204 response #47

thaoula opened this issue Jun 25, 2022 · 3 comments

Comments

@thaoula
Copy link

thaoula commented Jun 25, 2022

Hi,

Firstly, thanks so much for your client library.

We are attempting to use your library to make calls to Gotenberg 7.53. I have read the comments about making the necessary adjustments for version 7 and so far everything seems to work fine when Gotenberg returns a 200 response.

However, we would really like to use the WebHooks feature and we have the following issues -

  1. The WebHook header function seems to use the incorrect name -
    Gotenberg-Webhookurl-${name} instead of Gotenberg-Webhook-Url-${name}

We are currently working around this issue by setting the headers by hand in a custom function within the pipe method.

  1. It seems that Gotenberg return 204 No Content instead of 200 when the WebHook headers are set.

Gottenberg Docs

In your node.ts file it seems that the client is configured to reject all responses other than 200.

req.on('response', (res) => {
      if (res.statusCode === 200) {
        resolve(res)
      } else {
        let error = res.statusCode + ' ' + res.statusMessage

Do you know of anyway to override or workaround this issue this? Currently I am just catching the error and looking for the words '204 No Content'.

Regards,
Tarek

@yumauri
Copy link
Owner

yumauri commented Jun 25, 2022

Hello! Glad you find it useful :)

I wonder, what if I change condition for successful response to 200 <= statusCode < 300, will it break something? 🤔

Unfortunately there is no workaround to adjust request like with header, but you have another option.
It might be overkill, though :)

This is undocumented, but library allows you to use completely your own HTTP client instead of included. You can pass it as a second argument in function gotenberg.

HTTP client it is an object with methods post and optional get (for ping requests). Methods should return Promise<ReadableStream>.

export interface GotenbergClient {
post: (
url: string,
data: FormData,
headers?: {
[header: string]: number | string | string[] | undefined
}
) => Promise<NodeJS.ReadableStream>
get?: (url: string) => Promise<NodeJS.ReadableStream>
}

As a second argument you can pass either client object, or function factory, or class. If you pass function factory or class, you also can add optional third argument with any configuration for your client.

gotenberg('<url>', client)
gotenberg('<url>', clientFactory, config)
gotenberg('<url>', ClientClass, config)

For example, you can use got library as a underlying HTTP client like this:

import got from 'got'

const client = {
  post: (url, body, headers) =>
    Promise.resolve(
      got.post({ url, body, headers, isStream: true })),
}

pipe(
  gotenberg(`http://localhost:3500/forms/chromium`, client),
  // ...

@yumauri
Copy link
Owner

yumauri commented Jun 26, 2022

I wonder, what if I change condition for successful response to 200 <= statusCode < 300, will it break something? 🤔

I decided it shouldn't break anything, and published small change in version 0.7.3, you can try it :)

@thaoula
Copy link
Author

thaoula commented Jun 28, 2022

Hi @yumauri,

Apologies for not getting back earlier. I just updated to 0.7.3 and removed my try catch for the 204 and it worked fine.

Thanks for make the change.

Regards,
Tarek

@yumauri yumauri closed this as completed Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants