Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow request mappings to handle a request based on host #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
public class RequestMappingConfiguration implements Valid {

private String name;
private Pattern hostRegex;
private Pattern pathRegex;
private RestTemplateConfiguration restTemplateConfiguration;
private List<RequestForwardingInterceptor> requestForwardingInterceptors;
Expand All @@ -27,6 +28,7 @@ public class RequestMappingConfiguration implements Valid {

RequestMappingConfiguration(String name) {
this.name = name;
hostRegex = compile(".*");
pathRegex = compile("/.*");
requestForwardingInterceptors = new ArrayList<>();
unsetRequestForwardingInterceptors = new ArrayList<>();
Expand All @@ -41,6 +43,14 @@ public String getName() {
return name;
}

public Pattern getHostRegex() {
return hostRegex;
}

void setHostRegex(String hostRegex) {
this.hostRegex = compile(hostRegex);
}

public Pattern getPathRegex() {
return pathRegex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public static RequestMappingConfigurer requestMapping(String name) {
return new RequestMappingConfigurer(name);
}

public RequestMappingConfigurer hostRegex(String hostRegex) {
configuredObject.setHostRegex(hostRegex);
return this;
}

public RequestMappingConfigurer pathRegex(String pathRegex) {
configuredObject.setPathRegex(pathRegex);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ class RequestMappingResolver {
}

RequestMappingConfiguration resolveRequestMapping(HttpServletRequest request) {
final String serverName = request.getServerName();
String requestURI = request.getRequestURI();
List<RequestMappingConfiguration> configurations = requestMappingConfigurations.stream()
.filter(configuration -> configuration.getPathRegex().matcher(requestURI).matches())
.filter(configuration ->
configuration.getHostRegex().matcher(serverName).matches() &&
configuration.getPathRegex().matcher(requestURI).matches())
.collect(toList());
if (configurations.isEmpty()) {
log.debug("No request mapping matches {} incoming request", requestURI);
Expand Down