Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,13 @@ public final class MirrorSelector {
* mirror penalty.
*/
private static final List<Mirror> CANDIDATES = List.of(
// Domestic cache proxy for Chinese users — faster than direct GitHub access
// Domestic API cache proxy. Only handles GitHub API paths
// (/github/repos/...), not raw.githubusercontent.com or
// github.com pages. PREFIX_FULL_URL would produce
// /github/https://raw.githubusercontent.com/... which the
// server cannot serve → HTTP 403.
new Mirror("cache-121.199.60.4",
"http://121.199.60.4/github/", Strategy.PREFIX_FULL_URL, "http://121.199.60.4/github/"),
"http://121.199.60.4/github/", Strategy.API_PREFIX, "http://121.199.60.4/github/"),
// gh.tinylake.top first — TinyLake's own proxy, the same one
// mindustry.top/download links to. Empirically the most
// reliable mirror for users in mainland China.
Expand Down Expand Up @@ -252,7 +256,17 @@ private enum Strategy {
* Substitute {@code github.com} with the mirror host
* (and {@code raw.githubusercontent.com} with {@code raw.<host>/}).
*/
HOST_REPLACE
HOST_REPLACE,
/**
* Rewrite only {@code api.github.com} URLs by stripping the API
* host and prepending {@code prefix} + {@code repos/...}.
* Other GitHub origins (raw, github.com, codeload) are passed
* through unchanged — this mirror cannot serve them.
*
* <p>Designed for cache proxies that speak the GitHub API v3
* protocol but cannot proxy raw file downloads.</p>
*/
API_PREFIX
}

private static final class Mirror {
Expand Down Expand Up @@ -286,6 +300,12 @@ String wrap(String url) {
}
// api.github.com / codeload not handled by host-replace mirrors
return url;
case API_PREFIX:
if (url.startsWith(API)) {
return prefix + url.substring(API.length());
}
// raw / github.com / codeload URLs cannot go through this proxy
return url;
default:
return url;
}
Expand All @@ -305,4 +325,4 @@ public List<String> candidateNames() {
for (Mirror m : CANDIDATES) names.add(m.name);
return Collections.unmodifiableList(names);
}
}
}
Loading