Skip to content

Commit

Permalink
Merge pull request #1301 from zauberzeug/on_air_instance_picking
Browse files Browse the repository at this point in the history
Picking the right "On Air"-instance
  • Loading branch information
falkoschindler authored Aug 1, 2023
2 parents 323b43f + dbbe14d commit f34fd4d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions nicegui/air.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio
import gzip
import logging
import re
from typing import Any, Dict

import httpx
Expand Down Expand Up @@ -33,10 +33,15 @@ async def on_http(data: Dict[str, Any]) -> Dict[str, Any]:
content=data['body'],
)
response = await self.client.send(request)
instance_id = data['instance-id']
content = response.content.replace(
b'const extraHeaders = {};',
(f'const extraHeaders = {{ "fly-force-instance-id" : "{data["instance-id"]}" }};').encode(),
(f'const extraHeaders = {{ "fly-force-instance-id" : "{instance_id}" }};').encode(),
)
match = re.search(b'const query = ({.*?})', content)
if match:
new_js_object = match.group(1).decode().rstrip('}') + ", 'fly_instance_id' : '" + instance_id + "'}"
content = content.replace(match.group(0), f'const query = {new_js_object}'.encode())
response_headers = dict(response.headers)
response_headers['content-encoding'] = 'gzip'
compressed = gzip.compress(content)
Expand Down

0 comments on commit f34fd4d

Please sign in to comment.