diff --git a/src/main/java/moe/yushi/authlibinjector/httpd/URLFilter.java b/src/main/java/moe/yushi/authlibinjector/httpd/URLFilter.java index 46e8cdc..fdecb6e 100644 --- a/src/main/java/moe/yushi/authlibinjector/httpd/URLFilter.java +++ b/src/main/java/moe/yushi/authlibinjector/httpd/URLFilter.java @@ -6,8 +6,24 @@ import java.util.Optional; import moe.yushi.authlibinjector.internal.fi.iki.elonen.IHTTPSession; import moe.yushi.authlibinjector.internal.fi.iki.elonen.Response; +/** + * A URLFilter filters the URLs in the bytecode, and intercepts those he is interested in. + */ public interface URLFilter { + /** + * Returns true if the filter MAY be interested in the given URL. + * + * The URL is grabbed from the bytecode, and it may be different from the URL being used at runtime. + * Therefore, the URLs may be incomplete or malformed, or contain some template symbols. eg: + * https://api.mojang.com/profiles/ (the actual one being used is https://api.mojang.com/profiles/minecraft) + * https://sessionserver.mojang.com/session/minecraft/profile/ (template symbols) + * + * If this method returns true for the given URL, the URL will be intercepted. + * And when a request is sent to this URL, handle() will be invoked. + * If it turns out that the filter doesn't really want to intercept the URL (handle() returns empty), + * the request will be reverse-proxied to the original URL, as if nothing happened. + */ boolean canHandle(String domain, String path); Optional handle(String domain, String path, IHTTPSession session) throws IOException; diff --git a/src/main/java/moe/yushi/authlibinjector/httpd/URLProcessor.java b/src/main/java/moe/yushi/authlibinjector/httpd/URLProcessor.java index 7e8005d..893c7f3 100644 --- a/src/main/java/moe/yushi/authlibinjector/httpd/URLProcessor.java +++ b/src/main/java/moe/yushi/authlibinjector/httpd/URLProcessor.java @@ -39,6 +39,16 @@ public class URLProcessor { this.redirector = redirector; } + /** + * Transforms the input URL(which is grabbed from the bytecode). + * + * If any filter is interested in the URL, the URL will be redirected to the local HTTP server. + * Otherwise, the URLRedirector will be invoked to determine whether the URL should be modified + * and pointed to the customized authentication server. + * If none of above happens, empty is returned. + * + * @return the transformed URL, or empty if it doesn't need to be transformed + */ public Optional transformURL(String inputUrl) { Matcher matcher = URL_REGEX.matcher(inputUrl); if (!matcher.find()) { diff --git a/src/main/java/moe/yushi/authlibinjector/httpd/URLRedirector.java b/src/main/java/moe/yushi/authlibinjector/httpd/URLRedirector.java index 6688f64..41e8923 100644 --- a/src/main/java/moe/yushi/authlibinjector/httpd/URLRedirector.java +++ b/src/main/java/moe/yushi/authlibinjector/httpd/URLRedirector.java @@ -2,6 +2,10 @@ package moe.yushi.authlibinjector.httpd; import java.util.Optional; +/** + * A URLRedirector modifies the URLs found in the bytecode, + * and points them to the customized authentication server. + */ public interface URLRedirector { Optional redirect(String domain, String path); }