From 6b82cc7a69a9326775f1a45f6698b97867aa2303 Mon Sep 17 00:00:00 2001 From: Kumi Date: Mon, 25 Nov 2024 17:29:03 +0100 Subject: [PATCH] feat: Switch proxy service from Google Fonts to Typekit Replaces the existing Google Fonts proxy implementation with support for Typekit, enhancing user privacy. Updates relevant URLs and regex patterns to handle Typekit requests. Cleans up code by removing unused 'fonts.gstatic.com' proxy endpoint. Changes references in the HTML template and terminology to reflect the switch from 'GoogleDonts' to 'TypeNot'. Increases server port for the application from 5678 to 5690. --- app.py | 49 +++++++++----------------------------------- templates/index.html | 20 +++++++++--------- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/app.py b/app.py index e6eb75e..1f4f2e7 100644 --- a/app.py +++ b/app.py @@ -4,11 +4,12 @@ import re app = Flask(__name__) -FONT_STATIC_URL = "https://fonts.gstatic.com" -FONT_API_URL = "https://fonts.googleapis.com" +FONT_URL = "https://use.typekit.net" -PATTERN = rb"fonts\.gstatic\.com" +PATTERN = r"use\.typekit\.net" +# P_PATTERN: Any *line* that contains p.typekit.net will be removed +P_PATTERN = r".*p\.typekit\.net.*\n" @app.route("/") def home(): @@ -16,38 +17,10 @@ def home(): return render_template("index.html", domain=domain) -@app.route("/s/", methods=["GET"]) -def proxy_fonts_static(path): - url = f"{FONT_STATIC_URL}/s/{path}" - response = requests.get(url, stream=True) - - def generate(): - for chunk in response.iter_content(chunk_size=8192): - yield chunk - - # Remove hop-by-hop headers - headers = { - key: value - for key, value in response.headers.items() - if key.lower() - not in [ - "connection", - "keep-alive", - "proxy-authenticate", - "proxy-authorization", - "te", - "trailers", - "transfer-encoding", - "upgrade", - ] - } - return Response(generate(), status=response.status_code, headers=headers) - - @app.route("/", methods=["GET"]) -def proxy_fonts_api(path): +def proxy_fonts(path): query_string = request.query_string.decode("utf-8") - url = f"{FONT_API_URL}/{path}" + url = f"{FONT_URL}/{path}" if query_string: url += f"?{query_string}" headers = { @@ -58,13 +31,11 @@ def proxy_fonts_api(path): ) response = requests.get(url, headers=headers) - replacement = request.host.encode( - "utf-8" - ) # Convert the host to bytes for replacement if "text/css" in response.headers.get("Content-Type", ""): - content = response.content - content = re.sub(PATTERN, replacement, content) + content = response.content.decode("utf-8") + content = re.sub(PATTERN, request.host, content) + content = re.sub(P_PATTERN, "", content) headers = { key: value @@ -103,4 +74,4 @@ def proxy_fonts_api(path): if __name__ == "__main__": - app.run(host="0.0.0.0", port=5678) + app.run(host="0.0.0.0", port=5690) diff --git a/templates/index.html b/templates/index.html index 7caa834..6674ea2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -6,7 +6,7 @@ name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> - GoogleDonts + TypeNot
-

Welcome to GoogleDonts

+

Welcome to TypeNot

- GoogleDonts is a proxy service to Google Fonts. It allows you to use - Google Fonts without any data being sent to Google. + TypeNot is a privacy-focused proxy for Typekit. It allows you to use + Typekit fonts without giving your visitors' data to Adobe.

To use the proxy, simply replace - https://fonts.googleapis.com/ with + https://use.typekit.net/ with {{ domain }} in the URL.

Example:

- {{ domain }}css?family=Montserrat:400,700 + {{ domain }}/jjs4qed.css
@@ -79,9 +79,9 @@

Privacy / Disclaimer

- GoogleDonts is a privacy-focused service. It does not track you or log - any data. It creates a fully separate connection to Google Fonts for - each request, so Google does not see your IP address or any other + TypeNot is a privacy-focused service. It does not track you or log + any data. It creates a fully separate connection to Adobe Fonts for + each request, so Adobe does not see your IP address or any other information about you.

@@ -93,7 +93,7 @@

The service is open-source and you can view the source code on - Private.coffee Git.