Comments (13)
@trivigy thank you for posting this bug report and sorry for the long delay.
Yes, as I see *
handler from class based view's (CBV) takes precedence over OPTIONS
handler being added by aiohttp-cors, and I don't see easy way to handle CBV classes in aiohttp-cors so currently it will not work with them.
Perhaps best solution will be to introduce aiohttp-cors mixin for CBV which will handle OPTIONS
and require users to inherit from it, like:
# Not implemented yet
from aiohttp_cors import ViewMixin
class MyView(ViewMixin, web.View):
async def get(self):
return await get_resp(self.request)
async def post(self):
return await post_resp(self.request)
from aiohttp-cors.
Makes sense
from aiohttp-cors.
I am using the following workaround to register my classes so that they work with aiohttp_cors:
def register_view(app, url, view):
for method in ('get', 'post', 'delete', 'put'):
handler = getattr(view, method, None)
if not handler:
continue
app.router.add_route(method, url, handler)
from aiohttp-cors.
@balloob will aiohttp_cors.ViewMixin
mixin will help you if it will be implemented in aiohttp_cors
?
from aiohttp-cors.
Probably - but I was already using views in a weird way: I wanted to instantiate the views before registering them so I could keep a reference to the state of the house (I'm working on Home Assistant). So I actually had a __call__
method on my instantiated view that would handle the routing to get/post etc. (I know that it's not the right way but we're transitioning from CherryPi WSGI server + Werkzeug and getting it to work is the first step.)
from aiohttp-cors.
@balloob if you want to instantiate your view classes before registering you don't need aiohttp.web.View
at all -- custom classes may serve everything perfectly.
from aiohttp-cors.
@rutsky Thanks for the suggestion. Took me a long time to notice that you responded. I actually use a very custom implementation of the View within our system. I personally wanted to add a whole lot more functionalities to the view and therefore re-implemented it. Had to override add_route() functions and all. Therefore this problem was never an issue for my systems but it was certainly a bug worth reporting.
from aiohttp-cors.
@balloob's hack works ok for me as well, but I think a ViewMixin would be better.
from aiohttp-cors.
Guys, we need a champion for the issue.
Do anybody want work on PR?
from aiohttp-cors.
I recently changed job, moved to another country and on paternity leave right now, so I don't have free time right now, sorry.
from aiohttp-cors.
@asvetlov @rutsky would you please review my PR?
from aiohttp-cors.
Let me setup coverage tools first, I'll return to review after that.
from aiohttp-cors.
👍 💯
from aiohttp-cors.
Related Issues (20)
- Wildcard ports for localhost HOT 5
- method '*' treated differently from others HOT 9
- What is the best way to grant CORS for all subdomains dynamically? HOT 6
- Cors and IOS Safari HOT 3
- Only 1 is allowed HOT 1
- thx for password and key to pypi HOT 1
- Python 3.8 test_static_resource failure: TypeError: issubclass() arg 1 must be a class
- DeprecationWarnings with Python 3.8: "@coroutine" decorator
- cant import aiohttp_cors HOT 1
- python3.7 HOT 3
- Does this project follow semver? HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Routing hierarchy confusion with CORs
- Should aiohttp-cors add a Vary: Origin when emitting a access-control-allow-origin? HOT 1
- 0.7.0 + master: pytest is failing HOT 2
- Is it possible to return `Access-Control-Allow-Origin: *` in response to preflight request instead of existing `Origin` header?
- Regex domains
- Lets through Postman / Curl requests HOT 2
- Let's put `aiohttp-cors` under the `aio-libs` org on PyPI
- How can I enforce CORS despite middlewares?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aiohttp-cors.