def wrapped_app(req): resp = app(req) if not resp or resp.get("headers", {}).get("content_type"): return resp mime_type, _ = mimetypes.guess_type(req["uri"]) return response.with_content_type(resp, mime_type or "application/octet-stream")
def wrapped_app(req): resp = app(req) if not resp or resp.get("headers", {}).get("content_type"): return resp mime_type, _ = mimetypes.guess_type(req["uri"]) return response.with_content_type( resp, mime_type or "application/octet-stream")
def render(response, request): if not response: return if not isinstance(response, dict): # If the response is a function, call it and render the result. if callable(response): return render( response(request, **request.get("route_params", {})), request) response = with_body(response) response["body"] = _render_body(response.get("body"), request) # Default content_type is text/html. if not response.get("headers", {}).get("content_type"): response = with_content_type(response, "text/html") return response