-
-
Notifications
You must be signed in to change notification settings - Fork 168
Refactor to use HTTP response reason phrases from response object #205
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
Conversation
This means we no longer have to maintain a list of HTTP reason phrases ourselves, but instead rely on those already present in our HTTP message abstraction.
| $body->seek(0, SEEK_END); | ||
| $body->write(': ' . $reason); | ||
| } | ||
|
|
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.
Any particular reason you don't construct $message as before?
$message = 'Error ' . $code;
$reason = $response->getReasonPhrase();
if ($reason !== '') {
$message .= ': ' . $reason
}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.
The $message is used only as a constructor parameter for the response body and the default reason phrase is only available after calling the constructor, hence this assignment.
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.
Oh yes, missed that 😊
| $reason = $response->getReasonPhrase(); | ||
| if ($reason !== '') { | ||
| $body = $response->getBody(); | ||
| $body->seek(0, SEEK_END); |
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.
Why does it need that seek?
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.
This makes sure it seeks to the end so that we append the reason phrase to the existing body.
This means we no longer have to maintain a list of HTTP reason phrases
ourselves, but instead rely on those already present in our HTTP message
abstraction.