diff --git a/src/com/googlecode/utterlyidle/examples/HelloWorld.java b/src/com/googlecode/utterlyidle/examples/HelloWorld.java index 65619fdc..43f4840c 100644 --- a/src/com/googlecode/utterlyidle/examples/HelloWorld.java +++ b/src/com/googlecode/utterlyidle/examples/HelloWorld.java @@ -21,6 +21,7 @@ import com.googlecode.utterlyidle.annotations.FormParam; import com.googlecode.utterlyidle.annotations.GET; import com.googlecode.utterlyidle.annotations.HeaderParam; +import com.googlecode.utterlyidle.annotations.OPTIONS; import com.googlecode.utterlyidle.annotations.PATCH; import com.googlecode.utterlyidle.annotations.POST; import com.googlecode.utterlyidle.annotations.PUT; @@ -82,6 +83,12 @@ public Response getx(@QueryParam("name") String name) { return response(Status.OK).header("greeting", hello(name)).entity("").build(); } + @OPTIONS + @Path("helloworld/options") + public String options(@QueryParam("name") @DefaultValue("James") String name) { + return hello(name); + } + @GET @Path("helloworld/queryparam") public String get(@QueryParam("name") @DefaultValue("Matt") String name) { diff --git a/src/com/googlecode/utterlyidle/rendering/OPTIONS.st b/src/com/googlecode/utterlyidle/rendering/OPTIONS.st new file mode 100644 index 00000000..ed4de40c --- /dev/null +++ b/src/com/googlecode/utterlyidle/rendering/OPTIONS.st @@ -0,0 +1 @@ +
OPTIONS $resource.path$
diff --git a/test/com/googlecode/utterlyidle/ServerContract.java b/test/com/googlecode/utterlyidle/ServerContract.java index f100b387..44081133 100644 --- a/test/com/googlecode/utterlyidle/ServerContract.java +++ b/test/com/googlecode/utterlyidle/ServerContract.java @@ -39,6 +39,7 @@ import static com.googlecode.utterlyidle.RequestBuilder.delete; import static com.googlecode.utterlyidle.RequestBuilder.get; import static com.googlecode.utterlyidle.RequestBuilder.head; +import static com.googlecode.utterlyidle.RequestBuilder.options; import static com.googlecode.utterlyidle.RequestBuilder.patch; import static com.googlecode.utterlyidle.RequestBuilder.post; import static com.googlecode.utterlyidle.RequestBuilder.put; @@ -149,6 +150,14 @@ public void preservesXForwardedProtoIfRequestHasOne() throws Exception { assertThat(result, is("https")); } + @Test + public void handlesOptions() throws Exception { + Response response = handle(options("helloworld/options").query("name", "foo"), server); + + assertThat(response.status(), is(Status.OK)); + assertThat(response.entity().toString(), is("Hello foo")); + } + @Test public void handlesGets() throws Exception { Response response = handle(get("helloworld/queryparam").query("name", "foo"), server);