forked from codesquad-members-2021/java-was
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestLine.java
More file actions
57 lines (44 loc) · 1.61 KB
/
RequestLine.java
File metadata and controls
57 lines (44 loc) · 1.61 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package webserver.http.startline;
import webserver.http.attribute.Attributes;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
public class RequestLine extends StartLine {
private static final String METHOD_KEY = "method";
private static final String PATH_KEY = "path";
public RequestLine(Attributes statusLineAttributes) {
super(statusLineAttributes);
}
public static RequestLine from(List<String> statusLine) {
Attributes statusLineAttributes = new Attributes();
statusLineAttributes.add(METHOD_KEY, statusLine.get(0));
statusLineAttributes.add(PATH_KEY, statusLine.get(1));
statusLineAttributes.add(PROTOCOL_VERSION_KEY, statusLine.get(2));
return new RequestLine(statusLineAttributes);
}
public String getMethod() {
return getAttributeBy(METHOD_KEY);
}
private URI getUri() {
try {
return new URI(getAttributeBy(PATH_KEY));
} catch (URISyntaxException e) {
throw new IllegalStateException("Request의 Path가 올바르지 않음. path : " + getPath(), e);
}
}
public String getPath() {
return getUri().getPath();
}
public String getQueryString() {
return Objects.toString(getUri().getQuery(), "");
}
@Override
public String toString() {
return new StringJoiner(" ").add(getMethod())
.add(getPath())
.add(getProtocol())
.toString();
}
}