mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-22 12:03:09 -04:00
Hosting HTML files using the HTTP server
This commit is contained in:
parent
45208f64a7
commit
bff90479a5
@ -1,23 +1,36 @@
|
||||
package org.kiwix.kiwixmobile.webserver;
|
||||
|
||||
import android.util.Log;
|
||||
import fi.iki.elonen.NanoHTTPD;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class WebServer extends NanoHTTPD {
|
||||
private String selectedFilePath;
|
||||
|
||||
public WebServer(int port) {
|
||||
public WebServer(int port,String selectedFilePath) {
|
||||
super(port);
|
||||
this.selectedFilePath = selectedFilePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response serve(IHTTPSession session) {
|
||||
String msg = "<html><body><h1>Hello server</h1>\n";
|
||||
Map<String, String> parms = session.getParms();
|
||||
if (parms.get("username") == null) {
|
||||
msg += "<form action='?' method='get'>\n <p>Your name: <input type='text' name='username'></p>\n" + "</form>\n";
|
||||
} else {
|
||||
msg += "<p>Hello, " + parms.get("username") + "!</p>";
|
||||
String answer = "";
|
||||
try {
|
||||
FileReader index = new FileReader(selectedFilePath);
|
||||
BufferedReader reader = new BufferedReader(index);
|
||||
String line = "";
|
||||
while ((line = reader.readLine()) != null) {
|
||||
answer += line;
|
||||
}
|
||||
reader.close();
|
||||
|
||||
} catch(IOException ioe) {
|
||||
Log.w("Httpd", ioe.toString());
|
||||
}
|
||||
return newFixedLengthResponse( msg + "</body></html>\n" );
|
||||
|
||||
|
||||
return newFixedLengthResponse(answer);
|
||||
}
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ public class WebServerHelper {
|
||||
ip += "Something Wrong! " + e.toString() + "\n";
|
||||
};
|
||||
|
||||
Log.v("DANG", "Returning : " + "http://" + ip)
|
||||
Log.v("DANG", "Returning : " + "http://" + ip);
|
||||
return "http://" + ip;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user