Skip to content

Commit

Permalink
Now web server works with assets.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou Chang committed Jul 27, 2012
1 parent bcef5f4 commit 79ff711
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
8 changes: 0 additions & 8 deletions src/teaonly/droideye/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,6 @@ private void initCamera() {
}

public String getLocalIpAddress() {

AssetManager aman = getAssets();
try {
AssetFileDescriptor assetFile = aman.openFd("demo.html");
Log.d(TAG, "File length = " + assetFile.getLength() );
} catch ( IOException ex) {
Log.d(TAG, ex.toString());
}

try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
Expand Down
12 changes: 8 additions & 4 deletions src/teaonly/droideye/NanoHTTPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.content.res.Resources;
import android.content.res.AssetManager;
import android.content.res.AssetFileDescriptor;
import android.util.Log;

/**
* A simple, tiny, nicely embeddable HTTP 1.0 (partially 1.1) server in Java
Expand Down Expand Up @@ -244,7 +245,7 @@ public NanoHTTPD( int port, File wwwroot ) throws IOException
myTcpPort = port;
myRootDir = wwwroot;
myAssets = null;
myServerSocket = new ServerSocket( myTcpPort );
beginDaemon();
}
Expand All @@ -254,7 +255,7 @@ public NanoHTTPD( int port, AssetManager wwwroot ) throws IOException
myTcpPort = port;
myAssets = wwwroot;
myRootDir = null;

myServerSocket = new ServerSocket( myTcpPort );
beginDaemon();
}
Expand Down Expand Up @@ -899,7 +900,7 @@ public Response serveFile( String uri, Properties header, File homeDir,
Response res = null;

if ( homeDir == null) {
serveAssets(uri, header);
return serveAssets(uri, header);
}
// Make sure we won't die of an exception later
if ( !homeDir.isDirectory())
Expand Down Expand Up @@ -1090,6 +1091,9 @@ private Response serveAssets( String uri, Properties header) {

// Remove URL arguments
uri = uri.trim().replace( File.separatorChar, '/' );
if ( uri.startsWith("/") ) {
uri = uri.substring(1, uri.length());
}
if ( uri.indexOf( '?' ) >= 0 )
uri = uri.substring(0, uri.indexOf( '?' ));

Expand All @@ -1098,7 +1102,7 @@ private Response serveAssets( String uri, Properties header) {
res = new Response( HTTP_FORBIDDEN, MIME_PLAINTEXT,
"FORBIDDEN: Won't serve ../ for security reasons." );
}

AssetFileDescriptor assetFile = null;
try {
assetFile = myAssets.openFd(uri);
Expand Down

0 comments on commit 79ff711

Please sign in to comment.