diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 1b1f0ed..2a171ac 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -3,7 +3,11 @@
-
+
+
+
+
+
@@ -42,40 +46,41 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -149,10 +154,8 @@
-
-
@@ -167,12 +170,15 @@
-
-
+
+
+
+
+
@@ -266,7 +272,6 @@
-
@@ -279,9 +284,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -300,6 +338,11 @@
+
+
+
+
+
@@ -308,13 +351,8 @@
-
-
-
-
-
-
+
@@ -339,6 +377,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -782,15 +833,17 @@
-
+
+
-
-
-
+
+
+
+
@@ -814,11 +867,12 @@
+
-
+
@@ -848,13 +902,14 @@
+
-
+
-
+
@@ -862,7 +917,6 @@
-
@@ -875,7 +929,7 @@
-
+
@@ -884,7 +938,6 @@
-
@@ -967,13 +1020,6 @@
-
-
-
-
-
-
-
@@ -988,17 +1034,6 @@
-
-
-
-
-
-
-
-
-
-
-
@@ -1050,30 +1085,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1099,9 +1116,6 @@
-
-
-
@@ -1125,7 +1139,6 @@
-
@@ -1145,41 +1158,74 @@
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 3a1cc82..6aa101c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -5,7 +5,7 @@
com.iyanuadelekan
kanary
jar
- 0.9.0
+ 0.9.1
1.1.2-4
diff --git a/src/main/com/iyanuadelekan/kanary/core/KanaryRouter.kt b/src/main/com/iyanuadelekan/kanary/core/KanaryRouter.kt
index f542bcd..db9cdd3 100644
--- a/src/main/com/iyanuadelekan/kanary/core/KanaryRouter.kt
+++ b/src/main/com/iyanuadelekan/kanary/core/KanaryRouter.kt
@@ -24,6 +24,7 @@ class KanaryRouter(var basePath: String?= null, var routeController: KanaryContr
val putRouteList: RouteList = RouteList()
val patchRouteList: RouteList = RouteList()
val deleteRouteList: RouteList = RouteList()
+ val optionsRouteList: RouteList = RouteList()
/**
* Router function handling GET requests
@@ -85,6 +86,18 @@ class KanaryRouter(var basePath: String?= null, var routeController: KanaryContr
return this
}
+ /**
+ * Router function handling PATCH requests
+ * @param path Specified route path
+ * @param action Action to handle requests targeting specified route path
+ * @param controller Controller handling the route
+ * @return current instance of [KanaryRouter]
+ */
+ override fun options(path: String, action: (Request, HttpServletRequest, HttpServletResponse) -> Unit, controller: KanaryController?): KanaryRouter {
+ assembleAndQueueRoute(HttpConstants.OPTIONS.name, path, action, controller)
+ return this
+ }
+
/**
* Function used for route queuing
* adds a [route] based on its [method] to its appropriate route list
@@ -98,6 +111,7 @@ class KanaryRouter(var basePath: String?= null, var routeController: KanaryContr
HttpConstants.PUT.name -> putRouteList.add(route)
HttpConstants.DELETE.name -> deleteRouteList.add(route)
HttpConstants.PATCH.name -> patchRouteList.add(route)
+ HttpConstants.OPTIONS.name -> optionsRouteList.add(route)
else -> {
println("Unrecognized HTTP method: '$method'")
}
diff --git a/src/main/com/iyanuadelekan/kanary/handlers/AppHandler.kt b/src/main/com/iyanuadelekan/kanary/handlers/AppHandler.kt
index 16e5b21..147b520 100644
--- a/src/main/com/iyanuadelekan/kanary/handlers/AppHandler.kt
+++ b/src/main/com/iyanuadelekan/kanary/handlers/AppHandler.kt
@@ -35,27 +35,19 @@ class AppHandler(val app: KanaryApp): AbstractHandler() {
if (request != null) {
if(isMethodSupported(request.method)) {
- if(request.method == HttpConstants.OPTIONS.name) {
- response?.addHeader("Allow", "${HttpConstants.OPTIONS.name}, ${HttpConstants.GET.name}, " +
- "${HttpConstants.POST.name}, ${HttpConstants.PUT.name}, ${HttpConstants.DELETE.name}, " +
- HttpConstants.PATCH.name)
+ val route: Route? = resolveTargetRoute(request.method, "$target")
- response?. withStatus(200)?. send("")
- } else {
- val route: Route? = resolveTargetRoute(request.method, "$target")
-
- if (route != null) {
- val action = route.action
- executeBeforeAction(route, request, response)
-
- if(baseRequest != null && response != null) {
- action.invoke(baseRequest, request, response)
- }
+ if (route != null) {
+ val action = route.action
+ executeBeforeAction(route, request, response)
- executeAfterAction(route, request, response)
- } else {
- response?. withStatus(404)?. send("Method not found.")
+ if(baseRequest != null && response != null) {
+ action.invoke(baseRequest, request, response)
}
+
+ executeAfterAction(route, request, response)
+ } else {
+ response?. withStatus(404)?. send("Method not found.")
}
} else {
response?.addHeader("Allow", "${HttpConstants.OPTIONS.name}, ${HttpConstants.GET.name}, " +
@@ -119,6 +111,12 @@ class AppHandler(val app: KanaryApp): AbstractHandler() {
route = matchedRoutes[0]
}
}
+ HttpConstants.OPTIONS.name -> {
+ matchedRoutes = router.optionsRouteList.filter { it.path == formattedTarget }
+ if(matchedRoutes.isNotEmpty()) {
+ route = matchedRoutes[0]
+ }
+ }
}
} }
return route
diff --git a/src/main/com/iyanuadelekan/kanary/interfaces/RouterInterface.kt b/src/main/com/iyanuadelekan/kanary/interfaces/RouterInterface.kt
index bda0f05..3b06c36 100644
--- a/src/main/com/iyanuadelekan/kanary/interfaces/RouterInterface.kt
+++ b/src/main/com/iyanuadelekan/kanary/interfaces/RouterInterface.kt
@@ -27,4 +27,7 @@ interface RouterInterface {
fun patch(path: String, action: (Request, HttpServletRequest, HttpServletResponse) -> Unit,
controller: KanaryController?=null): KanaryRouter
+ fun options(path: String, action: (Request, HttpServletRequest, HttpServletResponse) -> Unit,
+ controller: KanaryController?=null): KanaryRouter
+
}
\ No newline at end of file
diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties
index 13d4241..085c529 100644
--- a/target/maven-archiver/pom.properties
+++ b/target/maven-archiver/pom.properties
@@ -1,5 +1,5 @@
#Generated by Maven
-#Thu Jun 01 20:20:29 WAT 2017
-version=0.9.0
+#Thu Jun 08 20:52:58 WAT 2017
+version=0.9.1
groupId=com.iyanuadelekan
artifactId=kanary