Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/main/java/moe/yushi/authlibinjector/AuthlibInjector.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.stream.Stream;
import moe.yushi.authlibinjector.httpd.AntiFeaturesFilter;
import moe.yushi.authlibinjector.httpd.DefaultURLRedirector;
import moe.yushi.authlibinjector.httpd.FloodgateGlobalLinkingFilter;
import moe.yushi.authlibinjector.httpd.LegacySkinAPIFilter;
import moe.yushi.authlibinjector.httpd.ProfileKeyFilter;
import moe.yushi.authlibinjector.httpd.PublickeysFilter;
Expand Down Expand Up @@ -259,6 +260,11 @@ private static List<URLFilter> createFilters(APIMetadata config) {
filters.add(new ProfileKeyFilter());
}

boolean floodgateGlobalLinkingDefault = Boolean.TRUE.equals(config.getMeta().get("feature.floodgate_global_linking"));
if (floodgateGlobalLinkingDefault) {
filters.add(new FloodgateGlobalLinkingFilter(config.getApiRoot()));
}

filters.add(new PublickeysFilter());

return filters;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2026 Haowei Wen <yushijinhun@gmail.com> and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package moe.yushi.authlibinjector.httpd;

import static moe.yushi.authlibinjector.util.IOUtils.CONTENT_TYPE_TEXT;
import static moe.yushi.authlibinjector.util.Logging.log;
import static moe.yushi.authlibinjector.util.Logging.Level.WARNING;

import java.io.IOException;
import java.util.Optional;
import java.util.regex.Pattern;

import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Response;
import moe.yushi.authlibinjector.internal.fi.iki.elonen.Status;

/**
* Proxies Floodgate Global Linking query requests to the custom authentication server.
*/
public class FloodgateGlobalLinkingFilter implements URLFilter {

private static final String GEYSER_GLOBAL_API_DOMAIN = "api.geysermc.org";
private static final Pattern LINK_QUERY_PATH = Pattern.compile("^/v2/link/(bedrock|java)/[^/]+$");

private String apiRoot;

public FloodgateGlobalLinkingFilter(String apiRoot) {
this.apiRoot = apiRoot.endsWith("/") ? apiRoot : apiRoot + "/";
}

@Override
public boolean canHandle(String domain) {
return domain.equals(GEYSER_GLOBAL_API_DOMAIN);
}

@Override
public Optional<Response> handle(String domain, String path, IHTTPSession session) throws IOException {
if (!domain.equals(GEYSER_GLOBAL_API_DOMAIN) || !session.getMethod().equals("GET") || !LINK_QUERY_PATH.matcher(path).find()) {
return Optional.empty();
}

String target = apiRoot + "geyser" + path;

try {
return Optional.of(URLProcessor.reverseProxy(session, target));
} catch (IOException e) {
log(WARNING, "Failed to proxy Floodgate Global Linking request to [" + target + "]", e);
return Optional.of(Response.newFixedLength(Status.BAD_GATEWAY, CONTENT_TYPE_TEXT, "Bad Gateway"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public Response serve(IHTTPSession session) {
private static final Set<String> ignoredHeaders = new HashSet<>(Arrays.asList("host", "expect", "connection", "keep-alive", "transfer-encoding"));

@SuppressWarnings("resource")
private Response reverseProxy(IHTTPSession session, String upstream) throws IOException {
static Response reverseProxy(IHTTPSession session, String upstream) throws IOException {
String method = session.getMethod();

String url = session.getQueryParameterString() == null ? upstream : upstream + "?" + session.getQueryParameterString();
Expand Down
Loading