1414import java .io .InputStream ;
1515import java .io .IOException ;
1616import java .net .URI ;
17+ import java .security .MessageDigest ;
1718import java .util .*;
1819import java .util .logging .Level ;
1920import java .util .logging .Logger ;
@@ -27,6 +28,8 @@ public class HTTPHandler extends ChannelInboundHandlerAdapter{
2728 public static final AttributeKey <List <HttpContent >> ATTR_CONTENT = AttributeKey .newInstance ("content" );
2829 private static final Logger LOGGER = Logger .getLogger ("Handler" );
2930
31+ private static byte [] jsHash ;
32+
3033 @ Override
3134 public void channelRead (ChannelHandlerContext ctx ,Object msg ){
3235 if (msg instanceof HttpRequest ){
@@ -62,7 +65,7 @@ private void handleResponse(ChannelHandlerContext ctx){
6265 status = 500 ;
6366 indexData = "Some error occured." .getBytes ();
6467 }
65- indexData = new String (indexData ).replace ("<div class=\" version\" ></div>" ,"<div class=\" version\" >" +Main .class .getPackage ().getImplementationVersion ()+"</div>" ).getBytes ();
68+ indexData = new String (indexData ).replace ("${GLOBE_JS_VERSION}" , Base64 . getEncoder (). encodeToString ( HTTPHandler . getJSHash ()). replaceAll ( "=" , "" )). replace ( " <div class=\" version\" ></div>" ,"<div class=\" version\" >" +Main .class .getPackage ().getImplementationVersion ()+"</div>" ).getBytes ();
6669 ByteBuf responseContent = Unpooled .copiedBuffer (indexData );
6770 FullHttpResponse response = new DefaultFullHttpResponse (request .protocolVersion (),HttpResponseStatus .valueOf (status ),responseContent );
6871 response .headers ().add ("Content-Length" ,responseContent .capacity ());
@@ -143,4 +146,14 @@ private static InputStream getResource(String name){
143146 return HTTPHandler .class .getClassLoader ().getResourceAsStream (name );
144147 }
145148
149+ private static byte [] getJSHash (){
150+ if (HTTPHandler .jsHash ==null ){
151+ try {
152+ MessageDigest md = MessageDigest .getInstance ("SHA-1" );
153+ HTTPHandler .jsHash = md .digest (HTTPHandler .readResource (HTTPHandler .getResource ("globe.js" )));
154+ }catch (Exception ignored ){}
155+ }
156+ return HTTPHandler .jsHash ;
157+ }
158+
146159}
0 commit comments