Git Product home page Git Product logo

playpauseandstop / aiohttp-middlewares Goto Github PK

View Code? Open in Web Editor NEW
50.0 50.0 6.0 643 KB

Collection of useful middlewares for aiohttp.web applications.

Home Page: http://aiohttp-middlewares.readthedocs.io

License: BSD 3-Clause "New" or "Revised" License

Makefile 6.58% Python 92.42% Shell 1.00%
aiohttp aiohttp-server middlewares python python-3 python-3-6 python-3-7 python-3-8 python-library

aiohttp-middlewares's Introduction

Hm...

Not sure what to write here...

aiohttp-middlewares's People

Contributors

badabump-release-bot[bot] avatar dependabot[bot] avatar greut avatar kunkku avatar mprasil avatar oleksandr-kuzmenko avatar playpauseandstop avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aiohttp-middlewares's Issues

Fix deprecation warning in `timeout` middleware

Deprecation warning reported from timeout middleware,

  .venv/lib/python3.10/site-packages/aiohttp_middlewares/timeout.py:141: DeprecationWarning: with timeout() is deprecated, use async with timeout() instead
    with timeout(seconds):

Need to change with context manager to async with and update lower-bound for async-timeout dependency to fix this deprecation warning.

[Discussion] Error handling middleware expansion opportunity?

Hey @playpauseandstop, first off, I dig this project very much just by browsing the code and the docs - great work.

While I never tried using your library, I've stumbled upon it on aiohttp's third-party libraries list and it caught my attention. A few months ago, I started putting together a library I titled aiohttp-catcher, which fulfills a very similar purpose aiohttp-middlewares's error_middleware does. aiohttp-catcher does it a bit differently, but the general idea is similar and I trust its repo's README file is useful in understanding how it works. Alas, the library never took off as I haven't really advertised it too ambitiously and I've only been using it in a few apps I run for non-commercial purposes.

My question is this: would you be interested in joining forces and work together on porting some of the logic of aiohttp-catcher into aiohttp-middlewares's error_middleware? I'm more than willing to do the heavy lifting myself. That is, if the architecture of aiohttp-catcher makes sense to you. Happy to start a discussion one way or another.

P.S.,
I couldn't help but notice your location - I hope that you and your close ones are safe πŸ‡ΊπŸ‡¦ ❀️

Return empty response body for CORS preflight requests

It was designed to return an empty response body for CORS preflight requests, but unfortunately aiohttp decided to return non-empty response body for web.HTTPOk exception.

Need to fix it, as returning non-empty response body data doesn't have sense for CORS preflight requests.

CORS Preflight Request

Screen Shot 2019-07-23 at 5 46 59 PM

CORS Preflight Response

Screen Shot 2019-07-23 at 5 47 18 PM

Allow ignoring list of exceptions in error middleware

There should be a necessity of ignoring some specific exceptions in error middleware.

For example, when aiohttp.web application provides ton of web.HTTPNotFound errors it might be OK to ignore them altogether from handling via error handler.

Similarly, when web.HTTPBadRequest or web.HTTPForbidden errors happened, it might be OK to not pass them to error handler and as result do not log given errors to Sentry or anywhere else.

Ensure Python 3.9 support

Need to move dev Python version to 3.9 and ensure that everything work as expected after the update.

When done, need to release new minor version.

Provide default error handler

As aiohttp.web applications designed to be API backend apps it is OK to provide default error handler, which can be used out-of-box with error_middleware.

The default error handler should be as tiny as,

import logging

from aiohttp import web
from aiohttp_middlewares import error_context


logger = logging.getLogger(__name__)


async def error(request: web.Request) -> web.Response:
    with error_context(request) as context:
        logger.error(context.message, exc_info=True)
        return web.json_response(context.data, status=context.status)

Also given default error handler should be enabled by default, so setting up error middleware will not require passing default_handler anymore.

Documentation should respect given changes as well.

`token_auth_middleware` even though the token is right, returns 403

The token_auth_middleware is not working as intended within Plover's websocket plugin of https://github.com/CosmicDNA/plover_websocket_server.git@benchmark-01.

To compare the difference in behaviour I have set a canonical implementation at https://github.com/CosmicDNA/tam-canonical-example where it does work as expected.

Now, when ran as a Plover plugin, the following result is seen in the browser after you have just followed the Plover Plugin Test Script:

image

Ensure project installed well at Windows & macOS ARM runners

It's been awhile since initial "Verify package is installed well" job been introduced to ci.yml, at that point of time WIndows runner support was broken for poetry and Mac M1/M2/M3 (ARM) was not a thing.

Need to update runners to use within that job to ensure that project installed well at Windows & macOS ARM runner.

Support yarl.URL everywhere

Make sure that passing yarl.URL instances into any middleware config works well.

For example,

from aiohttp import web
from aiohttp_middlewares import cors_middleware, error_middleware
from yarl import URL

from . import api_views, views


app = web.Application(
    middlewares=(
        cors_middleware(origins=(URL("http://localhost:8081"),)),
        error_middleware(
            default_handler=views.error, 
            config={URL("/api"): api_views.error}
        ),
    ),
)

Should work same ways as it works without wrapping,

  • "http://localhost:8081"
  • "/api"

into URL instance.

Upgrade aiohttp to 3.9.0, aiohttp-middlewares has errors

Hi,

While upgrading aiohttp to 3.9.0, aiohttp-middlewares has errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/local/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/execute_web_agent/web_agent/main.py", line 9, in <module>
    from aiohttp_middlewares import cors_middleware
  File "/usr/local/lib/python3.10/site-packages/aiohttp_middlewares/__init__.py", line 14, in <module>
    from aiohttp_middlewares.cors import cors_middleware
  File "/usr/local/lib/python3.10/site-packages/aiohttp_middlewares/cors.py", line 122, in <module>
    from aiohttp_middlewares.annotations import (
  File "/usr/local/lib/python3.10/site-packages/aiohttp_middlewares/annotations.py", line 22, in <module>
    from aiohttp.web_middlewares import _Middleware as Middleware
ImportError: cannot import name '_Middleware' from 'aiohttp.web_middlewares' (/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py)

It seems aiohttp removes _Middleware.
https://github.com/aio-libs/aiohttp/blob/master/aiohttp/web_middlewares.py

Dependabot can't resolve your Python dependency files

Dependabot can't resolve your Python dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Could not find a version that matches CHANGELOG.rst (from -r MANIFEST.in (line 1))
No versions found
Was <redacted> reachable?

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.