Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-09 10:47:39

0001 """Browser-tab identity for local and proxied devcloud HTML pages."""
0002 import re
0003 
0004 
0005 FAVICON_LINKS = (
0006     b'<link rel="icon" type="image/svg+xml" href="/favicon.svg?v=epic-red-e-1">\n'
0007     b'<link rel="alternate icon" href="/favicon.ico?v=epic-red-e-1">\n'
0008 )
0009 HEAD_END = re.compile(rb'</head\s*>', re.IGNORECASE)
0010 
0011 
0012 class DevcloudBrandingMiddleware:
0013     """Give locally rendered and tunnel-proxied pages the same favicon."""
0014 
0015     def __init__(self, get_response):
0016         self.get_response = get_response
0017 
0018     def __call__(self, request):
0019         response = self.get_response(request)
0020         if (response.streaming or
0021                 not response.get('Content-Type', '').lower().startswith('text/html') or
0022                 'attachment' in response.get('Content-Disposition', '').lower()):
0023             return response
0024         body = response.content
0025         if b'epic-red-e-1' not in body:
0026             body, changed = HEAD_END.subn(lambda m: FAVICON_LINKS + m.group(0), body, count=1)
0027             if changed:
0028                 response.content = body
0029                 if response.has_header('Content-Length'):
0030                     response['Content-Length'] = str(len(body))
0031         return response