ЛР3: балансировка, отказоустойчивость и идемпотентность
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
import socket
|
||||
from uuid import uuid4
|
||||
|
||||
from starlette.datastructures import MutableHeaders
|
||||
@@ -11,6 +13,7 @@ logger = logging.getLogger('app')
|
||||
class RequestContext:
|
||||
def __init__(self, app) -> None:
|
||||
self.app = app
|
||||
self.instance_id = os.getenv('INSTANCE_ID') or socket.gethostname()
|
||||
|
||||
async def __call__(self, scope, receive, send) -> None:
|
||||
if scope['type'] != 'http':
|
||||
@@ -25,7 +28,9 @@ class RequestContext:
|
||||
nonlocal started
|
||||
if message['type'] == 'http.response.start':
|
||||
started = True
|
||||
MutableHeaders(scope=message)['X-Request-Id'] = request_id
|
||||
headers = MutableHeaders(scope=message)
|
||||
headers['X-Request-Id'] = request_id
|
||||
headers['X-Instance-Id'] = self.instance_id
|
||||
await send(message)
|
||||
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user