Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca1c40e

Browse files
Ismail Turannicolas-grekas
Ismail Turan
authored andcommitted
[HttpKernel] Fix missing Request in RequestStack for StreamedResponse
1 parent4c1d953 commitca1c40e

File tree

4 files changed

+42
-3
lines changed

4 files changed

+42
-3
lines changed

‎src/Symfony/Component/HttpFoundation/StreamedResponse.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ public function setCallback(callable $callback): static
5656
return$this;
5757
}
5858

59+
publicfunctiongetCallback():\Closure
60+
{
61+
return ($this->callback)(...);
62+
}
63+
5964
/**
6065
* This method only sends the headers once.
6166
*

‎src/Symfony/Component/HttpKernel/HttpKernel.php‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
useSymfony\Component\HttpFoundation\Request;
1616
useSymfony\Component\HttpFoundation\RequestStack;
1717
useSymfony\Component\HttpFoundation\Response;
18+
useSymfony\Component\HttpFoundation\StreamedResponse;
1819
useSymfony\Component\HttpKernel\Controller\ArgumentResolver;
1920
useSymfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2021
useSymfony\Component\HttpKernel\Controller\ControllerResolverInterface;
@@ -70,8 +71,9 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
7071
$request->headers->set('X-Php-Ob-Level', (string)ob_get_level());
7172

7273
$this->requestStack->push($request);
74+
$response =null;
7375
try {
74-
return$this->handleRaw($request,$type);
76+
return$response =$this->handleRaw($request,$type);
7577
}catch (\Throwable$e) {
7678
if ($einstanceof \Error && !$this->handleAllThrowables) {
7779
throw$e;
@@ -86,9 +88,23 @@ public function handle(Request $request, int $type = HttpKernelInterface::MAIN_R
8688
throw$e;
8789
}
8890

89-
return$this->handleThrowable($e,$request,$type);
91+
return$response =$this->handleThrowable($e,$request,$type);
9092
}finally {
9193
$this->requestStack->pop();
94+
95+
if ($responseinstanceof StreamedResponse) {
96+
$callback =$response->getCallback();
97+
$requestStack =$this->requestStack;
98+
99+
$response->setCallback(staticfunction ()use ($request,$callback,$requestStack) {
100+
$requestStack->push($request);
101+
try {
102+
$callback();
103+
}finally {
104+
$requestStack->pop();
105+
}
106+
});
107+
}
92108
}
93109
}
94110

‎src/Symfony/Component/HttpKernel/Tests/HttpKernelTest.php‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
useSymfony\Component\HttpFoundation\Request;
1919
useSymfony\Component\HttpFoundation\RequestStack;
2020
useSymfony\Component\HttpFoundation\Response;
21+
useSymfony\Component\HttpFoundation\StreamedResponse;
2122
useSymfony\Component\HttpKernel\Controller\ArgumentResolverInterface;
2223
useSymfony\Component\HttpKernel\Controller\ControllerResolverInterface;
2324
useSymfony\Component\HttpKernel\Event\ExceptionEvent;
@@ -457,6 +458,23 @@ public function testVerifyRequestStackPushPopDuringHandle()
457458
$kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
458459
}
459460

461+
publicfunctiontestVerifyRequestStackPushPopWithStreamedResponse()
462+
{
463+
$request =newRequest();
464+
$stack =newRequestStack();
465+
$dispatcher =newEventDispatcher();
466+
$kernel =$this->getHttpKernel($dispatcher,fn () =>newStreamedResponse(function ()use ($stack) {
467+
echo$stack->getMainRequest()::class;
468+
}),$stack);
469+
470+
$response =$kernel->handle($request, HttpKernelInterface::MAIN_REQUEST);
471+
self::assertNull($stack->getMainRequest());
472+
ob_start();
473+
$response->send();
474+
self::assertSame(Request::class,ob_get_clean());
475+
self::assertNull($stack->getMainRequest());
476+
}
477+
460478
publicfunctiontestInconsistentClientIpsOnMainRequests()
461479
{
462480
$this->expectException(BadRequestHttpException::class);

‎src/Symfony/Component/HttpKernel/composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"symfony/deprecation-contracts":"^2.5|^3",
2121
"symfony/error-handler":"^6.3",
2222
"symfony/event-dispatcher":"^5.4|^6.0",
23-
"symfony/http-foundation":"^6.2.7",
23+
"symfony/http-foundation":"^6.3.4",
2424
"symfony/polyfill-ctype":"^1.8",
2525
"psr/log":"^1|^2|^3"
2626
},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp