-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpServerRequest.java
More file actions
38 lines (33 loc) · 1.15 KB
/
HttpServerRequest.java
File metadata and controls
38 lines (33 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
public class HttpServerRequest {
private String file = null;
private String host = null;
private boolean done = false;
private int line = 0;
public boolean isDone() { return done; }
public String getFile() { return file; }
public String getHost() { return host; }
public void process(String in)
{
if(line == 0){
//Splits the get request into three parts
String parts[] = in.split(" ");
//Checks for the get request and correct length
if(parts[0].trim().compareTo("GET") == 0 && parts.length >= 2){
file = parts[1].substring(1);
if(file.isEmpty()){
file = "index.html";
}
}
}
//Checks for the host header
if(in.startsWith("Host: ")){
host = in.substring(6);
}
//Checks for the end of the header
if (in == null || in.isEmpty()) {
done = true;
}
//System.out.println("Current Line: " + line + " Host: " + host + " file: " + file + " Done Status: " + done);
line++;
}
}