comparison src/goodjava/webserver/Status.java @ 1402:27efb1fcbcb5

move luan.lib to goodjava
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 17 Sep 2019 01:35:01 -0400
parents src/luan/lib/webserver/Status.java@643cf1c37723
children 8a7519dee55c
comparison
equal deleted inserted replaced
1401:ef1620aa99cb 1402:27efb1fcbcb5
1 package goodjava.webserver;
2
3 import java.util.Map;
4 import java.util.HashMap;
5 import goodjava.logging.Logger;
6 import goodjava.logging.LoggerFactory;
7
8
9 public class Status {
10 private static final Logger logger = LoggerFactory.getLogger(Status.class);
11
12 public final int code;
13 public final String reason;
14
15 public Status(int code,String reason) {
16 this.code = code;
17 this.reason = reason;
18 }
19
20 private static final Map<Integer,Status> map = new HashMap<Integer,Status>();
21
22 protected static Status newStatus(int code,String reason) {
23 Status status = new Status(code,reason);
24 map.put(code,status);
25 return status;
26 }
27
28 public static Status getStatus(int code) {
29 Status status = map.get(code);
30 if( status == null ) {
31 logger.warn("missing status "+code);
32 status = new Status(code,"");
33 }
34 return status;
35 }
36
37 public static final Status OK = newStatus(200,"OK");
38 public static final Status MOVED_PERMANENTLY = newStatus(301,"Moved Permanently");
39 public static final Status FOUND = newStatus(302,"Found");
40 public static final Status BAD_REQUEST = newStatus(400,"Bad Request");
41 public static final Status NOT_FOUND = newStatus(404,"Not Found");
42 public static final Status INTERNAL_SERVER_ERROR = newStatus(500,"Internal Server Error");
43 }