-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpStatus.java
More file actions
49 lines (38 loc) · 1.94 KB
/
Copy pathHttpStatus.java
File metadata and controls
49 lines (38 loc) · 1.94 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
package httpserver;
public class HttpStatus {
public int code;
public String message;
public String detail;
public HttpStatus(int statusCode, String statusMessage) {
code = statusCode;
message = statusMessage;
detail = "";
}
public boolean equals(HttpStatus otherStatus) {
return code == otherStatus.code;
}
public void setDetail(String statusDetail) {
detail = statusDetail;
}
public String toResponseLine() {
return String.format("HTTP/1.1 %1d %2s", code, message);
}
public String toResponseBody() {
return String.format("%1d %2s: %3s", code, message, detail);
}
static HttpStatus OK() { return new HttpStatus(200, "OK");}
static HttpStatus Created() { return new HttpStatus(201, "Created");}
static HttpStatus NoContent() { return new HttpStatus(204, "No Content");}
static HttpStatus MovedPermanently() { return new HttpStatus(301, "MovedvPermanently");}
static HttpStatus NotModified() { return new HttpStatus(304, "Not Modified");}
static HttpStatus TemporaryRedirect() { return new HttpStatus(307, "Temporary Redirect");}
static HttpStatus BadRequest() { return new HttpStatus(400, "Bad Request");}
static HttpStatus Forbidden() { return new HttpStatus(403, "Forbidden");}
static HttpStatus NotFound() { return new HttpStatus(404, "Not Found");}
static HttpStatus MethodNotAllowed() { return new HttpStatus(405, "Method Not Allowed");}
static HttpStatus PreconditionFailed() { return new HttpStatus(412, "Precondition Failed");}
static HttpStatus ServerError() { return new HttpStatus(500, "Server Error");}
static HttpStatus NotImplemented() { return new HttpStatus(501, "Not Implemented");}
static HttpStatus ServiceUnvavailable() { return new HttpStatus(503, "Service Unvavailable");}
static HttpStatus HttpVersionNotSupported() { return new HttpStatus(505, "HTTP Version Not Supported");}
}