Skip to content

Commit

Permalink
[RELEASE_8.7.0] Add new field form Chromium (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRenaux authored Jul 18, 2024
1 parent 17907f1 commit 560fd1a
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 4 deletions.
6 changes: 6 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand Down Expand Up @@ -88,6 +89,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand Down Expand Up @@ -119,6 +121,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand Down Expand Up @@ -155,6 +158,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand All @@ -171,6 +175,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand All @@ -187,6 +192,7 @@ sensiolabs_gotenberg:
wait_for_expression: null # None
emulated_media_type: null # 'print'
cookies: null # None
user_agent: null # None
extra_http_headers: null # None
fail_on_http_status_codes: null # [499-599]
fail_on_console_exceptions: null # false
Expand Down
3 changes: 3 additions & 0 deletions docs/pdf/builders_api/HtmlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
3 changes: 3 additions & 0 deletions docs/pdf/builders_api/MarkdownPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
3 changes: 3 additions & 0 deletions docs/pdf/builders_api/UrlPdfBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
27 changes: 26 additions & 1 deletion docs/pdf/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
[cookies](#cookies)
[setCookie](#setCookie)
[addCookies](#addCookies)
[userAgent](#userAgent)
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
[failOnHttpStatusCodes](#failOnHttpStatusCodes)
Expand Down Expand Up @@ -728,6 +729,31 @@ class YourController
}
```

### userAgent()

default: `None`

Override the default User-Agent HTTP header.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\Enumeration\UserAgent;
use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg
->html()
->userAgent(UserAgent::AndroidChrome) // You can pass any string. This class is just a helper.
->generate()
;
}
}
```

### extraHttpHeaders

default: `None`
Expand Down Expand Up @@ -1015,4 +1041,3 @@ class YourController

> [!TIP]
> For more information go to [Gotenberg documentations](https://gotenberg.dev/docs/routes#pdfa-chromium).
3 changes: 3 additions & 0 deletions docs/screenshot/builders_api/HtmlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
3 changes: 3 additions & 0 deletions docs/screenshot/builders_api/MarkdownScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
3 changes: 3 additions & 0 deletions docs/screenshot/builders_api/UrlScreenshotBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ For instance: "window.status === 'ready'".
* `emulatedMediaType(Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType $mediaType)`:
Forces Chromium to emulate, either "screen" or "print". (default "print").

* `userAgent(string $userAgent)`:
Override the default User-Agent HTTP header. (default None).

* `extraHttpHeaders(array $headers)`:
Sets extra HTTP headers that Chromium will send when loading the HTML
document. (default None). (overrides any previous headers).
Expand Down
25 changes: 25 additions & 0 deletions docs/screenshot/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[cookies](#cookies)
[setCookie](#setCookie)
[addCookies](#addCookies)
[userAgent](#userAgent)
[extraHttpHeaders](#extraHttpHeaders)
[addExtraHttpHeaders](#addExtraHttpHeaders)
[failOnHttpStatusCodes](#failOnHttpStatusCodes)
Expand Down Expand Up @@ -393,6 +394,30 @@ class YourController
}
```

### userAgent()

default: `None`

Override the default User-Agent HTTP header.

```php
namespace App\Controller;

use Sensiolabs\GotenbergBundle\GotenbergScreenshotInterface;

class YourController
{
public function yourControllerMethod(GotenbergScreenshotInterface $gotenberg): Response
{
return $gotenberg
->html()
->userAgent(UserAgent::AndroidChrome) // You can pass any string. This class is just a helper.
->generate()
;
}
}
```

### extraHttpHeaders

default: `None`
Expand Down
18 changes: 17 additions & 1 deletion src/Builder/Pdf/AbstractChromiumPdfBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sensiolabs\GotenbergBundle\Enumeration\Part;
use Sensiolabs\GotenbergBundle\Enumeration\PdfFormat;
use Sensiolabs\GotenbergBundle\Enumeration\Unit;
use Sensiolabs\GotenbergBundle\Enumeration\UserAgent;
use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration;
use Sensiolabs\GotenbergBundle\Exception\PdfPartRenderingException;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
Expand Down Expand Up @@ -375,11 +376,25 @@ public function emulatedMediaType(EmulatedMediaType $mediaType): static
return $this;
}

/**
* Override the default User-Agent HTTP header. (default None).
*
* @param UserAgent::*|string $userAgent
*
* @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium
*/
public function userAgent(string $userAgent): static
{
$this->formFields['userAgent'] = $userAgent;

return $this;
}

/**
* Sets extra HTTP headers that Chromium will send when loading the HTML
* document. (default None). (overrides any previous headers).
*
* @see https://gotenberg.dev/docs/routes#custom-http-headers
* @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium
*
* @param array<string, string> $headers
*/
Expand Down Expand Up @@ -565,6 +580,7 @@ protected function addConfiguration(string $configurationName, mixed $value): vo
'wait_for_expression' => $this->waitForExpression($value),
'emulated_media_type' => $this->emulatedMediaType(EmulatedMediaType::from($value)),
'cookies' => $this->cookies($value),
'user_agent' => $this->userAgent($value),
'extra_http_headers' => $this->extraHttpHeaders($value),
'fail_on_http_status_codes' => $this->failOnHttpStatusCodes($value),
'fail_on_console_exceptions' => $this->failOnConsoleExceptions($value),
Expand Down
18 changes: 17 additions & 1 deletion src/Builder/Screenshot/AbstractChromiumScreenshotBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Sensiolabs\GotenbergBundle\Enumeration\EmulatedMediaType;
use Sensiolabs\GotenbergBundle\Enumeration\Part;
use Sensiolabs\GotenbergBundle\Enumeration\ScreenshotFormat;
use Sensiolabs\GotenbergBundle\Enumeration\UserAgent;
use Sensiolabs\GotenbergBundle\Exception\InvalidBuilderConfiguration;
use Sensiolabs\GotenbergBundle\Exception\ScreenshotPartRenderingException;
use Sensiolabs\GotenbergBundle\Formatter\AssetBaseDirFormatter;
Expand Down Expand Up @@ -211,11 +212,25 @@ public function emulatedMediaType(EmulatedMediaType $mediaType): static
return $this;
}

/**
* Override the default User-Agent HTTP header. (default None).
*
* @param UserAgent::*|string $userAgent
*
* @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium
*/
public function userAgent(string $userAgent): static
{
$this->formFields['userAgent'] = $userAgent;

return $this;
}

/**
* Sets extra HTTP headers that Chromium will send when loading the HTML
* document. (default None). (overrides any previous headers).
*
* @see https://gotenberg.dev/docs/routes#custom-http-headers
* @see https://gotenberg.dev/docs/routes#custom-http-headers-chromium
*
* @param array<string, string> $headers
*/
Expand Down Expand Up @@ -363,6 +378,7 @@ private function addConfiguration(string $configurationName, mixed $value): void
'wait_for_expression' => $this->waitForExpression($value),
'emulated_media_type' => $this->emulatedMediaType($value),
'cookies' => $this->cookies($value),
'user_agent' => $this->userAgent($value),
'extra_http_headers' => $this->extraHttpHeaders($value),
'fail_on_http_status_codes' => $this->failOnHttpStatusCodes($value),
'fail_on_console_exceptions' => $this->failOnConsoleExceptions($value),
Expand Down
22 changes: 21 additions & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,16 @@ private function addChromiumPdfOptionsNode(ArrayNodeDefinition $parent): void
->end()
->end()
->end()
->scalarNode('user_agent')
->info('Override the default User-Agent HTTP header. - default None. https://gotenberg.dev/docs/routes#custom-http-headers-chromium')
->defaultNull()
->validate()
->ifTrue(static function ($option) {
return !\is_string($option);
})
->thenInvalid('Invalid value %s')
->end()
->end()
->arrayNode('extra_http_headers')
->info('HTTP headers to send by Chromium while loading the HTML document - default None. https://gotenberg.dev/docs/routes#custom-http-headers')
->defaultValue([])
Expand Down Expand Up @@ -415,8 +425,18 @@ private function addChromiumScreenshotOptionsNode(ArrayNodeDefinition $parent):
->end()
->end()
->end()
->scalarNode('user_agent')
->info('Override the default User-Agent HTTP header. - default None. https://gotenberg.dev/docs/routes#custom-http-headers-chromium')
->defaultNull()
->validate()
->ifTrue(static function ($option) {
return !\is_string($option);
})
->thenInvalid('Invalid value %s')
->end()
->end()
->arrayNode('extra_http_headers')
->info('HTTP headers to send by Chromium while loading the HTML document - default None. https://gotenberg.dev/docs/routes#custom-http-headers')
->info('HTTP headers to send by Chromium while loading the HTML document - default None. https://gotenberg.dev/docs/routes#custom-http-headers-chromium')
->defaultValue([])
->useAttributeAsKey('name')
->arrayPrototype()
Expand Down
Loading

0 comments on commit 560fd1a

Please sign in to comment.