Added basic HTML generation and response handling.
[jrw.git] / src / jrw / util / Http.java
index a5843d5..cadd856 100644 (file)
@@ -1,7 +1,29 @@
 package jrw.util;
 
+import java.util.*;
+
 public class Http {
     public static final java.nio.charset.Charset UTF8 = java.nio.charset.Charset.forName("UTF-8");
     public static final java.nio.charset.Charset LATIN1 = java.nio.charset.Charset.forName("ISO-8859-1");
     public static final java.nio.charset.Charset ASCII = java.nio.charset.Charset.forName("US-ASCII");
+    public static final Map<Integer, StatusInfo> statusinfo;
+
+    public static class StatusInfo {
+       public final String status, message;
+       public StatusInfo(String status, String message) {this.status = status; this.message = message;}
+    }
+
+    static {
+       Map<Integer, StatusInfo> buf = new HashMap<>();
+       buf.put(400, new StatusInfo("Bad Request", "Invalid HTTP request."));
+       buf.put(401, new StatusInfo("Unauthorized", "Authentication must be provided for the requested resource.."));
+       buf.put(403, new StatusInfo("Forbidden", "You ar enot authorized for the requested resource."));
+       buf.put(404, new StatusInfo("Not Found", "The requested resource was not found."));
+       buf.put(405, new StatusInfo("Method Not Allowed", "The request method is not valid or permitted by the requested resource."));
+       buf.put(429, new StatusInfo("Too Many Requests", "Your client is sending more frequent requests than are accepted."));
+       buf.put(500, new StatusInfo("Server Error", "An internal error occurred."));
+       buf.put(501, new StatusInfo("Not Implemented", "The requested functionality has not been implemented."));
+       buf.put(503, new StatusInfo("Service Unavailable", "Service is being denied at this time."));
+       statusinfo = Collections.unmodifiableMap(buf);
+    }
 }