Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed blank response header error #4

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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