mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-12 18:19:34 +00:00
Small changes in webhook handler.
This commit is contained in:
parent
68e016ecab
commit
ff2b7f9682
1 changed files with 19 additions and 5 deletions
|
|
@ -109,11 +109,7 @@ class WebhookRequestHandler(web.View):
|
|||
|
||||
:return: :class:`aiohttp.web.Response`
|
||||
"""
|
||||
if self.request.app.get('_check_ip', False):
|
||||
ip_address, accept = self.check_ip()
|
||||
if not accept:
|
||||
raise web.HTTPUnauthorized()
|
||||
context.set_value('TELEGRAM_IP', ip_address)
|
||||
self.validate_ip()
|
||||
|
||||
context.update_state({'CALLER': WEBHOOK,
|
||||
WEBHOOK_CONNECTION: True,
|
||||
|
|
@ -129,6 +125,14 @@ class WebhookRequestHandler(web.View):
|
|||
return response.get_web_response()
|
||||
return web.Response(text='ok')
|
||||
|
||||
async def get(self):
|
||||
self.validate_ip()
|
||||
return web.Response(text='')
|
||||
|
||||
async def head(self):
|
||||
self.validate_ip()
|
||||
return web.Response(text='')
|
||||
|
||||
async def process_update(self, update):
|
||||
"""
|
||||
Need respond in less than 60 seconds in to webhook.
|
||||
|
|
@ -220,6 +224,16 @@ class WebhookRequestHandler(web.View):
|
|||
# Not allowed and can't get client IP
|
||||
return None, False
|
||||
|
||||
def validate_ip(self):
|
||||
"""
|
||||
Check ip if that is needed. Raise web.HTTPUnauthorized for not allowed hosts.
|
||||
"""
|
||||
if self.request.app.get('_check_ip', False):
|
||||
ip_address, accept = self.check_ip()
|
||||
if not accept:
|
||||
raise web.HTTPUnauthorized()
|
||||
context.set_value('TELEGRAM_IP', ip_address)
|
||||
|
||||
|
||||
def configure_app(dispatcher, app: web.Application, path=DEFAULT_WEB_PATH):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue