GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Michael William Jonathan <[email protected]>,
	GNU/Weeb FB Team <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [PATCH fb v1 3/3] fb: web: Replace Facebook onion asset endpoint with non-onion
Date: Sat, 13 May 2023 01:44:11 +0700	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

... for faster response time.

Avoid HTTP request to Facebook onion if possible because using Tor
network is slow. When using Facebook onion, the CDN asset URL looks like
this:

  https://scontent.xx.facebookcooa4ldbat4g7iacswl3p2zrf5nuylvnhxn6kqolvojixwid.onion/something

we can simply replace the domain with scontent.xx.fbcdn.net to get the
same asset:

  https://scontent.xx.fbcdn.net/something

Side note: We don't fully understand how Facebook actually manages their
CDN. We may introduce a subtle issue by doing it this way. But we hope
we don't.

Signed-off-by: Ammar Faizi <[email protected]>
---
 web/public/api.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/web/public/api.php b/web/public/api.php
index 1b9ef97a2fb9c868..b2e19789dbca21c6 100644
--- a/web/public/api.php
+++ b/web/public/api.php
@@ -165,6 +165,14 @@ function rewriteOnionURL(?string $str): ?string
 		return $str;
 	}
 
+	/**
+	 * Don't use Facebook onion CDN for performance reasons.
+	 */
+	if (preg_match("/^scontent.xx.face.+?\.onion$/", $p["host"])) {
+		$p["host"] = "scontent.xx.fbcdn.net";
+		return build_url($p);
+	}
+
 	$signature = md5($str.API_SECRET, true);
 
 	/**
-- 
Ammar Faizi


  parent reply	other threads:[~2023-05-12 18:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-12 18:44 [PATCH fb v1 0/3] Facebook Onion assets optimization Ammar Faizi
2023-05-12 18:44 ` [PATCH fb v1 1/3] fb: web: Don't use proxy if the host isn't an onion domain Ammar Faizi
2023-05-12 18:44 ` [PATCH fb v1 2/3] fb: helper: Introduce `build_url()` function Ammar Faizi
2023-05-12 18:44 ` Ammar Faizi [this message]
2023-05-12 19:10 ` [PATCH fb v1 0/3] Facebook Onion assets optimization GNU/Weeb Facebook Team

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox