Skip to content

Commit

Permalink
Merge d1a727c into 5b72441
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Jan 25, 2016
2 parents 5b72441 + d1a727c commit 53f10df
Show file tree
Hide file tree
Showing 8 changed files with 736 additions and 144 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ CHANGES

- Enable access log by default #735

- Deprecate app.router.register_route() (the method was not documented
intentionally BTW).

- Deprecate app.router.named_routes() in favor of app.router.named_resources()

- route.add_static accepts pathlib.Path now #743

- Add command line support: `$ python -m aiohttp.web package.main` #740
Expand Down
4 changes: 2 additions & 2 deletions aiohttp/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def handler(self):

@property # pragma: no branch
@abstractmethod
def route(self):
"""Return route for match info"""
def expect_handler(self):
"""Expect handler for 100-continue processing"""


class AbstractView(metaclass=ABCMeta):
Expand Down
60 changes: 26 additions & 34 deletions aiohttp/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class RequestHandler(ServerHttpProtocol):

_meth = 'none'
_path = 'none'
_request = None

def __init__(self, manager, app, router, *,
secure_proxy_ssl_header=None, **kwargs):
Expand All @@ -59,8 +58,6 @@ def connection_lost(self, exc):
self._manager.connection_lost(self, exc)

super().connection_lost(exc)
if self._request is not None:
pass

@asyncio.coroutine
def handle_request(self, message, payload):
Expand All @@ -72,40 +69,35 @@ def handle_request(self, message, payload):
app, message, payload,
self.transport, self.reader, self.writer,
secure_proxy_ssl_header=self._secure_proxy_ssl_header)
self._request = request
self._meth = request.method
self._path = request.path
try:
try:
match_info = yield from self._router.resolve(request)

assert isinstance(match_info, AbstractMatchInfo), match_info

resp = None
request._match_info = match_info
expect = request.headers.get(hdrs.EXPECT)
if expect and expect.lower() == "100-continue":
resp = (
yield from match_info.route.handle_expect_header(
request))

if resp is None:
handler = match_info.handler
for factory in reversed(self._middlewares):
handler = yield from factory(app, handler)
resp = yield from handler(request)

assert isinstance(resp, StreamResponse), \
("Handler {!r} should return response instance, "
"got {!r} [middlewares {!r}]").format(
match_info.handler, type(resp), self._middlewares)
except HTTPException as exc:
resp = exc

resp_msg = yield from resp.prepare(request)
yield from resp.write_eof()
finally:
self._request = None
match_info = yield from self._router.resolve(request)

assert isinstance(match_info, AbstractMatchInfo), match_info

resp = None
request._match_info = match_info
expect = request.headers.get(hdrs.EXPECT)
if expect and expect.lower() == "100-continue":
resp = (
yield from match_info.expect_handler(request))

if resp is None:
handler = match_info.handler
for factory in reversed(self._middlewares):
handler = yield from factory(app, handler)
resp = yield from handler(request)

assert isinstance(resp, StreamResponse), \
("Handler {!r} should return response instance, "
"got {!r} [middlewares {!r}]").format(
match_info.handler, type(resp), self._middlewares)
except HTTPException as exc:
resp = exc

resp_msg = yield from resp.prepare(request)
yield from resp.write_eof()

# notify server about keep-alive
self.keep_alive(resp_msg.keep_alive())
Expand Down
Loading

0 comments on commit 53f10df

Please sign in to comment.