assertEquals(UNBOUNDED_BODY_SIZE, data.getBodyContentLength()); // Should be the full length, not the trimmed one
assertEquals(LONG_BODY_SIZE, data.getBodyContentLength()); // Should be the full length, not the trimmed one
assertEquals( UNBOUNDED_BODY_SIZE, data.getBodyContentLength()); // Should be the full length, not the trimmed one
@Test public void testWithLongBody() throws Exception { chain = new MockFilterChain( new HttpServlet() { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { req.getInputStream().read(new byte[LONG_BODY_SIZE]); res.getOutputStream().write("hello".getBytes()); } }); StringBuilder b = new StringBuilder(); for (int i = 0; i < MAX_BODY_SIZE; i++) { b.append('b'); } String wanted_body = b.toString(); for (int i = MAX_BODY_SIZE; i < LONG_BODY_SIZE; i++) { b.append('b'); } String given_body = b.toString(); HttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", given_body, null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals( wanted_body, new String(data.getBody())); // Should be trimmed to the maximum length assertEquals( LONG_BODY_SIZE, data.getBodyContentLength()); // Should be the full length, not the trimmed one }
public void testWithBody() throws Exception { chain.setServlet(new HttpServlet() { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { req.getInputStream().read(new byte[LONG_BODY_SIZE]); res.getOutputStream().write("hello".getBytes()); } }); HttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", "baz", null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertNull(data.getHttpReferer()); assertEquals(new String(data.getBody()), "baz"); assertEquals(3, data.getBodyContentLength()); assertEquals(5, data.getResponseLength()); } public void testWithLongBody() throws Exception {
@Test public void testWithBody() throws Exception { chain = new MockFilterChain( new HttpServlet() { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { req.getInputStream().read(new byte[LONG_BODY_SIZE]); res.getOutputStream().write("hello".getBytes()); } }); HttpServletRequest req = request("POST", "/bar/foo", "78.56.34.12", "baz", null); filter.doFilter(req, response(), chain); RequestData data = dao.getLast(); assertEquals("POST", data.getHttpMethod()); assertEquals("/bar/foo", data.getPath()); assertEquals("78.56.34.12", data.getRemoteAddr()); assertNull(data.getHttpReferer()); assertEquals(new String(data.getBody()), "baz"); assertEquals(3, data.getBodyContentLength()); assertEquals(5, data.getResponseLength()); }