Skip to content

Commit

Permalink
fix: Http/HttpTest
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepDiver1975 committed Oct 2, 2023
1 parent db10141 commit 9f6e161
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
17 changes: 9 additions & 8 deletions lib/private/AppFramework/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
use OCP\AppFramework\Http as BaseHttp;

class Http extends BaseHttp {
private $server;
private $protocolVersion;
protected $headers;
private array $server;
private string $protocolVersion;
protected array $headers;

/**
* @param array $server $_SERVER
* @param string $protocolVersion the http version to use defaults to HTTP/1.1
*/
public function __construct($server, $protocolVersion='HTTP/1.1') {
public function __construct(array $server, string $protocolVersion='HTTP/1.1') {
$this->server = $server;
$this->protocolVersion = $protocolVersion;

Expand Down Expand Up @@ -107,16 +107,17 @@ public function __construct($server, $protocolVersion='HTTP/1.1') {

/**
* Gets the correct header
*
* @param Http::CONSTANT $status the constant from the Http class
* @param \DateTime $lastModified formatted last modified date
* @param string $ETag the etag
* @param \DateTime|null $lastModified formatted last modified date
* @param null $ETag the etag
* @return string
*/
public function getStatusHeader(
$status,
\DateTime $lastModified=null,
$ETag=null
) {
): string {
if ($lastModified !== null) {
$lastModified = $lastModified->format(\DateTime::RFC2822);
}
Expand All @@ -135,7 +136,7 @@ public function getStatusHeader(

// we have one change currently for the http 1.0 header that differs
// from 1.1: STATUS_TEMPORARY_REDIRECT should be STATUS_FOUND
// if this differs any more, we want to create childclasses for this
// if this differs anymore, we want to create child-classes for this
if ($status === self::STATUS_TEMPORARY_REDIRECT
&& $this->protocolVersion === 'HTTP/1.0') {
$status = self::STATUS_FOUND;
Expand Down
27 changes: 13 additions & 14 deletions tests/lib/AppFramework/Http/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@

namespace Test\AppFramework\Http;

use DateTime;
use DateTimeZone;
use OC\AppFramework\Http;
use Test\TestCase;

class HttpTest extends \Test\TestCase {
private $server;

/**
* @var Http
*/
private $http;
class HttpTest extends TestCase {
private array $server;
private Http $http;

protected function setUp(): void {
parent::setUp();
Expand All @@ -40,33 +39,33 @@ protected function setUp(): void {
$this->http = new Http($this->server);
}

public function testProtocol() {
public function testProtocol(): void {
$header = $this->http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
$this->assertEquals('HTTP/1.1 307 Temporary Redirect', $header);
}

public function testProtocol10() {
public function testProtocol10(): void {
$this->http = new Http($this->server, 'HTTP/1.0');
$header = $this->http->getStatusHeader(Http::STATUS_OK);
$this->assertEquals('HTTP/1.0 200 OK', $header);
}

public function testEtagMatchReturnsNotModified() {
public function testEtagMatchReturnsNotModified(): void {
$http = new Http(['HTTP_IF_NONE_MATCH' => 'hi']);

$header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi');
$this->assertEquals('HTTP/1.1 304 Not Modified', $header);
}

public function testQuotedEtagMatchReturnsNotModified() {
public function testQuotedEtagMatchReturnsNotModified(): void {
$http = new Http(['HTTP_IF_NONE_MATCH' => '"hi"']);

$header = $http->getStatusHeader(Http::STATUS_OK, null, 'hi');
$this->assertEquals('HTTP/1.1 304 Not Modified', $header);
}

public function testLastModifiedMatchReturnsNotModified() {
$dateTime = new \DateTime(null, new \DateTimeZone('GMT'));
public function testLastModifiedMatchReturnsNotModified(): void {
$dateTime = new DateTime('now', new DateTimeZone('GMT'));
$dateTime->setTimestamp('12');

$http = new Http(
Expand All @@ -78,7 +77,7 @@ public function testLastModifiedMatchReturnsNotModified() {
$this->assertEquals('HTTP/1.1 304 Not Modified', $header);
}

public function testTempRedirectBecomesFoundInHttp10() {
public function testTempRedirectBecomesFoundInHttp10(): void {
$http = new Http([], 'HTTP/1.0');

$header = $http->getStatusHeader(Http::STATUS_TEMPORARY_REDIRECT);
Expand Down

0 comments on commit 9f6e161

Please sign in to comment.