starting
This commit is contained in:
parent
7b4a8d8bd0
commit
a0de379fb6
1 changed files with 21 additions and 10 deletions
|
@ -92,9 +92,28 @@ final class HttpRequest implements Runnable
|
||||||
System.out.println(" " + requestLine);
|
System.out.println(" " + requestLine);
|
||||||
|
|
||||||
String[] tokens = requestLine.split(" ");
|
String[] tokens = requestLine.split(" ");
|
||||||
|
|
||||||
|
String response = "";
|
||||||
|
if(tokens[0].equals(HTTP_METHOD.GET)){
|
||||||
|
response += HTTPVERSION + " ";
|
||||||
|
FileInputStream filein;
|
||||||
|
try{
|
||||||
|
filein = new FileInputStream(tokens[1]);
|
||||||
|
response += "200 OK "+CRLF+"kottedala"+CRLF;
|
||||||
|
outs.writeChars(response);
|
||||||
|
sendBytes(filein,outs);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException e){
|
||||||
|
response += "404 Not Found"+CRLF+"kottedala"+CRLF;
|
||||||
|
outs.writeChars(response);
|
||||||
|
// throw e;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
outs.writeChars(response + "400 Bad Request"+CRLF+"kotten"+CRLF);
|
||||||
|
|
||||||
// for(String token : tokens)
|
// for(String token : tokens)
|
||||||
// System.out.println("---> " + token);
|
// System.out.println("---> " + token);
|
||||||
sendResponse(tokens[1],outs);
|
// sendResponse(tokens[1],outs);
|
||||||
|
|
||||||
|
|
||||||
// Close streams and sockets
|
// Close streams and sockets
|
||||||
|
@ -102,14 +121,6 @@ final class HttpRequest implements Runnable
|
||||||
br.close();
|
br.close();
|
||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendResponse(String f,DataOutputStream outs)
|
|
||||||
throws Exception{
|
|
||||||
String response = HTTPVERSION+" 200 OK "+CRLF+"kottedala"+CRLF;
|
|
||||||
outs.writeChars(response);
|
|
||||||
sendBytes(new FileInputStream(f),outs);
|
|
||||||
|
|
||||||
}
|
|
||||||
private static void sendBytes(FileInputStream fins,
|
private static void sendBytes(FileInputStream fins,
|
||||||
OutputStream outs) throws Exception
|
OutputStream outs) throws Exception
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue