-
-
Notifications
You must be signed in to change notification settings - Fork 143
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
Return internal server error for unexpected exceptions #233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -186,7 +186,7 @@ public function handleConnection(ConnectionInterface $conn) | |
|
||
$that->writeError( | ||
$conn, | ||
$e->getCode() !== 0 ? $e->getCode() : 400 | ||
$e->getCode() !== 0 ? $e->getCode() : 500 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think any exception code should just be forwarded to the client here as a status code. Most exception codes aren't HTTP status codes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I've not been able to figure out if/what exception codes PHP uses. But inside react/http all codes are specifically generated with the purpose of being used as HTTP return codes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This particular code only catches |
||
); | ||
}); | ||
} | ||
|
@@ -198,7 +198,7 @@ public function handleRequest(ConnectionInterface $conn, ServerRequestInterface | |
$stream = new CloseProtectionStream($conn); | ||
if ($request->hasHeader('Transfer-Encoding')) { | ||
if (strtolower($request->getHeaderLine('Transfer-Encoding')) !== 'chunked') { | ||
$this->emit('error', array(new \InvalidArgumentException('Only chunked-encoding is allowed for Transfer-Encoding'))); | ||
$this->emit('error', array(new \InvalidArgumentException('Only chunked-encoding is allowed for Transfer-Encoding', 400))); | ||
return $this->writeError($conn, 501, $request); | ||
} | ||
|
||
|
@@ -214,7 +214,7 @@ public function handleRequest(ConnectionInterface $conn, ServerRequestInterface | |
$contentLength = (int)$string; | ||
if ((string)$contentLength !== (string)$string) { | ||
// Content-Length value is not an integer or not a single integer | ||
$this->emit('error', array(new \InvalidArgumentException('The value of `Content-Length` is not valid'))); | ||
$this->emit('error', array(new \InvalidArgumentException('The value of `Content-Length` is not valid', 400))); | ||
return $this->writeError($conn, 400, $request); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree that it may make sense for invalid request headers, I'm not sure about the changes in this class. This class only deals with decoding the request body which will be streamed to the request handler. As such, the status codes do not necessarily end up in the response code.
See also other occurrences in this class.