-
Notifications
You must be signed in to change notification settings - Fork 212
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
Middleware::ErrorDocument reuses Plack::Request fields from $env in subrequest #128
Comments
No, using That said, I see the first problem, where $env is being reused in the ErrorDocument. Will see how we can fix it, but can I see the problematic code that you're having trouble with? IMO this whole 'subrequest' concept in the ErrorDocument should be refactored/re-coded - it was written in the way early days, and could be implemented much better. |
I created a subclass on top of Plack::Request. When I use the class a second In this code there are the problematic pieces of code. I expect that the
I removed some code, that's not important. I hope this helps. |
Ok, so there are two problems: one is that the subrequest causes $env not to be cleaned up. It's actually intentional but Plack::Request and possibly other middleware that saves $env a cached value might get problematic. The other thing is that you're trying to subclass Plack::Request and want to mess with parameters. I actually had this exact problem with Tatsumaki where it has its own subclassed Request. I haven't yet found a good solution for this, but for the time being it probably might be a good idea to avoid reusing _parameters methods and instead define a new accessor that probably merges all the values from _parameters but do not rely on the $env storage cache. It turns out the latest release and its patch revealed that there's a problem with HTTP::Body and its temporary files cleanup when we instantiate Plack::Request twice - kind of like the same problem, even though the subrequest case has its own intention, which is quite different from calling Plack::Request twice in a legit way (once in middleware and another in the app). |
If an errorcode, e.g. 404, is returned from
$app
andPlack::Request
is used, then$app
adds 'plack.request.' fields to the$env
hash. IfErrorDocument
now calls$app
again (via subrequest) then the old fields are available in thePlack::Request
of the second call to$app
. The secondPlack::Request
shouldn't reuseplack.request.query
. Deleting theplack.request
fields from the$env
hash solves this issue.It however points to a bigger issue with
ErrorDocument
where the$env
hash should possibly be copied.Another problem exists in
Plack::Request
where it saves query information inplack.request.query
, which is the wrong place, when usingPlack::Request
again in a second call using the same$env
.The text was updated successfully, but these errors were encountered: