Skip to content

Commit

Permalink
Allow set JSON flags in HTTP Request and Response
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Sep 29, 2023
1 parent 0eb2aa0 commit f1c93e8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
12 changes: 12 additions & 0 deletions guide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ Request Config Options
'server_vars' => [],
'allowed_hosts' => [],
'force_https' => false,
'json_flags' => null,
],
],
]
Expand All @@ -949,6 +950,11 @@ force_https
Set ``true`` to automatically redirect to the HTTPS version of the current URL.
By default it is not set.

json_flags
""""""""""

Flags for ``json_decode``. The default is set to none.

Response Service
^^^^^^^^^^^^^^^^

Expand All @@ -974,6 +980,7 @@ Response Config Options
'cache' => null,
'csp' => [],
'csp_report_only' => [],
'json_flags' => null,
'request_instance' => 'default',
],
],
Expand Down Expand Up @@ -1028,6 +1035,11 @@ It can take an array of directives to initialize an instance of
``Framework\HTTP\CSP`` and pass it as the **Content-Security-Policy-Report-Only**
of the response.

json_flags
""""""""""

Flags for ``json_encode``. The default is set to none.

request_instance
""""""""""""""""

Expand Down
6 changes: 6 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -1122,6 +1122,9 @@ protected static function setRequest(string $instance) : Request
if (isset($config['force_https']) && $config['force_https'] === true) {
$service->forceHttps();
}
if (isset($config['json_flags'])) {
$service->setJsonFlags($config['json_flags']);
}
return static::setService('request', $service, $instance);
}

Expand Down Expand Up @@ -1191,6 +1194,9 @@ protected static function setResponse(string $instance) : Response
if (!empty($config['csp_report_only'])) {
$service->setCspReportOnly(new CSP($config['csp_report_only']));
}
if (isset($config['json_flags'])) {
$service->setJsonFlags($config['json_flags']);
}
return static::setService('response', $service, $instance);
}

Expand Down
1 change: 1 addition & 0 deletions tests/configs/request.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
'server_vars' => [
'HTTP_FOO' => 'Foo',
],
'json_flags' => \JSON_THROW_ON_ERROR,
],
];
1 change: 1 addition & 0 deletions tests/configs/response.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
'self',
],
],
'json_flags' => \JSON_THROW_ON_ERROR,
'request_instance' => 'default',
],
];

0 comments on commit f1c93e8

Please sign in to comment.