mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 18:57:06 +00:00
Remove fingerprint middleware (#20682)
* Remove fingerprint middleware * Lint
This commit is contained in:
parent
384a9625c9
commit
47f60e6cf2
@ -25,8 +25,7 @@ from .auth import setup_auth
|
||||
from .ban import setup_bans
|
||||
from .cors import setup_cors
|
||||
from .real_ip import setup_real_ip
|
||||
from .static import (
|
||||
CachingFileResponse, CachingStaticResource, staticresource_middleware)
|
||||
from .static import CachingFileResponse, CachingStaticResource
|
||||
|
||||
# Import as alias
|
||||
from .const import KEY_AUTHENTICATED, KEY_REAL_IP # noqa
|
||||
@ -192,8 +191,7 @@ class HomeAssistantHTTP:
|
||||
use_x_forwarded_for, trusted_proxies, trusted_networks,
|
||||
login_threshold, is_ban_enabled, ssl_profile):
|
||||
"""Initialize the HTTP Home Assistant server."""
|
||||
app = self.app = web.Application(
|
||||
middlewares=[staticresource_middleware])
|
||||
app = self.app = web.Application(middlewares=[])
|
||||
|
||||
# This order matters
|
||||
setup_real_ip(app, use_x_forwarded_for, trusted_proxies)
|
||||
|
@ -1,15 +1,10 @@
|
||||
"""Static file handling for HTTP component."""
|
||||
|
||||
import re
|
||||
|
||||
from aiohttp import hdrs
|
||||
from aiohttp.web import FileResponse, middleware
|
||||
from aiohttp.web import FileResponse
|
||||
from aiohttp.web_exceptions import HTTPNotFound
|
||||
from aiohttp.web_urldispatcher import StaticResource
|
||||
from yarl import URL
|
||||
|
||||
_FINGERPRINT = re.compile(r'^(.+)-[a-z0-9]{32}\.(\w+)$', re.IGNORECASE)
|
||||
|
||||
|
||||
class CachingStaticResource(StaticResource):
|
||||
"""Static Resource handler that will add cache headers."""
|
||||
@ -56,19 +51,3 @@ class CachingFileResponse(FileResponse):
|
||||
|
||||
# Overwriting like this because __init__ can change implementation.
|
||||
self._sendfile = sendfile
|
||||
|
||||
|
||||
@middleware
|
||||
async def staticresource_middleware(request, handler):
|
||||
"""Middleware to strip out fingerprint from fingerprinted assets."""
|
||||
path = request.path
|
||||
if not path.startswith('/static/') and not path.startswith('/frontend'):
|
||||
return await handler(request)
|
||||
|
||||
fingerprinted = _FINGERPRINT.match(request.match_info['filename'])
|
||||
|
||||
if fingerprinted:
|
||||
request.match_info['filename'] = \
|
||||
'{}.{}'.format(*fingerprinted.groups())
|
||||
|
||||
return await handler(request)
|
||||
|
Loading…
x
Reference in New Issue
Block a user