19 |
19 |
20 import sys |
20 import sys |
21 import traceback |
21 import traceback |
22 import threading |
22 import threading |
23 from cgi import FieldStorage, parse_header |
23 from cgi import FieldStorage, parse_header |
|
24 from functools import partial |
24 |
25 |
25 from cubicweb.statsd_logger import statsd_timeit |
26 from cubicweb.statsd_logger import statsd_timeit |
26 |
27 |
27 from twisted.internet import reactor, task, threads |
28 from twisted.internet import reactor, task, threads |
28 from twisted.web import http, server |
29 from twisted.web import http, server |
87 |
88 |
88 def getChild(self, path, request): |
89 def getChild(self, path, request): |
89 """Indicate which resource to use to process down the URL's path""" |
90 """Indicate which resource to use to process down the URL's path""" |
90 return self |
91 return self |
91 |
92 |
|
93 def on_request_finished_ko(self, request, reason): |
|
94 # annotate the twisted request so that we're able later to check for |
|
95 # failure without having to dig into request's internal attributes such |
|
96 # as _disconnected |
|
97 request.cw_failed = True |
|
98 self.warning('request finished abnormally: %s', reason) |
|
99 |
92 def render(self, request): |
100 def render(self, request): |
93 """Render a page from the root resource""" |
101 """Render a page from the root resource""" |
|
102 finish_deferred = request.notifyFinish() |
|
103 finish_deferred.addErrback(partial(self.on_request_finished_ko, request)) |
94 # reload modified files in debug mode |
104 # reload modified files in debug mode |
95 if self.config.debugmode: |
105 if self.config.debugmode: |
96 self.config.uiprops.reload_if_needed() |
106 self.config.uiprops.reload_if_needed() |
97 if self.https_url: |
107 if self.https_url: |
98 self.config.https_uiprops.reload_if_needed() |
108 self.config.https_uiprops.reload_if_needed() |