-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpMessage.java
More file actions
46 lines (36 loc) · 1.13 KB
/
HttpMessage.java
File metadata and controls
46 lines (36 loc) · 1.13 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
package core;
import util.LinkedCaseInsensitiveMap;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.regex.Pattern;
public abstract class HttpMessage {
public String requestMethod;
public String httpVersion;
public Map<String, String> headers = new LinkedCaseInsensitiveMap();
String body;
public Charset bodyCharset = StandardCharsets.ISO_8859_1;
public HttpStatusCode responseStatusCode;
public String getHeader(String header) {
return headers.get(header);
}
public void setHeader(String header, String value) {
this.headers.put(header, value);
}
public int calculateContentLength() {
return body == null ? 0 : body.getBytes(bodyCharset).length;
}
public String getBody() {
return body;
}
public void setBody(String body) {
this.body = body;
}
public boolean contentHeadersAreCorrect() {
if (body == null && !"HEAD".equals(requestMethod))
for(String key : headers.keySet())
if (Pattern.compile("Content-.*", Pattern.CASE_INSENSITIVE).matcher(key).matches())
return false;
return true;
}
}