diff options
author | yankee <yzeugs@cipher-code.de> | 2014-04-20 22:21:34 +0200 |
---|---|---|
committer | yankee <yzeugs@cipher-code.de> | 2014-04-20 22:21:34 +0200 |
commit | 67e24e482b132ff0a8618f96b43097c9ce5f2776 (patch) | |
tree | 97614329f9e59b244089ac3c858437f2b83501fe | |
parent | 852318439539b54ee6b4ce048df63b6c12cf0417 (diff) | |
download | nanohttpd-67e24e482b132ff0a8618f96b43097c9ce5f2776.tar.gz |
Extracted interface from Status enum, so that people can use custom status codes
-rw-r--r-- | core/src/main/java/fi/iki/elonen/NanoHTTPD.java | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java index 35690ed..e1ad214 100644 --- a/core/src/main/java/fi/iki/elonen/NanoHTTPD.java +++ b/core/src/main/java/fi/iki/elonen/NanoHTTPD.java @@ -549,7 +549,7 @@ public abstract class NanoHTTPD { /** * HTTP status code after processing, e.g. "200 OK", HTTP_OK */ - private Status status; + private IStatus status; /** * MIME type of content, e.g. "text/html" */ @@ -581,7 +581,7 @@ public abstract class NanoHTTPD { /** * Basic constructor. */ - public Response(Status status, String mimeType, InputStream data) { + public Response(IStatus status, String mimeType, InputStream data) { this.status = status; this.mimeType = mimeType; this.data = data; @@ -590,7 +590,7 @@ public abstract class NanoHTTPD { /** * Convenience method that makes an InputStream out of given text. */ - public Response(Status status, String mimeType, String txt) { + public Response(IStatus status, String mimeType, String txt) { this.status = status; this.mimeType = mimeType; try { @@ -689,7 +689,7 @@ public abstract class NanoHTTPD { } } - public Status getStatus() { + public IStatus getStatus() { return status; } @@ -724,11 +724,16 @@ public abstract class NanoHTTPD { public void setChunkedTransfer(boolean chunkedTransfer) { this.chunkedTransfer = chunkedTransfer; } + + public interface IStatus { + int getRequestStatus(); + String getDescription(); + } /** * Some HTTP response status codes */ - public enum Status { + public enum Status implements IStatus { OK(200, "OK"), CREATED(201, "Created"), ACCEPTED(202, "Accepted"), NO_CONTENT(204, "No Content"), PARTIAL_CONTENT(206, "Partial Content"), REDIRECT(301, "Moved Permanently"), NOT_MODIFIED(304, "Not Modified"), BAD_REQUEST(400, "Bad Request"), UNAUTHORIZED(401, "Unauthorized"), FORBIDDEN(403, "Forbidden"), NOT_FOUND(404, "Not Found"), METHOD_NOT_ALLOWED(405, "Method Not Allowed"), RANGE_NOT_SATISFIABLE(416, @@ -741,10 +746,12 @@ public abstract class NanoHTTPD { this.description = description; } + @Override public int getRequestStatus() { return this.requestStatus; } + @Override public String getDescription() { return "" + this.requestStatus + " " + description; } |