add some javadoc and cleanup to Request.get

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2023-08-18 12:42:03 +10:00
parent f9f42d5303
commit 9f6da9a11e
2 changed files with 12 additions and 8 deletions

View File

@ -271,6 +271,10 @@ public interface AuthenticationState extends Request.AuthenticationState
}
};
/**
* The {@link SecurityHandler} will use this to wrap the {@link Request}.
* And then will return a {@link Deferred} authentication to bypass security constraints.
*/
class ServeAs implements AuthenticationState
{
private final HttpURI _uri;
@ -295,6 +299,11 @@ public interface AuthenticationState extends Request.AuthenticationState
};
}
/**
* This interface can be used inside a {@link ServeAs} implementation to wrap the request
* changing its target to a given path. If a {@link Request} implements this interface it can
* be obtained with the {@link Request#as(Request, Class)} method.
*/
public interface Path
{
Request serveAs(Request request, String path);

View File

@ -790,15 +790,10 @@ public interface Request extends Attributes, Content.Source
}
@SuppressWarnings("unchecked")
static <T extends Request.Wrapper, R> R get(Request request, Class<T> type, Function<T, R> getter)
static <T, R> R get(Request request, Class<T> type, Function<T, R> getter)
{
while (request instanceof Request.Wrapper wrapper)
{
if (type.isInstance(wrapper))
return getter.apply((T)wrapper);
request = wrapper.getWrapped();
}
return null;
T t = Request.as(request, type);
return (t == null) ? null : getter.apply(t);
}
static Request unWrap(Request request)