-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
RequestFactory: invalid byte sequences in $_SERVER['REQUEST_URI'] #30
base: master
Are you sure you want to change the base?
Conversation
Exception is fine with me. But the main problem here is how to present the error to the user. If I visit such URL I definitely shouldn't see error page generated by Tracy. It should fall to error presenter - I don't wanna have log full of bluescreens - I want to have one string line in One thing that crosses my mind is to return instance of |
Then it should be your job to handle it. But it is obviously a nasty BC break.
👎 That does not feel right. Another think to consider – if you choose to change the API and throw exception, we may also reconsider how we handle control characters (note: that is something different than invalid encoding which is what the exception is primary for). Currently we ignore keys with control characters and discard values with control characters. |
The whole problem is that the usage of Http\Request in Nette\Application (the api) is really bad. The api should look like this $app = $container->getByType(Nette\Application\Application::class);
$app->handle($container->getByType(Nette\Http\RequestFactory::class)->create()); Then, you have perfect control of when the request is created and what you do with it. $app = $container->getByType(Nette\Application\Application::class);
try {
$app->handle($container->getByType(Nette\Http\RequestFactory::class)->create());
} catch (Nette\Http\InvalidRequestException $e) {
$app->handleInvalidRequest($e); // this could for example open the error presenter
} In the end, the entire thing could be hidden in public function run()
{
try {
$this->handle($this->httpFactory->create());
} catch (Nette\Http\InvalidRequestException $e) {
$this->handleInvalidRequest($e); // this could for example open the error presenter
}
} At this point, you're gaining the possibility to handle the exception created by invalid request in appropriate level of abstraction. It should either be rejected by the http server (nginx), or it should be handled by the front controller as bad request and error presenter should be shown. Having The service Symfony has much better front controller API ... We should investigate how Symfony and other frameworks handle this situation and then decide what is best for us. |
So |
I was thinking something like class RequestStack implements IRequest
{
private $requests = [];
private $lastRequest;
public function append(IRequestFactory $factory)
{
$this->lastRequest = $factory->create();
$this->requests[] = $this->lastRequest;
return $this->lastRequest;
}
public function getUrl()
{
return $this->lastRequest->getUrl();
}
// ...
} How will the stack be handled is a detail, it could even be container only for the lastRequest. The point is, that we must have a container for the |
$_SERVER['REQUEST_URI']
$_SERVER['REQUEST_URI']
acdaec6
to
563c85a
Compare
+1 Only thing which bothers me is not logging this exception. Don't worry about making the bc break. Can't imagine how somehow would create theses malformed urls intentionaly. |
Related – I would also like to change how we handle invalid |
@fprochazka I look at the It seems to be the best solution to the problem. Thoughts? cc @dg Note: Nette needs the Maybe – just maybe – we may 1) remove |
@JanTvrdik well, beeing the one suggesting it, I hardly can disagree :) |
RequestStack is not suitable for Nette, because it solves a different problem (as @JanTvrdik said, Nette has stack of Application\Request). When you need to create Http\Request inside Application, Nette has native solution: interface & generated factory. |
@dg I'm not sure you understand the problem. The problem is that |
@fprochazka I understand. (btw, value object can be service.) |
Well obviousely, but that doesn't make it right. Identity is not a service. |
"Identity is not a service → value object as a service is wrong" is fallacy of the converse. |
The
Because Nette has no scopes in DIC, having value objects as a service is wrong. Simple as that. |
@fprochazka in czech. Prove that for each value object is wrong to have it as a service. |
I don't want to say "there isn't a case where having value object as a service is a good thing", but I can't think of any. I also don't have to prove it (at least not about In other case (there are two, the specific one with
Also about the Identity example, that you like to repeat instead of continuing in the discussion, I haven't stated that there is an implication, it was just a very good example, because it's the most obviouse one. |
Basically, DIC should almost always hold only services, not the entities, crates, etc. This is the general rule, which also aplies here. |
Regarding |
Stack makes sense with subrequests in symfony. They don't have snippets and controls. They have subrequests (recursive calling of controllers and their output is then composed into a single template), which can be converted to proxy-level subrequests, which makes caching them a reall bliss. I don't think that makes much sense with Nette, implementing this would be probably hard. Stack might make sense when you have forwarded requests. But I'm not sure. |
@fprochazka You said that the value object cannot be a service, which is a strong & general statement, but you cannot prove it (the fact that some value objects cannot be used as services is really not an evidence, see fallacy of the converse). I would prefer to end debate about VO. |
Would you preffer to end it at this issue (because it's a little bit off topic), or end it all together? Because I don't think the debate is over, because you haven't conviced me and neither have I convinced you. |
Here. It is off topic. |
da24b94
to
540335c
Compare
e7c7e2d
to
bf945f3
Compare
9a14e6e
to
a20fb8f
Compare
55488bd
to
2042d2e
Compare
4960652
to
5e67add
Compare
689f4ae
to
33aae19
Compare
09923de
to
02ae846
Compare
The goal is to not simply ignore invalid byte sequences in URL, but throw Exception or return NULL. Current Nette behavior is unwanted, e.g. these URLs should not be accepted at all:
How would you prefer to handle it? Exception or by returning NULL. Both break the RequestFactory API. I would prefer the exception, e. g.
Nette\Http\InvalidRequestException
. Do you like the name?cc @fprochazka