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

Bug: No default HTTP protocol version is set when creating a new Response #2383

Closed
hcbd opened this issue Nov 2, 2019 · 0 comments
Closed
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@hcbd
Copy link

hcbd commented Nov 2, 2019

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

  1. 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;}
}
  1. Create alias and add it to an route

  2. Invoke filter by opening the route in the browser

  3. 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:

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

public function getProtocolVersion(): string

Context

  • OS: Fedora
  • Web server: PHP buildt-in Webserver
  • PHP version 7.3.10
@hcbd hcbd added the bug Verified issues on the current code behavior or pull requests that will fix them label Nov 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

1 participant