Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
fix(Response): Fix Header Set-Cookie header don't clean
Browse files Browse the repository at this point in the history
1. since $response->headers->replace() will not clean the whole headerBag (will left the `cookies` and may cause the header `Date` appear twice), it's may better to create a new ResponseHeaderBag Instance for $response->headers but not reuse it. (See: symfony/symfony#35845 )
2. Use `$response->headers->clearCookie` to remove browser cookie install the wrong method `removeCookie()`.
  • Loading branch information
Rhilip committed Feb 24, 2020
1 parent 82977ea commit 144eef7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion application/Middleware/AuthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle($callable, \Closure $next)
}

// Prevent Other Route
app()->response->headers->removeCookie(Constant::cookie_name); // Delete exist cookies
app()->response->headers->clearCookie(Constant::cookie_name); // Delete exist cookies
app()->session->set('login_return_to', app()->request->getUri()); // Store the url which visitor want to hit
return app()->response->setRedirect('/auth/login');
}
Expand Down
2 changes: 1 addition & 1 deletion application/Models/Form/Auth/UserLogoutForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function flush()

private function invalidSession()
{
app()->response->headers->removeCookie(Constant::cookie_name); // Clean cookie
app()->response->headers->clearCookie(Constant::cookie_name); // Clean cookie
app()->redis->zAdd(UserFactory::mapUserSessionToId, 0, $this->sid); // Quick Mark this invalid in cache

// Set this session expired
Expand Down
1 change: 0 additions & 1 deletion application/Models/Form/User/SessionsListForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static function inputRules(): array

protected function getRemoteTotal(): int
{
var_dump($this->getInput('expired'));
return app()->pdo->prepare([
['SELECT COUNT(`id`) FROM sessions WHERE uid = :uid ', 'params' => ['uid' => $this->getInput('uid')]],
['AND `expired` IN (:expired)', 'params' => ['expired' => $this->getInput('expired')]],
Expand Down
6 changes: 3 additions & 3 deletions framework/Http/HttpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
class HttpServer
{
public $name = 'rid-httpd';
public string $name = 'rid-httpd';

// 运行参数
public $settings = [];
public array $settings = [];

// 默认运行参数
protected $_default_settings = [
protected array $_default_settings = [
'enable_coroutine' => false, // 开启协程
'reactor_num' => 8, // 主进程事件处理线程数
'worker_num' => 8, // 工作进程数
Expand Down
25 changes: 17 additions & 8 deletions framework/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Response as HttpFoundationResponse;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;

/**
* Response组件
Expand All @@ -16,17 +17,25 @@ class Response extends HttpFoundationResponse implements Base\StaticInstanceInte
{
use Base\StaticInstanceTrait, Base\ComponentTrait;

/** @var \Swoole\Http\Response */
protected $_responder;
/**
* Class of Response From Swoole
*
* @var \Swoole\Http\Response
*/
protected \Swoole\Http\Response $_responder;

/**
* @var File
* The file we want to send to client
*/
protected $file;
protected $filename;
protected ?File $file = null;
protected ?string $filename = null;

// 是否已经发送
protected $_isSent = false;
/**
* If this response have been sent to client
*
* @var bool
*/
protected bool $_isSent = false;

protected static $trustXSendfileTypeHeader = false;

Expand All @@ -45,7 +54,7 @@ public function setResponder(\Swoole\Http\Response $responder)
}

private function cleanResponse() {
$this->headers->replace();
$this->headers = new ResponseHeaderBag([]);
$this->setContent('');
$this->setStatusCode(200);
$this->setProtocolVersion('1.0');
Expand Down

0 comments on commit 144eef7

Please sign in to comment.