Untitled

From Sole Water Vole, 7 Years ago, written in Plain Text, viewed 2 times.
URL https://paste.blessuren.de/view/5f5e2cfd Embed
Download Paste or View Raw
  1. package net.hellmann.platform.authproxy.proxy.filter;
  2.  
  3. import com.netflix.util.Pair;
  4. import com.netflix.zuul.ZuulFilter;
  5. import com.netflix.zuul.context.RequestContext;
  6. import org.springframework.stereotype.Component;
  7. import org.springframework.web.util.UrlPathHelper;
  8.  
  9. import java.util.Optional;
  10.  
  11. @Component
  12. public class LocationHeaderRewritingFilter extends ZuulFilter {
  13.  
  14.     private final UrlPathHelper urlPathHelper = new UrlPathHelper();
  15.  
  16.     @Override
  17.     public String filterType() {
  18.         return "post";
  19.     }
  20.  
  21.     @Override
  22.     public int filterOrder() {
  23.         return 100;
  24.     }
  25.  
  26.     @Override
  27.     public boolean shouldFilter() {
  28.         return extractLocationHeader(RequestContext.getCurrentContext()).isPresent();
  29.     }
  30.  
  31.     @Override
  32.     public Object run() {
  33.         RequestContext ctx = RequestContext.getCurrentContext();
  34.         Pair<String, String> lh = extractLocationHeader(ctx).get();
  35.         lh.setSecond(lh.second().replace("http://", "https://"));
  36.         return null;
  37.     }
  38.  
  39.     private Optional<Pair<String, String>> extractLocationHeader(RequestContext ctx) {
  40.         return ctx.getZuulResponseHeaders().stream().filter(p -> "Location".equals(p.first())).findFirst();
  41.     }
  42. }

Reply to "Untitled"

Here you can reply to the paste above