-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
plain text http responses to errors #3483
Conversation
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.
LGTM!
Maybe we should change the content-type to Doesn't make sense for this to be html I would guess. |
Agree, makes sense. |
Should all be changed as per requests. |
aiohttp/web_protocol.py
Outdated
msg = "<h1>500 Internal Server Error</h1>" | ||
ct = 'text/plain' | ||
if status == HTTPStatus.INTERNAL_SERVER_ERROR: | ||
title = '500 Internal Server Error' |
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.
title = '500 Internal Server Error' | |
title = ' '.join((str(HTTPStatus.INTERNAL_SERVER_ERROR.value), HTTPStatus.INTERNAL_SERVER_ERROR.phrase)) |
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.
In [1]: import http
In [3]: http.HTTPStatus.INTERNAL_SERVER_ERROR
Out[3]: <HTTPStatus.INTERNAL_SERVER_ERROR: 500>
In [5]: http.HTTPStatus.INTERNAL_SERVER_ERROR.phrase
Out[5]: 'Internal Server Error'
In [6]: http.HTTPStatus.INTERNAL_SERVER_ERROR.value
Out[6]: 500
In [8]: http.HTTPStatus.INTERNAL_SERVER_ERROR.description
Out[8]: 'Server got itself in trouble'
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.
@webknjaz honestly the original (a plain string) looks more readable for me.
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.
But I can live with any variant, too negligeable reason for contestion.
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.
Agreed. I'd probably go for
title = '500 Internal Server Error' | |
title = str(HTTPStatus.INTERNAL_SERVER_ERROR.value) + ' ' + HTTPStatus.INTERNAL_SERVER_ERROR.phrase |
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.
would it be better readable?
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.
I'm a bit surprised that http.HTTPStatus
doesn't have a method to construct a status string. IMHO it should be smth like title = http.HTTPStatus.INTERNAL_SERVER_ERROR.to_status_string()
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.
HTTP reason is gone in htttp/2 BTW.
I suspect that very many Web frameworks have own copies of these constants.
+0 for adding to_status_string()
to CPython, at least I don't want to make a Pull Request (but you can count me on the PR review).
Co-Authored-By: samuelcolvin <samcolvin@gmail.com>
I've left my laptop at work so will fix on Monday. |
Should now be fixed. I've gone back on @webknjaz previous request and removed Having thought about this "Server got itself in trouble" is a completely meaningless sentence designed as something to say when we have no information; it adds no further information to casual users or application developers. If we're showing the traceback it is unnecessary and only makes the output more verbose and harder to read. This maintains the previous behaviour. I hope this is ok. |
Codecov Report
@@ Coverage Diff @@
## master #3483 +/- ##
==========================================
+ Coverage 97.92% 97.93% +<.01%
==========================================
Files 44 44
Lines 8567 8560 -7
Branches 1383 1380 -3
==========================================
- Hits 8389 8383 -6
+ Misses 74 72 -2
- Partials 104 105 +1
Continue to review full report at Codecov.
|
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.
LGTM
I think this can also be backported |
ok, do we have an automated way of doing this or should I create a pull request against |
There's cherry-picker, which you can use manually. No bot doing it currently. |
Thanks! |
(cherry picked from commit b42a23b) Co-authored-by: Samuel Colvin <samcolvin@gmail.com>
Backport PR: #3499 |
What do these changes do?
When using curl or httpie, error responses should not be html.
Are there changes in behavior for the user?
Yes, errors should be plain text not html when
text/html
is not in the "browsers"Accept
header.Currently this is failing due to an existing error which I inadvertently uncovered. I'll comment on the code below. I'll add
CHANGES
etc. once this is fixed.Checklist
CONTRIBUTORS.txt
CHANGES
folder<issue_id>.<type>
for example (588.bugfix)issue_id
change it to the pr id after creating the pr.feature
: Signifying a new feature..bugfix
: Signifying a bug fix..doc
: Signifying a documentation improvement..removal
: Signifying a deprecation or removal of public API..misc
: A ticket has been closed, but it is not of interest to users.