MCPcopy
hub / github.com/aio-libs/aiohttp / handle_request

Method handle_request

aiohttp/web.py:63–111  ·  view source on GitHub ↗
(self, message, payload)

Source from the content-addressed store, hash-verified

61
62 @asyncio.coroutine
63 def handle_request(self, message, payload):
64 if self.access_log:
65 now = self._loop.time()
66
67 app = self._app
68 request = web_reqrep.Request(
69 app, message, payload,
70 self.transport, self.reader, self.writer,
71 secure_proxy_ssl_header=self._secure_proxy_ssl_header)
72 self._meth = request.method
73 self._path = request.path
74 try:
75 match_info = yield from self._router.resolve(request)
76
77 assert isinstance(match_info, AbstractMatchInfo), match_info
78
79 resp = None
80 request._match_info = match_info
81 expect = request.headers.get(hdrs.EXPECT)
82 if expect:
83 resp = (
84 yield from match_info.expect_handler(request))
85
86 if resp is None:
87 handler = match_info.handler
88 for factory in reversed(self._middlewares):
89 handler = yield from factory(app, handler)
90 resp = yield from handler(request)
91
92 assert isinstance(resp, web_reqrep.StreamResponse), \
93 ("Handler {!r} should return response instance, "
94 "got {!r} [middlewares {!r}]").format(
95 match_info.handler, type(resp), self._middlewares)
96 except web_exceptions.HTTPException as exc:
97 resp = exc
98
99 resp_msg = yield from resp.prepare(request)
100 yield from resp.write_eof()
101
102 # notify server about keep-alive
103 self.keep_alive(resp_msg.keep_alive())
104
105 # log access
106 if self.access_log:
107 self.log_access(message, None, resp_msg, self._loop.time() - now)
108
109 # for repr
110 self._meth = 'none'
111 self._path = 'none'
112
113
114class RequestHandlerFactory:

Calls 9

factoryFunction · 0.85
log_accessMethod · 0.80
handlerFunction · 0.50
resolveMethod · 0.45
getMethod · 0.45
expect_handlerMethod · 0.45
prepareMethod · 0.45
write_eofMethod · 0.45
keep_aliveMethod · 0.45