-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
allow HEAD requests to default routes #1618
Comments
bump, any news one this? I think it's important and requires a fix. |
i am not entirely sure what you are proposing? |
I'm proposing a new method Then change in documentation to encourage people to use that method instead of |
Perhaps easiest if I do a pull request then you can comment on that. |
Shouldn't allow GET also allow HEAD? |
yes it should, but I do understand why it's confusing if I'm easy, could just modify |
i think i'm missing something. you can do |
app.router.add_get('/', index, name='index')
app.router.add_route('HEAD', '/', index) Is a pretty ugly preferred way of adding a standard endpoint. |
we can do something like |
makes sense, for me Perhaps have |
Sounds good for me, just only may be |
|
It follows the same naming policy as HTTP has: you |
but this would look strange:
|
maybe |
The What if instead of:
Have:
A bit out of rules, but since GET and HEAD are heavy bounded, could this be legal? |
i like |
Brrr...ignore my last post. Case 1: we're fine to handle HEAD requests with GET handler.
Case 2: we need to disallow HEAD requests for GET endpoints
Case 3: we want to have custom HEAD handler at the same endpoint
E.g. you don't need to explicitly disable default HEAD handler or care about if you define own a bit later. API remains consistent and clear without mandatory flags or additional handlers. |
Ah, one more: Case 4: I don't know what I want to have
(: Yes, you, probably, can write something like that, but why? (not a rhetorical question) |
but i like head_handler, |
I don't understand what That sounds wrong, HEAD requests should be processed by the same handler as get so the response code and headers are the same as GET. |
@samuelcolvin |
ok, it seems it is about flag only. |
then |
I think just Perhaps |
technically |
True, but it's very rare to initialise UrlDispatcher directly, either an Application kwarg or a method: app.router.set_default(allow_head=True)
app.router.add_get('/', index) # this will allow head requests I can imagine there might be other default behaviour to configure on |
@asvetlov do you have ideas about |
@samuelcolvin would you like to work on this feature? |
yes will do. |
cool, thanks. |
Just checked and both flask and django by default allow
HEAD
requests (but notPOST
,PUT
etc.) to the default routed endpoints.The closest equivalent in aiohttp is
add_get
but understandably that doesn't allowHEAD
requests and returns 405.aiohttp should add a method to add routes which accept the "noop" or safe http methods eg.
GET
,HEAD
andOPTIONS
.To be consistent with other servers and act in the spirit of http, this method should be the default. AFAIK returning 405 to
HEAD
requests toGET
endpoints is wrong.I'm trying to think about the best name for such a method which is both clear and not verbose, it's not obvious. Wikipedia calls these "safe methods" but
add_safe
could be a confusing; making people think aiohttp is giving some kind of protection which it isn't.Perhaps the simplest options would be just
add
.So code would be
What exactly it should do with
OPTIONS
requests is debatable. The fact it should gracefully acceptHEAD
requests is a no-brainer for me.The text was updated successfully, but these errors were encountered: