WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Headers are ignored #3

@cs278

Description

@cs278

This code does not work when run on the CLI, which poses a problem when trying to write tests which send headers.

$headers = [];
$php_headers = headers_list();
foreach ($php_headers as $value) {
// Get the header name
$parts = explode(':', $value);
if (count($parts) > 1) {
$name = trim(array_shift($parts));
// Build the header hash map
$headers[$name] = trim(implode(':', $parts));
}
}
$headers['Content-type'] = isset($headers['Content-type'])
? $headers['Content-type']
: "text/html; charset=UTF-8";
$response = new Response($content, 200, $headers);

From what I can tell the header() function on the CLI does absolutely nothing so the headers are not stored for later retrieval.

There are a few other problems with this code like it always returns a 200 response code, headers are case insensitive which could break the isset(), the same header can be sent multiple times so only the last one will be kept by this code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions