Skip to content

Commit

Permalink
Fixed blank response header error (#4)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Bryan Nielsen <[email protected]>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent 4f84b71 commit 74926ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Generic fieldtype passes `content_id` along to core fieldtype handler and triggers `pre_process` hook.
- Error checking and handling for GraphQL compatible fieldtypes
- Trigger `core_boot` hook during GraphQL requests
- Handling of blank headers in HTTP responses
- Custom field orderby clauses when it uses legacy field data storage

## [1.1.2] - 2023-07-27
Expand Down
10 changes: 6 additions & 4 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,16 @@ public static function fromOutput($status = 200)
// Transform headers that have already been set on the request
// to the correct format ["header_name" => "value"]
$headers = array_reduce(headers_list(), function ($carry, $header) use ($exclude) {
$pieces = explode(': ', $header);
$pieces = explode(':', $header);
$name = trim($pieces[0]);
$value = $pieces[1] ?? '';

if (! in_array(strtolower($pieces[0]), $exclude)) {
$carry[$pieces[0]] = $pieces[1];
if (! in_array(strtolower($name), $exclude)) {
$carry[$name] = trim($value);
}

// Remove the already set header to avoid duplicates in the response
header_remove($pieces[0]);
header_remove($name);

return $carry;
}, []);
Expand Down

0 comments on commit 74926ec

Please sign in to comment.