Skip to content

Commit bb1caff

Browse files
Update RedirectFilter.java
1 parent e90052d commit bb1caff

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/main/java/org/example/filter/redirect/RedirectFilter.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,29 @@ public void init() {
2424

2525
@Override
2626
public void doFilter(HttpRequest request, HttpResponseBuilder response, FilterChain chain) {
27-
String path = request.getPath();
28-
29-
for (RedirectRule rule : rules) {
30-
final String sanitizedPath = path.replaceAll("[\\r\\n]", "_");
31-
LOG.info(() -> "Redirecting " + sanitizedPath + " -> " + rule.getTargetUrl() + " (" + rule.getStatusCode() + ")");
32-
response.setStatusCode(rule.getStatusCode());
33-
response.setHeader("Location", rule.getTargetUrl());
34-
return; // STOP pipeline
35-
}
36-
}
27+
String path = request.getPath();
3728

29+
if (path == null) {
3830
chain.doFilter(request, response);
31+
return;
32+
}
33+
34+
for (RedirectRule rule : rules) {
35+
if (rule.matches(path)) { // <-- DENNA RADEN SKA FINNAS
36+
final String sanitizedPath = path.replaceAll("[\\r\\n]", "_");
37+
LOG.info(() -> "Redirecting " + sanitizedPath + " -> "
38+
+ rule.getTargetUrl() + " (" + rule.getStatusCode() + ")");
39+
40+
response.setStatusCode(rule.getStatusCode());
41+
response.setHeader("Location", rule.getTargetUrl());
42+
return; // STOP pipeline
43+
}
3944
}
4045

46+
chain.doFilter(request, response);
47+
}
48+
49+
4150
@Override
4251
public void destroy() {
4352
// no-op

0 commit comments

Comments
 (0)