Skip to content

Commit 0ec781f

Browse files
committed
proxy: match www.x.com + subdomains for GraphQL URL truncation (#64)
The x.com GraphQL URL-length fix added in v1.2.1 (cbe06b5) only matched exact host "x.com". But browsers actually navigate to www.x.com, and api.x.com serves GraphQL endpoints too — the original fix never fired for real traffic. @pourya-p's log in #64 made this unambiguous: relay GET https://www.x.com/i/api/graphql/<hash>/HomeTimeline?variables=...&features=... ... ERROR Relay failed: relay error: Exception: بیش از حد مجاز: طول نشانی وب URLFetch. (That Persian text is Apps Script's "URLFetch URL length exceeded" error, which is exactly what the truncation was supposed to prevent.) Widened the host matcher to `host == "x.com" || host ends with ".x.com"` so www.x.com / api.x.com / any future x.com subdomain all hit the rewrite. The path-pattern constraint (`/i/api/graphql/... ?variables=`) already filters to the right endpoints. 73 tests still pass.
1 parent 378013d commit 0ec781f

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

‎src/proxy_server.rs‎

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,13 +1182,22 @@ where
11821182
// x.com's GraphQL endpoints concatenate three huge JSON blobs into
11831183
// the query string: `?variables=<json>&features=<json>&fieldToggles=<json>`.
11841184
// The combined URL regularly exceeds Apps Script's URL length limit
1185-
// (it returns a generic "relay error" with no useful detail). The
1186-
// `variables=` portion alone is enough for x.com to serve the
1187-
// timeline — `features` / `fieldToggles` are client-capability
1188-
// hints it tolerates being absent. Truncating at the first `&`
1189-
// after `?variables=` ships a working request that fits under the
1190-
// limit. Ported from upstream Python 2d959d4 (p0u1ya's fix).
1191-
let path = if host.eq_ignore_ascii_case("x.com")
1185+
// (Apps Script returns "بیش از حد مجاز: طول نشانی وب URLFetch" /
1186+
// "URLFetch URL length exceeded"). The `variables=` portion alone
1187+
// is enough for x.com to serve the timeline — `features` /
1188+
// `fieldToggles` are client-capability hints it tolerates being
1189+
// absent. Truncating at the first `&` after `?variables=` ships a
1190+
// working request that fits under the limit. Ported from upstream
1191+
// Python 2d959d4 (p0u1ya's fix). Issue #64.
1192+
//
1193+
// Host matcher: browsers actually hit `www.x.com` (and sometimes
1194+
// `api.x.com`), not bare `x.com`. The original check only matched
1195+
// `x.com` exactly, so real traffic flew past the rewrite until
1196+
// pourya-p's log in #64 showed the real Host header. Match every
1197+
// subdomain of x.com here.
1198+
let host_lower = host.to_ascii_lowercase();
1199+
let is_x_com = host_lower == "x.com" || host_lower.ends_with(".x.com");
1200+
let path = if is_x_com
11921201
&& path.starts_with("/i/api/graphql/")
11931202
&& path.contains("?variables=")
11941203
{

0 commit comments

Comments
 (0)