-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick of Improvements to PathSpec for Jetty 10.0.x (#8136)
* Cherry-pick of Improvements to PathSpec. * From commit: 5b4d1dd * Fixing ConstraintSecurityHandler usage of PathMappings * Fixing bad INCLUDE logic from cherry-pick in ServletHandler.doScope() * Cleanup of non ServletPathSpec behaviors in ServletPathMapping class * Skip optional group name/info lookup if regex fails. * Prevent NPE on static servletPathMappings * Update WebSocketMappings to use new PathMappings.getMatched(String) Signed-off-by: Joakim Erdfelt <[email protected]>
- Loading branch information
Showing
22 changed files
with
1,202 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/MatchedPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.http.pathmap; | ||
|
||
public interface MatchedPath | ||
{ | ||
MatchedPath EMPTY = new MatchedPath() | ||
{ | ||
@Override | ||
public String getPathMatch() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPathInfo() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return MatchedPath.class.getSimpleName() + ".EMPTY"; | ||
} | ||
}; | ||
|
||
static MatchedPath from(String pathMatch, String pathInfo) | ||
{ | ||
return new MatchedPath() | ||
{ | ||
@Override | ||
public String getPathMatch() | ||
{ | ||
return pathMatch; | ||
} | ||
|
||
@Override | ||
public String getPathInfo() | ||
{ | ||
return pathInfo; | ||
} | ||
|
||
@Override | ||
public String toString() | ||
{ | ||
return MatchedPath.class.getSimpleName() + "[pathMatch=" + pathMatch + ", pathInfo=" + pathInfo + "]"; | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Return the portion of the path that matches a path spec. | ||
* | ||
* @return the path name portion of the match. | ||
*/ | ||
String getPathMatch(); | ||
|
||
/** | ||
* Return the portion of the path that is after the path spec. | ||
* | ||
* @return the path info portion of the match, or null if there is no portion after the {@link #getPathMatch()} | ||
*/ | ||
String getPathInfo(); | ||
} |
76 changes: 76 additions & 0 deletions
76
jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/MatchedResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.http.pathmap; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* The match details when using {@link PathMappings#getMatched(String)}, used to minimize return to the PathSpec or PathMappings for subsequent details | ||
* that are now provided by the {@link MatchedPath} instance. | ||
* | ||
* @param <E> the type of resource (IncludeExclude uses boolean, WebSocket uses endpoint/endpoint config, servlet uses ServletHolder, etc) | ||
*/ | ||
public class MatchedResource<E> | ||
{ | ||
private final E resource; | ||
private final PathSpec pathSpec; | ||
private final MatchedPath matchedPath; | ||
|
||
public MatchedResource(E resource, PathSpec pathSpec, MatchedPath matchedPath) | ||
{ | ||
this.resource = resource; | ||
this.pathSpec = pathSpec; | ||
this.matchedPath = matchedPath; | ||
} | ||
|
||
public static <E> MatchedResource<E> of(Map.Entry<PathSpec, E> mapping, MatchedPath matchedPath) | ||
{ | ||
return new MatchedResource<>(mapping.getValue(), mapping.getKey(), matchedPath); | ||
} | ||
|
||
public MatchedPath getMatchedPath() | ||
{ | ||
return this.matchedPath; | ||
} | ||
|
||
public PathSpec getPathSpec() | ||
{ | ||
return this.pathSpec; | ||
} | ||
|
||
public E getResource() | ||
{ | ||
return this.resource; | ||
} | ||
|
||
/** | ||
* Return the portion of the path that matches a path spec. | ||
* | ||
* @return the path name portion of the match. | ||
*/ | ||
public String getPathMatch() | ||
{ | ||
return matchedPath.getPathMatch(); | ||
} | ||
|
||
/** | ||
* Return the portion of the path that is after the path spec. | ||
* | ||
* @return the path info portion of the match, or null if there is no portion after the {@link #getPathMatch()} | ||
*/ | ||
public String getPathInfo() | ||
{ | ||
return matchedPath.getPathInfo(); | ||
} | ||
} |
Oops, something went wrong.