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
[yii2] Headers are cached when flushInterval is low. #4587
Comments
Understood more or less. No immediate thoughts on fixing it though. |
Adding this after reinitializing // Clear the headers cache.
if (Yii::$app->has('request', true)) {
$property = (new \ReflectionClass(Request::class))->getProperty('_headers');
$property->setAccessible(true);
$property->setValue(\Yii::$app->request, null);
} |
I guess same should be done to _cookies, right? |
Probably. |
A pull request? |
Which approach? I found some other things that initiate the
The problem here is that calling |
This is a niche issue; I'll update it with more information and a proposed solution in the coming days.
Also I'll clean it up soon ^^
@samdark please have a look as well and see if understand what I mean.
What are you trying to achieve?
Functional test, specifically
sendPost
andamBearerAuthenticated
.What do you get instead?
The header is not interpreted by Yii.
The problem is caused by the following chain of events:
_before
loads the application.request
component in its bootstrap:yii\log\Target
tries to get the user IP.$_SERVER
variable gets initialized for the request.Known causes
yii\helpers\Url::to
(sidenote passing an array tosendPOST
doesn't work but works for_request
; itwould still create a bad cache for theRequest
component).Proposed solution with changes to Yii2 and Codeception:
The
Request
component could be improved to allow for clearing the header cache; or a configuration option could be added to disable it.The Codeception code should then clear the header cache via the configuration option or method.
Proposed solution with changes to Codeception (Yii2 only):
Alternatively we could forcefully go into the object and set it's private property to
null
, we should do this everytime after we change $_SERVER:Conclusion
The first approach makes it testable in Yii2 code and is future proof. The second approach could theoretically break at any moment where the internal structure of
yii\web\Request
changes.The text was updated successfully, but these errors were encountered: