From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1683917065; bh=5SXMADDkoLSkDmg13RcCzEW1ilOVI4UlpVL0Yo4XMnw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=RNYzW8O+uLBB1Lc4huu/BWTs6dQkESGwVk6yeeN75fdEp5YEpu7pZ4r0B9MGQxlB5 sxMMI1l1jWAjNXGMRks6Z0z1ppeCyBBPloxP1cwIn3abGs9//GdYbfoYTOWdCDgshS MDAZ0cSWbNLo8Yq5JhcgM+7r+tNK41jmk63UM8mFqqrH+tTGS6eB4ZzwU/sH8lOrNL FUghbsD9JoV89n2Y3sXBhxFQ4Au/eoJhoetaGkfr/jPpnntTNsmrVrqbAn5NeeKR+R a8M1I0WHyI57aNPXalQ9UkjRNlHMjuOVk+hvo/b8ggfkeP4wFyM3B/S8tUPodiVTAR MLW4102xXJJBw== Received: from integral2.. (unknown [128.199.192.202]) by gnuweeb.org (Postfix) with ESMTPSA id E3F3B2491E2; Sat, 13 May 2023 01:44:23 +0700 (WIB) From: Ammar Faizi To: Ammar Faizi Cc: Michael William Jonathan , GNU/Weeb FB Team , GNU/Weeb Mailing List 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 Message-Id: <20230512184411.26860-4-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230512184411.26860-1-ammarfaizi2@gnuweeb.org> References: <20230512184411.26860-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: ... 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 --- 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