File tree Expand file tree Collapse file tree
stubbornjava-common/src/main/java/com/stubbornjava/common
main/java/com/stubbornjava/webapp
test/java/com/stubbornjava/webapp/post Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- package com .stubbornjava .webapp . post ;
1+ package com .stubbornjava .common ;
22
33import java .util .regex .Matcher ;
44import java .util .regex .Pattern ;
55
6- public class SlugUtil {
6+ public class Slugs {
77 // Match any non "word" ([a-zA-Z_0-9]) character
88 private static final Pattern pattern = Pattern .compile ("\\ W+" );
99
Original file line number Diff line number Diff line change 2929import io .undertow .server .handlers .resource .FileResourceManager ;
3030import io .undertow .server .handlers .resource .ResourceHandler ;
3131import io .undertow .server .handlers .resource .ResourceManager ;
32+ import io .undertow .util .Headers ;
3233import okhttp3 .HttpUrl ;
3334
3435public class CustomHandlers {
@@ -114,4 +115,24 @@ public static ExceptionHandler exception(HttpHandler handler) {
114115 }
115116 });
116117 }
118+
119+ public static HttpHandler loadbalancerHttpToHttps (HttpHandler next ) {
120+ return (HttpServerExchange exchange ) -> {
121+ HttpUrl currentUrl = Exchange .urls ().currentUrl (exchange );
122+ String protocolForward = Exchange .headers ().getHeader (exchange , "X-Forwarded-Proto" ).orElse (null );
123+ if (null != protocolForward && protocolForward .equalsIgnoreCase ("http" )) {
124+ log .debug ("non https switching to https {}" , currentUrl .host ());
125+ HttpUrl newUrl = currentUrl .newBuilder ()
126+ .scheme ("https" )
127+ .port (443 )
128+ .build ();
129+ exchange .setStatusCode (301 );
130+ exchange .getResponseHeaders ().put (Headers .LOCATION , newUrl .toString ());
131+ exchange .endExchange ();
132+ return ;
133+ }
134+
135+ next .handleRequest (exchange );
136+ };
137+ }
117138}
Original file line number Diff line number Diff line change 99
1010import com .google .common .collect .ImmutableList ;
1111import com .stubbornjava .common .Json ;
12+ import com .stubbornjava .common .Slugs ;
1213import com .stubbornjava .common .Templating ;
13- import com .stubbornjava .webapp .post .SlugUtil ;
1414
1515public class Guides {
1616 private static final Logger log = LoggerFactory .getLogger (Guides .class );
@@ -28,7 +28,7 @@ private Guides() {}
2828 }
2929
3030 private static Guide buildGuide (String title ) {
31- String slug = SlugUtil .toSlug (title );
31+ String slug = Slugs .toSlug (title );
3232 String content = Templating .instance ().renderTemplate ("templates/src/guides/" + slug );
3333 Guide guide = new Guide (title , slug , content );
3434 return guide ;
Original file line number Diff line number Diff line change 33import java .time .LocalDateTime ;
44import java .util .List ;
55
6+ import com .stubbornjava .common .Slugs ;
67import com .stubbornjava .webapp .github .FileReference ;
78
89import lombok .Builder ;
@@ -24,6 +25,6 @@ public class PostRaw {
2425 @ Singular private final List <FileReference > gitFileReferences ;
2526
2627 public String getSlug () {
27- return SlugUtil .toSlug (title );
28+ return Slugs .toSlug (title );
2829 }
2930}
Load diff This file was deleted.
You can’t perform that action at this time.
0 commit comments