-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequest.java
executable file
·92 lines (71 loc) · 1.99 KB
/
Request.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.HashMap;
public class Request {
private String uri, verb, httpVersion;
private byte[] body;
private HashMap<String, String> headers;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getVerb() {
return verb;
}
public void setVerb(String verb) {
this.verb = verb;
}
public String getHttpVersion() {
return httpVersion;
}
public void setHttpVersion(String httpVersion) {
this.httpVersion = httpVersion;
}
public byte[] getBody() {
return body;
}
public void setBody(byte[] body) {
this.body = body;
}
public HashMap<String, String> getHeaders() {
return headers;
}
public void setHeaders(HashMap<String, String> headers) {
this.headers = headers;
}
public void parse(String line) {
}
public Request(String test) {
}
public Request(Socket client) throws IOException {
String line;
int lineCount = 0;
BufferedReader reader = new BufferedReader(
new InputStreamReader(client.getInputStream())
);
while ((line = reader.readLine()) != null && (line.length() != 0)) {
lineCount += 1;
if (lineCount == 1) {
parseInitialLine(line);
} else {
String[] header = line.split(": ");
if (headers == null) {
headers = new HashMap();
}
headers.put(header[0], header[1]);
System.out.println(line);
}
}
System.out.println();
}
public void parseInitialLine(String line) {
String[] request = line.split(" ");
setVerb(request[0]);
setUri(request[1]);
setHttpVersion(request[2]);
}
}