From a7b39b40ecad595a9b78d579385951664cdd4835 Mon Sep 17 00:00:00 2001 From: Sonu Auti Date: Sat, 11 Aug 2018 10:01:36 +0530 Subject: [PATCH] Auto detect index file from web directory added support for auto detect index file from web directory (support any type of index file (index.*) --- .../TinyWebServer$EchoThread.class | Bin 3818 -> 3818 bytes .../androidhttpweb/TinyWebServer.class | Bin 15453 -> 16023 bytes .../src/androidhttpweb/TinyWebServer.java | 31 ++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/AndroidWebServer/build/classes/androidhttpweb/TinyWebServer$EchoThread.class b/AndroidWebServer/build/classes/androidhttpweb/TinyWebServer$EchoThread.class index e9cef90800e9411434878bb99e2c89000013a667..f828b4dad422e2d00b61a489cab2c743313d9aa3 100644 GIT binary patch delta 238 zcmWNJJugE67)HblJ>Sa?hn-z|*u!O?ehzZu;YC|H#5kgZ<3OL_k!OTc z#yDewb0#S;!v%4QB)DXjE9SUno)Qb(kfKbQTUNPajS3r7+2Vm6YQgm}sO#M0)8a`X zo)w{?Azn1ftEPEVVv44c0i=0Xh7YY%(I#Ko=37~Ql&7r%zpC=5hR~-v)mE38y3Lhi T5%pP2t_`Ty1{KXMIm`M7?hZz7 delta 238 zcmWN_yDvil7>D8a_Z5xCIdY-~!&xjAgNV&PU?K)X2SbMr1|7uKCN_!DWMMTKn$+Yn zxko~xtxL3$x)g^ZNW`V+_&k9h_?fPVvqCegxUA8}dbTezZc`f=n>4Up?;U)0>1Ll^ z4(R8Q0gf0Z&jJQY1x*X)c(h%siJYa>Ftewzwt79oO9RN}v!A z@_1AyRrT55-f`O}9QRa29h!se>Q SJhfU>jePx;Xe)UGaT7(_<-SqhMSC#5jG-593u%v5{-ny z;)-!4DNMN%#+s6>lBZINO08T;4O2f!gW=NJ72lQgFx5*NBN>Wqb!0nNGQ%{)Iwb8O zNtUWRK#EAmFvLzewzKwh(Z}p0=_=ifbPr1p>1m{wDtm`%s^sXvJ}Tv^uCI|iBl#Mw zU-h}bNTF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xX1`JEV_StYH#xDEDkdg?cNLTpK zjhaXq{OC#9c;w_r56YF^)^5Eqb71XFu$HVji12urlhnlUGpN@wQ~uxGOFa@R>D~LB z{f%Kz<|k1kmJd76#$OxII)8mY_xT$Fs`rC{ zHv0Dmw8`Hb&=&uJfVTSE0(#JYD4>V^?EyWatIY5p4QPk|SU`{aPXx5ne=?w_{HFtY z#(y@T=ltg*0lnbA7|=`pu7FMhQBAEz5bg4z2(0h&^!LS0lnwH zpS*=W4Co{O{e3avEC1`5@Qwd%O!&_KJ|_I&?~e)n5BNXE zq@VnQG2v&w2hza*1v$~QT}Nbv5_cON8oQYe2b8Y)!S;QygG!kM~m3U_0b#; XJ>eJ7FZ?1NoB9%Cl;!30EAf8;`e~G# diff --git a/AndroidWebServer/src/androidhttpweb/TinyWebServer.java b/AndroidWebServer/src/androidhttpweb/TinyWebServer.java index 7644624..f14ef9a 100644 --- a/AndroidWebServer/src/androidhttpweb/TinyWebServer.java +++ b/AndroidWebServer/src/androidhttpweb/TinyWebServer.java @@ -151,6 +151,7 @@ public class TinyWebServer extends Thread { public static String SERVER_IP="localhost"; public static int SERVER_PORT=9000; public static boolean isStart=true; + public static String INDEX_FILE_NAME="index.html"; public TinyWebServer(final String ip, final int port) throws IOException { @@ -281,7 +282,7 @@ public void processLocation(DataOutputStream out, String location, String postDa case "/": //root location, server index file CONTENT_TYPE = "text/html"; - data=readFile(WEB_DIR_PATH+"/index.php"); + data=readFile(WEB_DIR_PATH+"/"+INDEX_FILE_NAME); constructHeader(out, data.length() + "", data); break; default: @@ -528,6 +529,7 @@ public String readFile(String fileName){ } }catch(Exception er){ pageNotFound(); + return ""; } return content; } @@ -538,6 +540,7 @@ public static void init(String ip,int port,String public_dir){ SERVER_IP=ip; SERVER_PORT=port; WEB_DIR_PATH=public_dir; + scanFileDirectory(); } @@ -568,7 +571,31 @@ public static void stopServer(){ } } - /*//use for testing + + //scan for index file + public static void scanFileDirectory(){ + boolean isIndexFound=false; + try{ + File file=new File(WEB_DIR_PATH); + if(file.isDirectory()){ + File[] allFiles=file.listFiles(); + for (File allFile : allFiles) { + //System.out.println(allFile.getName().split("\\.")[0]); + if(allFile.getName().split("\\.")[0].equalsIgnoreCase("index")){ + TinyWebServer.INDEX_FILE_NAME=allFile.getName(); + isIndexFound=true; + } + } + } + + }catch(Exception er){} + + if(!isIndexFound){ + System.out.println("Index file not found !"); + } + } + + /* //use for testing public static void main(String[] args) { try {