-
Notifications
You must be signed in to change notification settings - Fork 9
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
Option to add http/https agent of my own. #28
Comments
Hello! You can do it :) Actually, there are few options (none is documented though...). But not with Function
It tries to guess type of a second argument, and if it is not HTTP client — it is considered to be config for embeded client. gotenberg(
getVariableValue("GOTENBERG_BASE_URL"),
{ agent: new http.Agent({ keepAlive: true }) }
), As stated in the 1, you can create and pass completely your own HTTP client to HTTP Client (GotenbergClient) could be a plain object with fields Then
and should return |
Sidenote about point 1: |
Hi ! Update: Thanks ! |
Sidenote about point 2: Here are different examples of custom HTTP client, based on got library (I didn't try them though, but to show an idea it should be enough):
const client = {
post(url, body, headers) {
return got.post(url, { body, headers })
}
}
function client(config) {
// you can use config here for some preparations
return {
post(url, body, headers) {
return got.post(url, { body, headers })
}
}
}
class client {
constructor(config) {
// you can use config here for some preparations
}
post(url, body, headers) {
return got.post(url, { body, headers })
}
} Then you can use this client in gotenberg(
getVariableValue("GOTENBERG_BASE_URL"),
client, // one of the clients from above
config // any config for your client
), |
So, As this is technique from functional programming — you can partially apply pipe, like this: const partialToPDF = pipe(
gotenberg(
getVariableValue("GOTENBERG_BASE_URL"),
{ agent: new http.Agent({ keepAlive: true }) }
),
convert,
html,
)
// ---8<---
function convertMyDocument(document) {
const toPDF = pipe(
partialToPDF,
to({
marginTop: margin.top,
marginBottom: margin.bot,
marginLeft: margin.left,
marginRight: margin.right,
landscape
}),
please
)
return toPDF(document)
}
If you pass |
Note, that you can't change conversion type in partial pipe application, because pipe(
gotenberg(...),
convert,
url,
html,
...
) It will use path But I've got you covered, and made an exception for such case :) Following issue #14 But overriding margings, paper size, orientation and any headers should work fine. |
Sorry for amount of comments :) You also can make smth like this: // define this globally
const myGotenberg = gotenberg(
getVariableValue("GOTENBERG_BASE_URL"),
{ agent: new http.Agent({ keepAlive: true }) }
)
// then use this function in pipe
const toPDF = pipe(
myGotenberg,
convert,
html,
to({
marginTop: margin.top,
marginBottom: margin.bot,
marginLeft: margin.left,
marginRight: margin.right,
landscape
}),
please
) |
Hello, |
Hi,
What I want to be able to do is send my own HTTP/HTTPS agent - this is to be able to set keepAlive: true.
I tried looking through the library's code but couldn't find a way. (could barely understand what was going on - inexperienced with ts)
Does this option exist today?
Is it possible to add or make a workaround in my project to set it like this?
If its not possible I will have to "wrap" the gotenberg client myself which I really try to avoid.
Thanks :)
Update:
I just noticed you added "adjust" in your latest version.
It looks like it might be able to do what I need.
Can you let me know if this code does it ?
The text was updated successfully, but these errors were encountered: