forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
36c8881
commit 5f338a7
Showing
7 changed files
with
113 additions
and
9 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
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
16 changes: 16 additions & 0 deletions
16
...evspace-proxy-core/src/main/java/io/quarkus/devspace/server/HeaderParamSessionRouter.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,16 @@ | ||
package io.quarkus.devspace.server; | ||
|
||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class HeaderParamSessionRouter implements RequestSessionRouter { | ||
private final String name; | ||
|
||
public HeaderParamSessionRouter(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String match(RoutingContext ctx) { | ||
return ctx.request().headers().get(name); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
.../devspace-proxy-core/src/main/java/io/quarkus/devspace/server/PathParamSessionRouter.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,33 @@ | ||
package io.quarkus.devspace.server; | ||
|
||
import io.vertx.core.http.HttpServerRequest; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class PathParamSessionRouter implements RequestSessionRouter { | ||
private final Pattern pattern; | ||
|
||
public PathParamSessionRouter(String pathExpression) { | ||
String regex = pathExpression.replace("<service>", "(?<service>[^/]+)"); | ||
pattern = Pattern.compile(regex + ".*"); | ||
} | ||
|
||
@Override | ||
public String match(RoutingContext ctx) { | ||
String path = ctx.normalizedPath(); | ||
return match(path); | ||
} | ||
|
||
public String match(String path) { | ||
if (path == null) | ||
return null; | ||
Matcher matcher = pattern.matcher(path); | ||
if (matcher.matches()) { | ||
return matcher.group("service"); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...devspace-proxy-core/src/main/java/io/quarkus/devspace/server/QueryParamSessionRouter.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,16 @@ | ||
package io.quarkus.devspace.server; | ||
|
||
import io.vertx.ext.web.RoutingContext; | ||
|
||
public class QueryParamSessionRouter implements RequestSessionRouter { | ||
private final String name; | ||
|
||
public QueryParamSessionRouter(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String match(RoutingContext ctx) { | ||
return ctx.queryParams().get(name); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...tp/devspace-proxy-core/src/main/java/io/quarkus/devspace/server/RequestSessionRouter.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,11 @@ | ||
package io.quarkus.devspace.server; | ||
|
||
import io.vertx.core.http.HttpServerRequest; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* | ||
*/ | ||
public interface RequestSessionRouter { | ||
String match(RoutingContext ctx); | ||
} |
16 changes: 16 additions & 0 deletions
16
...ions/vertx-http/devspace-proxy-core/src/test/java/io/quarkus/devspace/test/MatchTest.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,16 @@ | ||
package io.quarkus.devspace.test; | ||
|
||
import io.quarkus.devspace.server.PathParamSessionRouter; | ||
import org.junit.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
public class MatchTest { | ||
@Test | ||
public void testPathParam() { | ||
PathParamSessionRouter router = new PathParamSessionRouter("/foo/bar/<service>"); | ||
Assertions.assertEquals("bill", router.match("/foo/bar/bill")); | ||
Assertions.assertEquals("bill", router.match("/foo/bar/bill/other/stuff")); | ||
Assertions.assertEquals("bill", router.match("/foo/bar/bill/")); | ||
} | ||
|
||
} |