Skip to content

Commit

Permalink
Handle redirects
Browse files Browse the repository at this point in the history
Fixes micronaut-projects#360
Instead of passing a missing body to the view do an early exit if a redirect is encountered.
  • Loading branch information
Brutus5000 committed Mar 4, 2022
1 parent fd47ae9 commit dc5efef
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions views-core/src/main/java/io/micronaut/views/ViewsFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.micronaut.core.annotation.AnnotationMetadata;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.io.Writable;
import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.HttpAttributes;
Expand Down Expand Up @@ -78,6 +79,10 @@ public final Publisher<MutableHttpResponse<?>> doFilter(HttpRequest<?> request,
ServerFilterChain chain) {
return Flux.from(chain.proceed(request))
.switchMap(response -> {
if(response.getStatus() == HttpStatus.MOVED_PERMANENTLY) {
LOG.debug("redirect, passing through");
return Flux.just(response);
}
Optional<String> optionalView = viewsResolver.resolveView(request, response);
if (!optionalView.isPresent()) {
LOG.debug("no view found");
Expand Down

0 comments on commit dc5efef

Please sign in to comment.