gotenberg icon indicating copy to clipboard operation
gotenberg copied to clipboard

Ability to post data when using chromium

Open davideapvd opened this issue 3 years ago • 4 comments

Is it be possible to change the request method to POST passing additional body data when using chromium engine?

davideapvd avatar Aug 29 '22 14:08 davideapvd

From the README.md:

You may use any HTTP client that is able to handle a PSR-7 RequestInterface to call the API:

use Gotenberg\Gotenberg;

$request = Gotenberg::chromium('http://localhost:3000')->url('https://my.url');

gulien avatar Aug 29 '22 15:08 gulien

Hello @gulien, what I meant is not for calling the api but instructing chromium to make a POST request to url, passing additional data (for example as multipart/form-data), instead, can you make an example if that's already possible?

davideapvd avatar Aug 29 '22 15:08 davideapvd

Ok, got it!

No, you can't do that, but you could try some workarounds, for instance by injecting a remote script that do the job (extraScriptTags - https://gotenberg.dev/docs/modules/chromium#url). I guess it would require the --chromium-disable-web-security property. Also, it would depend on the security backend wise.

If you have access to the URL source code, using custom HTTP headers might also do the trick:

curl \
--request POST 'http://localhost:3000/forms/chromium/convert/url' \
--form 'url="https://my.url"' \
--form 'userAgent="Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1"' \
--form 'extraHttpHeaders="{\"MyHeader\": \"MyValue\"}"' \
-o my.pdf

gulien avatar Aug 29 '22 15:08 gulien

I was thinking of using extraScriptTags but in the end is not really feasible, as I see, and speaking for a general case, it it could be useful to have a standard way to pass configuration data, because often those pdf are something we customize for a client: invoices, product configuration, reports, and are the result of some sort of form submit from the user.

I don't like the the suggested http header because often proxies are configured to have a really short http header limit and could be equivalent to passing GET data in terms on limitations.

What do you think?

davideapvd avatar Aug 30 '22 07:08 davideapvd