Skip to content

Commit 74926ec

Browse files
krytenukgarryxigenbryannielsen
authored
Fixed blank response header error (#4)
* Added check to ensure response header is not blank * Changed removal of blank header to just fix header name and use a blank content * Simplify default blank header and add changelog --------- Co-authored-by: Garry Childs <garry.childs@xigen.co.uk> Co-authored-by: Bryan Nielsen <bryan@packettide.com>
1 parent 4f84b71 commit 74926ec

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Generic fieldtype passes `content_id` along to core fieldtype handler and triggers `pre_process` hook.
1313
- Error checking and handling for GraphQL compatible fieldtypes
1414
- Trigger `core_boot` hook during GraphQL requests
15+
- Handling of blank headers in HTTP responses
1516
- Custom field orderby clauses when it uses legacy field data storage
1617

1718
## [1.1.2] - 2023-07-27

src/Response.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,16 @@ public static function fromOutput($status = 200)
257257
// Transform headers that have already been set on the request
258258
// to the correct format ["header_name" => "value"]
259259
$headers = array_reduce(headers_list(), function ($carry, $header) use ($exclude) {
260-
$pieces = explode(': ', $header);
260+
$pieces = explode(':', $header);
261+
$name = trim($pieces[0]);
262+
$value = $pieces[1] ?? '';
261263

262-
if (! in_array(strtolower($pieces[0]), $exclude)) {
263-
$carry[$pieces[0]] = $pieces[1];
264+
if (! in_array(strtolower($name), $exclude)) {
265+
$carry[$name] = trim($value);
264266
}
265267

266268
// Remove the already set header to avoid duplicates in the response
267-
header_remove($pieces[0]);
269+
header_remove($name);
268270

269271
return $carry;
270272
}, []);

0 commit comments

Comments
 (0)