Skip to content

Commit f1c93e8

Browse files
committed
Allow set JSON flags in HTTP Request and Response
1 parent 0eb2aa0 commit f1c93e8

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

guide/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,7 @@ Request Config Options
929929
'server_vars' => [],
930930
'allowed_hosts' => [],
931931
'force_https' => false,
932+
'json_flags' => null,
932933
],
933934
],
934935
]
@@ -949,6 +950,11 @@ force_https
949950
Set ``true`` to automatically redirect to the HTTPS version of the current URL.
950951
By default it is not set.
951952

953+
json_flags
954+
""""""""""
955+
956+
Flags for ``json_decode``. The default is set to none.
957+
952958
Response Service
953959
^^^^^^^^^^^^^^^^
954960

@@ -974,6 +980,7 @@ Response Config Options
974980
'cache' => null,
975981
'csp' => [],
976982
'csp_report_only' => [],
983+
'json_flags' => null,
977984
'request_instance' => 'default',
978985
],
979986
],
@@ -1028,6 +1035,11 @@ It can take an array of directives to initialize an instance of
10281035
``Framework\HTTP\CSP`` and pass it as the **Content-Security-Policy-Report-Only**
10291036
of the response.
10301037

1038+
json_flags
1039+
""""""""""
1040+
1041+
Flags for ``json_encode``. The default is set to none.
1042+
10311043
request_instance
10321044
""""""""""""""""
10331045

src/App.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,9 @@ protected static function setRequest(string $instance) : Request
11221122
if (isset($config['force_https']) && $config['force_https'] === true) {
11231123
$service->forceHttps();
11241124
}
1125+
if (isset($config['json_flags'])) {
1126+
$service->setJsonFlags($config['json_flags']);
1127+
}
11251128
return static::setService('request', $service, $instance);
11261129
}
11271130

@@ -1191,6 +1194,9 @@ protected static function setResponse(string $instance) : Response
11911194
if (!empty($config['csp_report_only'])) {
11921195
$service->setCspReportOnly(new CSP($config['csp_report_only']));
11931196
}
1197+
if (isset($config['json_flags'])) {
1198+
$service->setJsonFlags($config['json_flags']);
1199+
}
11941200
return static::setService('response', $service, $instance);
11951201
}
11961202

tests/configs/request.config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
'server_vars' => [
1515
'HTTP_FOO' => 'Foo',
1616
],
17+
'json_flags' => \JSON_THROW_ON_ERROR,
1718
],
1819
];

tests/configs/response.config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
'self',
3939
],
4040
],
41+
'json_flags' => \JSON_THROW_ON_ERROR,
4142
'request_instance' => 'default',
4243
],
4344
];

0 commit comments

Comments
 (0)