File tree Expand file tree Collapse file tree 3 files changed +19
-1
lines changed
charon-spring-webmvc/src/main/java/com/github/mkopylec/charon Expand file tree Collapse file tree 3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change 19
19
public class RequestMappingConfiguration implements Valid {
20
20
21
21
private String name ;
22
+ private Pattern hostRegex ;
22
23
private Pattern pathRegex ;
23
24
private RestTemplateConfiguration restTemplateConfiguration ;
24
25
private List <RequestForwardingInterceptor > requestForwardingInterceptors ;
@@ -27,6 +28,7 @@ public class RequestMappingConfiguration implements Valid {
27
28
28
29
RequestMappingConfiguration (String name ) {
29
30
this .name = name ;
31
+ hostRegex = compile (".*" );
30
32
pathRegex = compile ("/.*" );
31
33
requestForwardingInterceptors = new ArrayList <>();
32
34
unsetRequestForwardingInterceptors = new ArrayList <>();
@@ -41,6 +43,14 @@ public String getName() {
41
43
return name ;
42
44
}
43
45
46
+ public Pattern getHostRegex () {
47
+ return hostRegex ;
48
+ }
49
+
50
+ void setHostRegex (String hostRegex ) {
51
+ this .hostRegex = compile (hostRegex );
52
+ }
53
+
44
54
public Pattern getPathRegex () {
45
55
return pathRegex ;
46
56
}
Original file line number Diff line number Diff line change @@ -14,6 +14,11 @@ public static RequestMappingConfigurer requestMapping(String name) {
14
14
return new RequestMappingConfigurer (name );
15
15
}
16
16
17
+ public RequestMappingConfigurer hostRegex (String hostRegex ) {
18
+ configuredObject .setHostRegex (hostRegex );
19
+ return this ;
20
+ }
21
+
17
22
public RequestMappingConfigurer pathRegex (String pathRegex ) {
18
23
configuredObject .setPathRegex (pathRegex );
19
24
return this ;
Original file line number Diff line number Diff line change @@ -23,9 +23,12 @@ class RequestMappingResolver {
23
23
}
24
24
25
25
RequestMappingConfiguration resolveRequestMapping (HttpServletRequest request ) {
26
+ final String serverName = request .getServerName ();
26
27
String requestURI = request .getRequestURI ();
27
28
List <RequestMappingConfiguration > configurations = requestMappingConfigurations .stream ()
28
- .filter (configuration -> configuration .getPathRegex ().matcher (requestURI ).matches ())
29
+ .filter (configuration ->
30
+ configuration .getHostRegex ().matcher (serverName ).matches () &&
31
+ configuration .getPathRegex ().matcher (requestURI ).matches ())
29
32
.collect (toList ());
30
33
if (configurations .isEmpty ()) {
31
34
log .debug ("No request mapping matches {} incoming request" , requestURI );
You can’t perform that action at this time.
0 commit comments