Skip to content
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

support aiohttp-3.8.0 #31

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions aiodogstatsd/contrib/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
from typing import AsyncIterator, Callable, Optional, cast

from aiohttp import web
from aiohttp.web_app import _Middleware
from aiohttp.web_routedef import _SimpleHandler
try:
from aiohttp.typedefs import Middleware
except ImportError:
# aiohttp < 3.8.0
from aiohttp.web_app import _Middleware as Middleware
try:
from aiohttp.typedefs import Handler
except ImportError:
# aiohttp < 3.8.0
from aiohttp.web_routedef import _SimpleHandler as Handler
from aiohttp.web_urldispatcher import DynamicResource, MatchInfoError

from aiodogstatsd import Client, typedefs
Expand Down Expand Up @@ -55,10 +63,10 @@ def middleware_factory(
request_duration_metric_name: str = DEAFULT_REQUEST_DURATION_METRIC_NAME,
collect_not_allowed: bool = False,
collect_not_found: bool = False,
) -> _Middleware:
) -> Middleware:
@web.middleware
async def middleware(
request: web.Request, handler: _SimpleHandler
request: web.Request, handler: Handler
) -> web.StreamResponse:
loop = get_event_loop()
request_started_at = loop.time()
Expand Down