Skip to content

Commit

Permalink
Added support for WebDAV specific HTTP methods.
Browse files Browse the repository at this point in the history
See also issue #109.
  • Loading branch information
s-ludwig committed Feb 25, 2013
1 parent 9bc2058 commit f08e515
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions source/vibe/http/common.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum HttpVersion {
}

enum HttpMethod {
// HTTP standard
GET,
HEAD,
PUT,
Expand All @@ -41,7 +42,16 @@ enum HttpMethod {
DELETE,
OPTIONS,
TRACE,
CONNECT
CONNECT,

// WEBDAV extensions
COPY,
LOCK,
MKCOL,
MOVE
PROPFIND,
PROPPATCH,
UNLOCK
}


Expand All @@ -50,12 +60,9 @@ enum HttpMethod {
*/
string httpMethodString(HttpMethod m)
{
static immutable strings = ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS", "TRACE", "CONNECT"];
static assert(m.max+1 == strings.length);
return strings[m];
return to!string(m);
}


/**
Returns the HttpMethod value matching the given HTTP method string.
*/
Expand All @@ -72,9 +79,25 @@ HttpMethod httpMethodFromString(string str)
case "OPTIONS": return HttpMethod.OPTIONS;
case "TRACE": return HttpMethod.TRACE;
case "CONNECT": return HttpMethod.CONNECT;
case "COPY": return HttpMethod.COPY;
case "LOCK": return HttpMethod.LOCK;
case "MKCOL": return HttpMethod.MKCOL;
case "MOVE": return HttpMethod.MOVE;
case "PROPFIND": return HttpMethod.PROPFIND;
case "PROPPATCH": return HttpMethod.PROPPATCH;
case "UNLOCK": return HttpMethod.UNLOCK;
}
}

unittest
{
assert(httpMethodString(HttpMethod.GET) == "GET");
assert(httpMethodString(HttpMethod.UNLOCK) == "UNLOCK");
assert(httpMethodFromString("GET") == HttpMethod.GET);
assert(httpMethodFromString("UNLOCK") == HttpMethod.UNLOCK);
}


/**
Utility function that throws a HttpStatusException if the _condition is not met.
*/
Expand Down

0 comments on commit f08e515

Please sign in to comment.