Where people come together to learn, code, and play. Custom-built HTTP server, site generator, and website from scratch using no external libraries. Goal is to be as minimalistic and fun as possible.
http://projectdivar.com
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
2.2 KiB
40 lines
2.2 KiB
try {
|
|
socket = new ServerSocket(sigPlace.PORT);
|
|
System.out.println("Listening on port "+sigPlace.PORT+".");
|
|
while (true) {
|
|
try (Socket client = socket.accept()) {
|
|
System.out.println("New client connection detected: "+client.toString());
|
|
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
|
|
String requestLine,line;
|
|
ZonedDateTime modifiedDate = null;
|
|
String boundary="";
|
|
boolean truncateUntilBoundary=false;
|
|
requestLine=in.readLine(); //Read the first line, this should be our request.
|
|
if (requestLine!=null) {
|
|
while (in.ready()) {
|
|
line=in.readLine();
|
|
|
|
if (!truncateUntilBoundary) {
|
|
System.out.println(line);
|
|
|
|
if (boundary.length()>0) {
|
|
if (line.equals(boundary)) {
|
|
truncateUntilBoundary=true;
|
|
}
|
|
}
|
|
} else
|
|
if (line.contains(boundary)) {
|
|
System.out.println("<...>");
|
|
System.out.println("");
|
|
System.out.println(line);
|
|
truncateUntilBoundary=false;
|
|
} else
|
|
if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) {
|
|
System.out.println(line);
|
|
}
|
|
|
|
if (line.contains("Content-Type: multipart/form-data; boundary=")) {
|
|
boundary="--"+line.substring("Content-Type: multipart/form-data; boundary=".length());
|
|
} else
|
|
if (line.contains("If-Modified-Since: ")) {
|
|
String modifiedSince=line.replace("If-Modified-Since: ","");
|
|
|