Trying to gzip compress response
This commit is contained in:
56
.vscode/settings.json
vendored
56
.vscode/settings.json
vendored
@@ -1,10 +1,56 @@
|
|||||||
{
|
{
|
||||||
|
"editor.formatOnSave": true,
|
||||||
|
"[python]": {
|
||||||
|
"editor.defaultFormatter": "charliermarsh.ruff",
|
||||||
|
"editor.codeActionsOnSave": {
|
||||||
|
"source.fixAll": "explicit",
|
||||||
|
"source.organizeImports": "explicit"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"[json]": {
|
||||||
|
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||||
|
},
|
||||||
|
"notebook.formatOnSave.enabled": true,
|
||||||
|
"notebook.codeActionsOnSave": {
|
||||||
|
// "notebook.source.fixAll": "explicit",
|
||||||
|
// "notebook.source.organizeImports": "explicit"
|
||||||
|
},
|
||||||
|
"notebook.output.wordWrap": true,
|
||||||
|
"notebook.output.textLineLimit": 200,
|
||||||
|
"jupyter.debugJustMyCode": false,
|
||||||
|
"python.testing.pytestEnabled": true,
|
||||||
"python.testing.pytestArgs": [
|
"python.testing.pytestArgs": [
|
||||||
"tests"
|
"tests"
|
||||||
],
|
],
|
||||||
"python.testing.unittestEnabled": false,
|
"files.exclude": {
|
||||||
"python.testing.pytestEnabled": true,
|
"**/*.egg-info": true,
|
||||||
"python.analysis.typeCheckingMode": "basic",
|
"**/htmlcov": true,
|
||||||
"python.terminal.activateEnvironment": true,
|
"**/~$*": true,
|
||||||
"python-envs.defaultEnvManager": "uv",
|
"**/.coverage.*": true,
|
||||||
|
"**/.venv": true,
|
||||||
|
"**/__pycache__": true,
|
||||||
|
"**/.mypy_cache": true,
|
||||||
|
"**/.pytest_cache": true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// .vscode/launch.json
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Python: Debug Tests",
|
||||||
|
"type": "debugpy",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${file}",
|
||||||
|
"purpose": [
|
||||||
|
"debug-test"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"justMyCode": false,
|
||||||
|
"env": {
|
||||||
|
"PYTEST_ADDOPTS": "--no-cov"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
@@ -9,13 +9,7 @@ from functools import partial
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
from fastapi import (
|
from fastapi import APIRouter, Depends, FastAPI, HTTPException, Request
|
||||||
APIRouter,
|
|
||||||
Depends,
|
|
||||||
FastAPI,
|
|
||||||
HTTPException,
|
|
||||||
Request,
|
|
||||||
)
|
|
||||||
from fastapi.middleware.cors import CORSMiddleware
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from fastapi.responses import HTMLResponse, Response
|
from fastapi.responses import HTMLResponse, Response
|
||||||
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
from fastapi.security import HTTPBasic, HTTPBasicCredentials
|
||||||
@@ -28,22 +22,12 @@ from .alpinebits_server import (
|
|||||||
AlpineBitsServer,
|
AlpineBitsServer,
|
||||||
Version,
|
Version,
|
||||||
)
|
)
|
||||||
from .auth import (
|
from .auth import generate_api_key, generate_unique_id, validate_api_key
|
||||||
generate_api_key,
|
|
||||||
generate_unique_id,
|
|
||||||
validate_api_key,
|
|
||||||
)
|
|
||||||
from .config_loader import load_config
|
from .config_loader import load_config
|
||||||
from .db import (
|
from .db import Base
|
||||||
Base,
|
from .db import Customer as DBCustomer
|
||||||
get_database_url,
|
from .db import Reservation as DBReservation
|
||||||
)
|
from .db import get_database_url
|
||||||
from .db import (
|
|
||||||
Customer as DBCustomer,
|
|
||||||
)
|
|
||||||
from .db import (
|
|
||||||
Reservation as DBReservation,
|
|
||||||
)
|
|
||||||
from .rate_limit import (
|
from .rate_limit import (
|
||||||
BURST_RATE_LIMIT,
|
BURST_RATE_LIMIT,
|
||||||
DEFAULT_RATE_LIMIT,
|
DEFAULT_RATE_LIMIT,
|
||||||
@@ -326,8 +310,7 @@ async def health_check(request: Request):
|
|||||||
|
|
||||||
# Extracted business logic for handling Wix form submissions
|
# Extracted business logic for handling Wix form submissions
|
||||||
async def process_wix_form_submission(request: Request, data: dict[str, Any], db):
|
async def process_wix_form_submission(request: Request, data: dict[str, Any], db):
|
||||||
"""Shared business logic for handling Wix form submissions (test and production).
|
"""Shared business logic for handling Wix form submissions (test and production)."""
|
||||||
"""
|
|
||||||
timestamp = datetime.now().isoformat()
|
timestamp = datetime.now().isoformat()
|
||||||
|
|
||||||
_LOGGER.info(f"Received Wix form data at {timestamp}")
|
_LOGGER.info(f"Received Wix form data at {timestamp}")
|
||||||
@@ -807,6 +790,11 @@ async def alpinebits_server_handshake(
|
|||||||
"X-AlpineBits-Server-Version": "2024-10",
|
"X-AlpineBits-Server-Version": "2024-10",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if is_compressed:
|
||||||
|
# Compress response if client sent compressed request
|
||||||
|
response_xml = gzip.compress(response_xml.encode("utf-8"))
|
||||||
|
headers["Content-Encoding"] = "gzip"
|
||||||
|
|
||||||
return Response(
|
return Response(
|
||||||
content=response_xml, status_code=response.status_code, headers=headers
|
content=response_xml, status_code=response.status_code, headers=headers
|
||||||
)
|
)
|
||||||
@@ -847,12 +835,9 @@ app.include_router(api_router)
|
|||||||
|
|
||||||
@app.get("/", response_class=HTMLResponse)
|
@app.get("/", response_class=HTMLResponse)
|
||||||
async def landing_page():
|
async def landing_page():
|
||||||
"""Serve the under construction landing page at the root route
|
"""Serve the under construction landing page at the root route."""
|
||||||
"""
|
|
||||||
try:
|
try:
|
||||||
# Get the path to the HTML file
|
# Get the path to the HTML file
|
||||||
import os
|
|
||||||
|
|
||||||
html_path = os.path.join(os.path.dirname(__file__), "templates", "index.html")
|
html_path = os.path.join(os.path.dirname(__file__), "templates", "index.html")
|
||||||
|
|
||||||
with open(html_path, encoding="utf-8") as f:
|
with open(html_path, encoding="utf-8") as f:
|
||||||
|
|||||||
Reference in New Issue
Block a user