Remove nevow from allmydata.web.root.IncidentReporter

This change calls for an explanation:

- `RenderMixin` doesn't seem to be adding anything here, so it is
   gone.

- The web browser was unhappy without a charset in the response
  (Firefox 74 was anyway), so `content-type` header also gets a
  `charset=UTF-8`.

- Returning a Unicode string made nevow appserver unhappy, so it is
  just a `str`.  The precise error message was:

  exceptions.TypeError: ('Could not adapt', u'An incident report has been saved to logs/incidents/ in the node directory.', <InterfaceClass nevow.inevow.IResource>)

Fixes: ticket:3294
This commit is contained in:
Sajith Sasidharan 2020-04-09 15:09:58 -04:00
parent 34e85ac515
commit a14cee5cce
2 changed files with 7 additions and 6 deletions

0
newsfragments/3294.minor Normal file
View File

View File

@ -28,7 +28,7 @@ from allmydata.web.common import (
WebError,
get_arg,
MultiFormatPage,
RenderMixin,
MultiFormatResource,
get_format,
get_mutable_type,
render_time_delta,
@ -169,14 +169,15 @@ class FileHandler(rend.Page):
raise WebError("/file must be followed by a file-cap and a name",
http.NOT_FOUND)
class IncidentReporter(RenderMixin, rend.Page):
def render_POST(self, ctx):
req = IRequest(ctx)
class IncidentReporter(MultiFormatResource):
"""Handler for /report_incident POST request"""
def render(self, req):
log.msg(format="User reports incident through web page: %(details)s",
details=get_arg(req, "details", ""),
level=log.WEIRD, umid="LkD9Pw")
req.setHeader("content-type", "text/plain")
return "An incident report has been saved to logs/incidents/ in the node directory."
req.setHeader("content-type", "text/plain; charset=UTF-8")
return b"An incident report has been saved to logs/incidents/ in the node directory."
SPACE = u"\u00A0"*2