public Response execute() throws IOException { return execute(0); }
public Response head() throws IOException { setMethod(ConnectionMethod.HEAD); return execute(); }
public Response put() throws IOException { setMethod(ConnectionMethod.PUT); return execute(); }
public Response head() throws IOException { setMethod(ConnectionMethod.HEAD); return execute(); }
public Response get() throws IOException { setMethod(ConnectionMethod.GET); return execute(); }
public Response post() throws IOException { setMethod(ConnectionMethod.POST); return execute(); }
public Response options() throws IOException { setMethod(ConnectionMethod.OPTIONS); return execute(); }
public Response get() throws IOException { setMethod(ConnectionMethod.GET); return execute(); }
public Response post() throws IOException { setMethod(ConnectionMethod.POST); return execute(); }
public Response trace() throws IOException { setMethod(ConnectionMethod.TRACE); return execute(); }
public Response delete() throws IOException { setMethod(ConnectionMethod.DELETE); return execute(); }
public Response trace() throws IOException { setMethod(ConnectionMethod.TRACE); return execute(); }
public Response put() throws IOException { setMethod(ConnectionMethod.PUT); return execute(); }
public Response delete() throws IOException { setMethod(ConnectionMethod.DELETE); return execute(); }
public Response options() throws IOException { setMethod(ConnectionMethod.OPTIONS); return execute(); }
@Test public void testMethod() throws IOException { handler = (request, response) -> response.setBody(request.method().name()); System.out.println("get"); Assert.assertEquals("GET", makeRequest("/").get().asString()); System.out.println("post"); Assert.assertEquals("POST", makeRequest("/").post().asString()); System.out.println("put"); Assert.assertEquals("PUT", makeRequest("/").method(ConnectionMethod.PUT).execute().asString()); System.out.println("delete"); Assert.assertEquals("DELETE", makeRequest("/").method(ConnectionMethod.DELETE).execute().asString()); }
@Test public void testHead() throws IOException { handler = (request, response) -> response.setBody("response"); com.wizzardo.tools.http.Response response = makeRequest("/").setMethod(ConnectionMethod.HEAD).execute(); Assert.assertEquals(200, response.getResponseCode()); Assert.assertEquals("8", response.header("Content-Length")); Assert.assertEquals("", response.asString()); Assert.assertEquals("response", makeRequest("/").get().asString()); }
@Test public void test_allowNothing_butOptions() throws IOException { handler = new UrlHandler() .append("/rest", new RestHandler().get(null)) ; Assert.assertEquals(405, makeRequest("/rest").get().getResponseCode()); Assert.assertEquals("OPTIONS", makeRequest("/rest").get().header("Allow")); Assert.assertEquals(405, makeRequest("/rest").method(ConnectionMethod.HEAD).execute().getResponseCode()); }
@Test public void test_allowGetAndDelete() throws IOException { handler = new UrlHandler() .append("/rest", new RestHandler() .get( (request, response) -> response.setBody("get") ) .delete( (request, response) -> response.setBody("delete") )) ; Assert.assertEquals("get", makeRequest("/rest").get().asString()); Assert.assertEquals("delete", makeRequest("/rest").method(ConnectionMethod.DELETE).execute().asString()); Assert.assertEquals(405, makeRequest("/rest").post().getResponseCode()); Assert.assertEquals("GET, HEAD, DELETE, OPTIONS", makeRequest("/rest").post().header("Allow")); }
@Test public void test_allowPostAndPut() throws IOException { handler = new UrlHandler() .append("/rest", new RestHandler() .post( (request, response) -> response.setBody("post") ) .put( (request, response) -> response.setBody("put") )) ; Assert.assertEquals("post", makeRequest("/rest").post().asString()); Assert.assertEquals("put", makeRequest("/rest").method(ConnectionMethod.PUT).execute().asString()); Assert.assertEquals(405, makeRequest("/rest").get().getResponseCode()); Assert.assertEquals("POST, PUT, OPTIONS", makeRequest("/rest").get().header("Allow")); Assert.assertEquals("POST, PUT, OPTIONS", makeRequest("/rest").options().header("Allow")); }