|
package fvhttpserver;
import java.io.*;
import java.util.StringTokenizer;
public class ProcessQuery {
for(int i=0;i<query.length();i++) {
if(query.charAt(i) == '\r' || query.charAt(i) == '\n') {
pl = query.substring(0, i);
break;
}
}
System. out. println("[" + ip + "]: " + pl );
boolean uq = false;
if(cmd.toLowerCase().equals("get") || cmd.toLowerCase().equals("post")) {
uq = true;
file = file.substring(1).replace("/", "\\").replace("%20", " ");
File f = new File(Main. basedir. equals("") ? file : Main. basedir + "\\" + file );
if(f.isDirectory()) {
f = new File(f. getPath() + "\\" + "index.html");
if(!f.exists())
f = new File(f. getPath() + "\\" + "index.htm");
}
if(f.exists()) {
try {
out.println("HTTP/1.0 200 OK\r"
+ "Content-Length: " + f.length() + "\r\n");
System. out. println("[" + ip + "][Server]: HTTP/1.0 200 OK");
byte[] tmp = new byte[2048];
int len = 0;
while((len = in.read(tmp)) != -1 && !cc.finish) {
out.write(tmp, 0, len);
}
}
} else {
out.println("HTTP/1.0 404 Not Found");
System. out. println("[" + ip + "][Server]: HTTP/1.0 404 Not Found");
}
}
if(!uq) {
out.println("HTTP/1.0 400 Bad Request");
System. out. println("[" + ip + "][Server]: HTTP/1.0 400 Bad Request");
}
}
}
|
|