Last active
January 12, 2024 21:30
-
-
Save drizzt/0a9e409e7cc6cb7cb6f0b113800ecf9c to your computer and use it in GitHub Desktop.
Revisions
-
drizzt revised this gist
Jan 12, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -40,6 +40,6 @@ async def topic(request): app = Starlette( debug=True, routes=[ Route("/{path:path}", topic, methods=["POST"]), ], ) -
drizzt revised this gist
Jan 12, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ async def topic(request): pubKey = request.headers.get("crypto-key").encode() salt = request.headers.get("encryption").encode() body = b"aesgcm\nEncryption: " + salt + b"\nCrypto-Key: " + pubKey + b"\n" + await request.body() headers = dict(request.headers) del headers["content-encoding"] -
drizzt created this gist
Dec 11, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ #!/usr/bin/python3 from starlette.applications import Starlette from starlette.responses import Response from starlette.routing import Route import httpx async def topic(request): host = request.headers.get("host") path = request.path_params["path"] target_url = f"https://{host}/{path}" pubKey = request.headers.get("crypto-key").encode() salt = request.headers.get("encryption").encode() body = await request.body() + b"\n" + pubKey + b"\n" + salt + b"\naesgcm" headers = dict(request.headers) del headers["content-encoding"] del headers["content-length"] # Forward the request to the target URL async with httpx.AsyncClient() as client: upstream_response = await client.request( method=request.method, url=target_url, headers=headers, data=body, params=request.query_params, ) return Response( content=upstream_response.content, status_code=upstream_response.status_code ) app = Starlette( debug=True, routes=[ Route("/{path:path}", topic, methods=["GET", "POST", "PUT"]), ], ) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ map $http_content_encoding $ntfy_backend { "aesgcm" "127.0.0.1:8000"; default "127.0.0.1:2586"; } server { listen 80; listen [::]:80; server_name YOURDOMAIN; location /generic { proxy_pass http://127.0.0.1:5000; } location / { add_header alt-svc 'h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400, h3=":443"; ma=86400'; proxy_pass http://$ntfy_backend; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 3m; proxy_send_timeout 3m; proxy_read_timeout 3m; client_max_body_size 0; # Stream request body to backend } }