Skip to content

Commit

Permalink
Added HTTP PATCH support
Browse files Browse the repository at this point in the history
  • Loading branch information
Cody Ebberson committed Jun 24, 2016
1 parent 805e573 commit 2397f2f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 13 additions & 2 deletions jester.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ type
HttpDelete = "DELETE",
HttpHead = "HEAD",
HttpOptions = "OPTIONS",
HttpTrace = "TRACE"
HttpTrace = "TRACE",
HttpPatch = "PATCH"

CallbackAction* = enum
TCActionSend, TCActionRaw, TCActionPass, TCActionNothing
Expand Down Expand Up @@ -231,6 +232,8 @@ proc parseReqMethod(reqMethod: string, output: var ReqMeth): bool =
output = HttpOptions
of "trace":
output = HttpTrace
of "patch":
output = HttpPatch
else:
result = false

Expand Down Expand Up @@ -733,13 +736,14 @@ macro routes*(body: stmt): stmt {.immediate.} =
var caseStmtHeadBody = newNimNode(nnkStmtList)
var caseStmtOptionsBody = newNimNode(nnkStmtList)
var caseStmtTraceBody = newNimNode(nnkStmtList)
var caseStmtPatchBody = newNimNode(nnkStmtList)

for i in 0 .. <body.len:
case body[i].kind
of nnkCommand:
let cmdName = body[i][0].ident.`$`.normalize
case cmdName
of "get", "post", "put", "delete", "head", "options", "trace":
of "get", "post", "put", "delete", "head", "options", "trace", "patch":
case cmdName
of "get":
createRoute(body, caseStmtGetBody, i)
Expand All @@ -755,6 +759,8 @@ macro routes*(body: stmt): stmt {.immediate.} =
createRoute(body, caseStmtOptionsBody, i)
of "trace":
createRoute(body, caseStmtTraceBody, i)
of "patch":
createRoute(body, caseStmtPatchBody, i)
else:
discard
else:
Expand Down Expand Up @@ -799,6 +805,11 @@ macro routes*(body: stmt): stmt {.immediate.} =
ofBranchTrace.add caseStmtTraceBody
caseStmt.add ofBranchTrace

var ofBranchPatch = newNimNode(nnkOfBranch)
ofBranchPatch.add newIdentNode("HttpPatch")
ofBranchPatch.add caseStmtPatchBody
caseStmt.add ofBranchPatch

matchBody.add caseStmt

var matchProc = parseStmt("proc match(request: Request," &
Expand Down
5 changes: 5 additions & 0 deletions tests/alltest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,9 @@ routes:
get re"^\/([0-9]{2})\.html$":
resp request.matches[0]

patch "/patch":
body.add "Received: "
body.add($request.body)
status = Http200

runForever()

0 comments on commit 2397f2f

Please sign in to comment.