Javadoc for URLFilter&URLProcessor&URLRedirector

This commit is contained in:
yushijinhun 2018-12-31 11:22:50 +08:00
parent eeda91c329
commit cbc1e8c664
No known key found for this signature in database
GPG Key ID: 5BC167F73EA558E4
3 changed files with 30 additions and 0 deletions

View File

@ -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/<uuid> (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<Response> handle(String domain, String path, IHTTPSession session) throws IOException;

View File

@ -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<String> transformURL(String inputUrl) {
Matcher matcher = URL_REGEX.matcher(inputUrl);
if (!matcher.find()) {

View File

@ -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<String> redirect(String domain, String path);
}