In my mind , the value of private String uri
and the value of local var String newURI
will be the same in any time.
But in fact, I test many times, sometimes the two values are not the same, why? What happened with NanoHTTPD ?
Guess
I guess the function public Response serve(IHTTPSession session)
is muilti threads in the process public class HttpServer extends NanoHTTPD
,
different threads operate the two value , so sometimes uri and newURL have different value, right?
public class HttpServer extends NanoHTTPD {
private String uri;
private void GetURLAndParValue(IHTTPSession session){
uri = session.getUri(); //I pass the value to private var uri
}
@Override
public Response serve(IHTTPSession session) {
GetURLAndParValue(session);
String newURI= session.getUri(); // I pass the value to local newURI
MResponseInput mResponseInput=new MResponseInput();
Utility.LogError("New0:"+this.uri+" : "+newURI);
String parDiskPath=session.getParms().get(mContext.getString(R.string.ParDiskIndex));
String parIsAssets=session.getParms().get(mContext.getString(R.string.ParIsAssets));
Utility.LogError("New1:"+this.uri+" : "+newURI);
if (newURI.endsWith("/")){
if (newURI.length()==1) {
String homePage = mContext.getString(R.string.WebHomePageHtml);
mResponseInput= GetMResponseInputByHtmlFile(mContext,homePage);
String s=HttpHelper.HomePage(mContext);
return newFixedLengthResponse(s);
}else{
String temp=HttpHelper.ListFolderByName(mContext,session);
return newFixedLengthResponse(temp);
}
}else{
String mimeTypeForFile = getMimeTypeForFile(newURI).trim().toLowerCase();
Utility.LogError("New2:"+this.uri+" : "+newURI);
if (parIsAssetsValue!=null&&parIsAssetsValue.equals("1")){
return GetResponseInputByAssetsFile(newURI);
}
if (mimeTypeForFile.equals("text/html")){
String fileName=PublicParFun.RemoveFirstBackslash(newURI).toLowerCase();
}
}
return newFixedLengthResponse(Response.Status.OK,mResponseInput.mimeTypeForFile,mResponseInput.inputStream, mResponseInput.Size);
}
}