-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Describe the bug
No default HTTP protocol version is set when you create a new response object with
$request = new Response( \Config\App() );
CodeIgniter 4 version
4.0.0-rc3
Affected module(s)
HTTP\Response
Expected behavior
A default HTTP protocol version is set and outputted
Output:
HTTP/1.1 200 Found <rest of response>
Currently it outputs:
HTTP/ 200 Found <rest of response>
Reproduce
- Create your own filter
<?php namespace App\Filters;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\Response;
class My_Filter_Name implements FilterInterface
{
function before( RequestInterface $request )
{
// sends a response because it does not like the json provided for example
$response = new Response( \Config\App() );
$response->setHeader('X-Framework', 'CI4');
return $response;
}
function after( RequestInterface $request, ResponseInterface $response ) {return;}
}
-
Create alias and add it to an route
-
Invoke filter by opening the route in the browser
-
You get the raw data string from the server; beginning with
HTTP/ 200 Found
Host: localhost:8080
Date: Sat, 02 Nov 2019 17:34:58 GMT
........
Workaround
set the protocol version in your filter:
$response->setProtocolVersion(1.1);
Fix/Patch
A fix is pretty simple, by editing the following line:
CodeIgniter4/system/HTTP/Response.php
Line 722 in c20b7d7
header(sprintf('HTTP/%s %s %s', $this->protocolVersion, $this->statusCode, $this->reason), true, $this->statusCode); |
Replace
$this->protocolVersion
with
$this->getProtocolVersion()
header(sprintf('HTTP/%s %s %s', $this->getProtocolVersion(), $this->statusCode, $this->reason), true, , $this->statusCode);
The getProtocolVersion() function defaults to 1.1
CodeIgniter4/system/HTTP/Message.php
Line 351 in c20b7d7
public function getProtocolVersion(): string |
Context
- OS: Fedora
- Web server: PHP buildt-in Webserver
- PHP version 7.3.10