Skip to content

Commit

Permalink
feat: rawPath
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and yzfeng2020 committed Oct 22, 2024
1 parent ce8a5ef commit 144b37f
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ protected AbstractRequestContextBuilder(boolean server, RpcRequest rpcReq, URI u
} else {
reqTarget = DefaultRequestTarget.createWithoutValidation(
RequestTargetForm.ORIGIN, null, null, null, -1,
uri.getRawPath(), uri.getRawPath(), uri.getRawQuery(), uri.getRawFragment());
uri.getRawPath(), uri.getRawPath(), null,
uri.getRawQuery(), uri.getRawFragment());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ static RequestTarget forClient(String reqTarget, @Nullable String prefix) {
*/
String maybePathWithMatrixVariables();

/**
* Returns the raw server path of this {@link RequestTarget}, which always starts with {@code '/'}.
* Unlike {@link #path()}, the returned string is the original request path without any normalization.
* For client target it always returns null.
*/
@Nullable
String rawPath();

/**
* Returns the query of this {@link RequestTarget}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,8 @@ boolean mustPreserveEncoding(int cp) {
private static final Bytes EMPTY_BYTES = new Bytes(0);
private static final Bytes SLASH_BYTES = new Bytes(new byte[] { '/' });

private static final RequestTarget INSTANCE_ASTERISK = createWithoutValidation(
RequestTargetForm.ASTERISK,
null,
null,
null,
-1,
"*",
"*",
null,
null);
private static final RequestTarget CLIENT_INSTANCE_ASTERISK = createAsterisk(false);
private static final RequestTarget SERVER_INSTANCE_ASTERISK = createAsterisk(true);

/**
* The main implementation of {@link RequestTarget#forServer(String)}.
Expand Down Expand Up @@ -232,10 +224,10 @@ public static RequestTarget forClient(String reqTarget, @Nullable String prefix)
*/
public static RequestTarget createWithoutValidation(
RequestTargetForm form, @Nullable String scheme, @Nullable String authority,
@Nullable String host, int port, String path, String pathWithMatrixVariables,
@Nullable String host, int port, String path, String pathWithMatrixVariables, @Nullable String rawPath,
@Nullable String query, @Nullable String fragment) {
return new DefaultRequestTarget(
form, scheme, authority, host, port, path, pathWithMatrixVariables, query, fragment);
form, scheme, authority, host, port, path, pathWithMatrixVariables, rawPath, query, fragment);
}

private final RequestTargetForm form;
Expand All @@ -249,14 +241,16 @@ public static RequestTarget createWithoutValidation(
private final String path;
private final String maybePathWithMatrixVariables;
@Nullable
private final String rawPath;
@Nullable
private final String query;
@Nullable
private final String fragment;
private boolean cached;

private DefaultRequestTarget(RequestTargetForm form, @Nullable String scheme,
@Nullable String authority, @Nullable String host, int port,
String path, String maybePathWithMatrixVariables,
String path,String maybePathWithMatrixVariables, @Nullable String rawPath,
@Nullable String query, @Nullable String fragment) {

assert (scheme != null && authority != null && host != null) ||
Expand All @@ -270,6 +264,7 @@ private DefaultRequestTarget(RequestTargetForm form, @Nullable String scheme,
this.port = port;
this.path = path;
this.maybePathWithMatrixVariables = maybePathWithMatrixVariables;
this.rawPath = rawPath;
this.query = query;
this.fragment = fragment;
}
Expand Down Expand Up @@ -312,6 +307,12 @@ public String maybePathWithMatrixVariables() {
return maybePathWithMatrixVariables;
}

@Override
@Nullable
public String rawPath() {
return rawPath;
}

@Nullable
@Override
public String query() {
Expand Down Expand Up @@ -380,6 +381,21 @@ public String toString() {
}
}

private static RequestTarget createAsterisk(boolean server) {
final String rawPath = server ? "*" : null;
return createWithoutValidation(
RequestTargetForm.ASTERISK,
null,
null,
null,
-1,
"*",
"*",
rawPath,
null,
null);
}

@Nullable
private static RequestTarget slowForServer(String reqTarget, boolean allowSemicolonInPathComponent,
boolean allowDoubleDotsInQueryString) {
Expand Down Expand Up @@ -411,7 +427,7 @@ private static RequestTarget slowForServer(String reqTarget, boolean allowSemico
// Reject a relative path and accept an asterisk (e.g. OPTIONS * HTTP/1.1).
if (isRelativePath(path)) {
if (query == null && path.length == 1 && path.data[0] == '*') {
return INSTANCE_ASTERISK;
return SERVER_INSTANCE_ASTERISK;
} else {
// Do not accept a relative path.
return null;
Expand Down Expand Up @@ -443,6 +459,7 @@ private static RequestTarget slowForServer(String reqTarget, boolean allowSemico
-1,
matrixVariablesRemovedPath,
encodedPath,
reqTarget,
encodeQueryToPercents(query),
null);
}
Expand Down Expand Up @@ -622,7 +639,7 @@ private static RequestTarget slowForClient(String reqTarget,

// Accept an asterisk (e.g. OPTIONS * HTTP/1.1).
if (query == null && path.length == 1 && path.data[0] == '*') {
return INSTANCE_ASTERISK;
return CLIENT_INSTANCE_ASTERISK;
}

final String encodedPath;
Expand All @@ -645,7 +662,9 @@ private static RequestTarget slowForClient(String reqTarget,
null,
-1,
encodedPath,
encodedPath, encodedQuery,
encodedPath,
null,
encodedQuery,
encodedFragment);
}
}
Expand Down Expand Up @@ -692,6 +711,7 @@ private static DefaultRequestTarget newAbsoluteTarget(
port,
encodedPath,
encodedPath,
null,
encodedQuery,
encodedFragment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ default RoutingContext withPath(String path) {
oldReqTarget.port(),
pathWithoutMatrixVariables,
path,
path,
oldReqTarget.query(),
oldReqTarget.fragment());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,7 @@ best
bestbuy
bet
bet.ar
bet.br
beta.bounty-full.com
beta.tailscale.net
betainabox.com
Expand Down Expand Up @@ -4732,6 +4733,7 @@ legal
legnica.pl
lego
leikanger.no
leilao.br
leirfjord.no
leirvik.no
leitungsen.de
Expand Down Expand Up @@ -5281,6 +5283,8 @@ mitoyo.kagawa.jp
mitsubishi
mitsue.nara.jp
mitsuke.niigata.jp
mittwald.info
mittwaldserver.info
miura.kanagawa.jp
miyada.nagano.jp
miyagi.jp
Expand Down Expand Up @@ -5471,6 +5475,7 @@ myasustor.com
mycloudnas.com
mydatto.com
mydatto.net
mydbserver.com
myddns.rocks
mydissent.net
mydns.bz
Expand Down Expand Up @@ -6793,6 +6798,7 @@ prof
prof.pr
profesional.bo
progressive
project.space
promo
properties
property
Expand Down Expand Up @@ -8598,6 +8604,7 @@ tychy.pl
tydal.no
tynset.no
typedream.app
typo3server.info
tysfjord.no
tysnes.no
tysvar.no
Expand Down Expand Up @@ -9000,6 +9007,7 @@ website.yandexcloud.net
websitebuilder.online
websozai.jp
webspace.rocks
webspaceconfig.de
webthings.io
webview-assets.aws-cloud9.af-south-1.amazonaws.com
webview-assets.aws-cloud9.ap-east-1.amazonaws.com
Expand Down
Loading

0 comments on commit 144b37f

Please sign in to comment.