Turn the HTTP method into an enumeration.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Oct 2010 06:08:57 +0000 (08:08 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Oct 2010 06:08:57 +0000 (08:08 +0200)
src/main/java/net/pterodactylus/sone/web/page/Page.java
src/main/java/net/pterodactylus/sone/web/page/PageToadlet.java

index a1125cc..8f2a4d7 100644 (file)
@@ -58,11 +58,42 @@ public interface Page {
         */
        public class Request {
 
+               /**
+                * Enumeration for all possible HTTP request methods.
+                *
+                * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’
+                *         Roden</a>
+                */
+               public enum Method {
+
+                       /** GET. */
+                       GET,
+
+                       /** POST. */
+                       POST,
+
+                       /** PUT. */
+                       PUT,
+
+                       /** DELETE. */
+                       DELETE,
+
+                       /** HEAD. */
+                       HEAD,
+
+                       /** OPTIONS. */
+                       OPTIONS,
+
+                       /** TRACE. */
+                       TRACE,
+
+               }
+
                /** The URI that was accessed. */
                private final URI uri;
 
                /** The HTTP method that was used. */
-               private final String method;
+               private final Method method;
 
                /** The HTTP request. */
                private final HTTPRequest httpRequest;
@@ -82,7 +113,7 @@ public interface Page {
                 * @param toadletContext
                 *            The toadlet context of the request
                 */
-               public Request(URI uri, String method, HTTPRequest httpRequest, ToadletContext toadletContext) {
+               public Request(URI uri, Method method, HTTPRequest httpRequest, ToadletContext toadletContext) {
                        this.uri = uri;
                        this.method = method;
                        this.httpRequest = httpRequest;
@@ -103,7 +134,7 @@ public interface Page {
                 * 
                 * @return The HTTP method
                 */
-               public String getMethod() {
+               public Method getMethod() {
                        return method;
                }
 
index af826f1..57a3439 100644 (file)
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.net.URI;
 import java.util.Map.Entry;
 
+import net.pterodactylus.sone.web.page.Page.Request.Method;
 import freenet.client.HighLevelSimpleClient;
 import freenet.clients.http.LinkEnabledCallback;
 import freenet.clients.http.Toadlet;
@@ -99,7 +100,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
         *             if the toadlet context is closed
         */
        public void handleMethodGET(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
-               handleRequest(new Page.Request(uri, "GET", httpRequest, toadletContext));
+               handleRequest(new Page.Request(uri, Method.GET, httpRequest, toadletContext));
        }
 
        /**
@@ -117,7 +118,7 @@ public class PageToadlet extends Toadlet implements LinkEnabledCallback {
         *             if the toadlet context is closed
         */
        public void handleMethodPOST(URI uri, HTTPRequest httpRequest, ToadletContext toadletContext) throws IOException, ToadletContextClosedException {
-               handleRequest(new Page.Request(uri, "POST", httpRequest, toadletContext));
+               handleRequest(new Page.Request(uri, Method.POST, httpRequest, toadletContext));
        }
 
        /**