changeset 1155:4100304340bc

minor
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 04 Feb 2018 20:53:07 -0700
parents bbad9a21277c
children 3839ecc130ea
files src/luan/webserver/Status.java
diffstat 1 files changed, 28 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
diff -r bbad9a21277c -r 4100304340bc src/luan/webserver/Status.java
--- a/src/luan/webserver/Status.java	Sun Feb 04 20:34:56 2018 -0700
+++ b/src/luan/webserver/Status.java	Sun Feb 04 20:53:07 2018 -0700
@@ -1,7 +1,14 @@
 package luan.webserver;
 
+import java.util.Map;
+import java.util.HashMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 public class Status {
+	private static final Logger logger = LoggerFactory.getLogger(Status.class);
+
 	public final int code;
 	public final String reason;
 
@@ -10,7 +17,25 @@
 		this.reason = reason;
 	}
 
-	public static final Status OK = new Status(200,"OK");
-	public static final Status NOT_FOUND = new Status(404,"Not Found");
-	public static final Status INTERNAL_SERVER_ERROR = new Status(500,"Internal Server Error");
+	private static final Map<Integer,Status> map = new HashMap<Integer,Status>();
+
+	protected static Status newStatus(int code,String reason) {
+		Status status = new Status(code,reason);
+		map.put(code,status);
+		return status;
+	}
+
+	public static Status getStatus(int code) {
+		Status status = map.get(code);
+		if( status == null ) {
+			logger.warn("missing status "+code);
+			status = new Status(code,"");
+		}
+		return status;
+	}
+
+	public static final Status OK = newStatus(200,"OK");
+	public static final Status MOVED_PERMANENTLY = newStatus(301,"Moved Permanently");
+	public static final Status NOT_FOUND = newStatus(404,"Not Found");
+	public static final Status INTERNAL_SERVER_ERROR = newStatus(500,"Internal Server Error");
 }