gvsu/cs654/lab3/partA/HttpRequest.java
josh a82373c0fe cs654/lab3 partA finished
git-svn-id: svn://anubis/gvsu@4 45c1a28c-8058-47b2-ae61-ca45b979098e
2008-02-03 02:47:51 +00:00

54 lines
1.3 KiB
Java

import java.io.* ;
import java.net.* ;
import java.util.* ;
final class HttpRequest implements Runnable {
final static String CRLF = "\r\n";
Socket socket;
// Constructor
public HttpRequest(Socket socket) throws Exception {
this.socket = socket;
}
// Implement the run() method of the Runnable interface.
public void run()
{
try {
processRequest();
} catch (Exception e) {
System.out.println(e);
}
}
private void processRequest() throws Exception {
// Set up output stream
DataOutputStream os = new DataOutputStream(socket.getOutputStream());
// Set up input stream filters.
BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
// Get the request line of the HTTP request message.
String requestLine = br.readLine();
// Display the request line.
System.out.println();
System.out.println(requestLine);
// Get and display the header lines.
String headerLine = null;
while ((headerLine = br.readLine()).length() != 0) {
System.out.println(headerLine);
}
// Close streams and socket.
os.close();
br.close();
socket.close();
}
}