Browse Source

next 2

master
gsd 4 weeks ago
parent
commit
c8eb5a4580
  1. 12
      server.py

12
server.py

@ -15,7 +15,7 @@ class Collector:
def __init__(self) -> None: def __init__(self) -> None:
self.secrets = os.getenv("KEYS", "secret").split(",") self.secrets = os.getenv("KEYS", "secret").split(",")
self.hosts = os.getenv("HOSTS", "srv").split(",") self.hosts = os.getenv("HOSTS", "srv").split(",")
self.dead_after = int(os.getenv("DEAD_AFTER", "60")) self.dead_after = int(os.getenv("DEAD_AFTER", "90"))
self.build_routes() self.build_routes()
def check_headers(self, request: Request): def check_headers(self, request: Request):
@ -55,7 +55,10 @@ class Collector:
host = host.split(":")[0] host = host.split(":")[0]
if host in self.store and self.store[host]['data']: if host in self.store and self.store[host]['data']:
return Response(content=self.store[host]['data'], status_code=200) return Response(
content=self.store[host]['data'],
status_code=200,
headers=self.store[host]['headers'])
else: else:
return Response(status_code=404) return Response(status_code=404)
@ -70,8 +73,11 @@ class Collector:
self.store[host] = { self.store[host] = {
"data":await request.body(), "data":await request.body(),
"timestamp": time() "timestamp": time(),
"headers": {
"Content-Type": "text/plain; version=0.0.4; charset=utf-8; escaping=underscores"
} }
}
background_tasks.add_task(self.deadline, host) background_tasks.add_task(self.deadline, host)
return Response(status_code=200) return Response(status_code=200)

Loading…
Cancel
Save