/** * Set whether range requests (resumable downloads; media streaming) should be enabled. * @param enableRangeSupport true to enable range support * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.StaticHandler setEnableRangeSupport(boolean enableRangeSupport) { delegate.setEnableRangeSupport(enableRangeSupport); return this; }
/** * Set whether range requests (resumable downloads; media streaming) should be enabled. * @param enableRangeSupport true to enable range support * @return a reference to this, so the API can be used fluently */ public io.vertx.rxjava.ext.web.handler.StaticHandler setEnableRangeSupport(boolean enableRangeSupport) { delegate.setEnableRangeSupport(enableRangeSupport); return this; }
@Test public void testOutOfRangeRequestBody() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=15783-"), res -> res.bodyHandler(buff -> { assertEquals("bytes */15783", res.headers().get("Content-Range")); testComplete(); }), 416, "Requested Range Not Satisfiable", null); await(); }
@Test public void testRangeAwareRequestBodyForDisabledRangeSupport() throws Exception { stat.setEnableRangeSupport(false); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> res.bodyHandler(buff -> { assertNull(res.headers().get("Accept-Ranges")); assertNotSame("1000", res.headers().get("Content-Length")); assertNotSame(1000, buff.length()); testComplete(); }), 200, "OK", null); await(); }
@Test public void testRangeAwareRequestBody() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> res.bodyHandler(buff -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("1000", res.headers().get("Content-Length")); assertEquals("bytes 0-999/15783", res.headers().get("Content-Range")); assertEquals(1000, buff.length()); testComplete(); }), 206, "Partial Content", null); await(); }
@Test public void testRangeAwareRequestHeaders() throws Exception { stat.setEnableRangeSupport(true); // this is a 3 step test // 1. request a head to a static image, this should tell us the server supports ranges // 2. make a request of the 1st 1000 bytes // 3. request all bytes after 1000 // 4. request bytes from 1000 up to 5000000 if available (which isn't) testRequest(HttpMethod.HEAD, "/somedir/range.jpg", null, res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("15783", res.headers().get("Content-Length")); }, 200, "OK", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("1000", res.headers().get("Content-Length")); assertEquals("bytes 0-999/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=1000-"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("14783", res.headers().get("Content-Length")); assertEquals("bytes 1000-15782/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=1000-5000000"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("14783", res.headers().get("Content-Length")); assertEquals("bytes 1000-15782/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); }
@Test public void testRangeAwareRequestSegment() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.bin", req -> req.headers().set("Range", "bytes=0-1023"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges"));
@Test public void testOutOfRangeRequestBody() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=15783-"), res -> res.bodyHandler(buff -> { assertEquals("bytes */15783", res.headers().get("Content-Range")); testComplete(); }), 416, "Requested Range Not Satisfiable", null); await(); }
@Test public void testRangeAwareRequestBodyForDisabledRangeSupport() throws Exception { stat.setEnableRangeSupport(false); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> res.bodyHandler(buff -> { assertNull(res.headers().get("Accept-Ranges")); assertNotSame("1000", res.headers().get("Content-Length")); assertNotSame(1000, buff.length()); testComplete(); }), 200, "OK", null); await(); }
@Test public void testRangeAwareRequestBody() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> res.bodyHandler(buff -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("1000", res.headers().get("Content-Length")); assertEquals("bytes 0-999/15783", res.headers().get("Content-Range")); assertEquals(1000, buff.length()); testComplete(); }), 206, "Partial Content", null); await(); }
@Test public void testRangeAwareRequestHeaders() throws Exception { stat.setEnableRangeSupport(true); // this is a 3 step test // 1. request a head to a static image, this should tell us the server supports ranges // 2. make a request of the 1st 1000 bytes // 3. request all bytes after 1000 // 4. request bytes from 1000 up to 5000000 if available (which isn't) testRequest(HttpMethod.HEAD, "/somedir/range.jpg", null, res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("15783", res.headers().get("Content-Length")); }, 200, "OK", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=0-999"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("1000", res.headers().get("Content-Length")); assertEquals("bytes 0-999/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=1000-"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("14783", res.headers().get("Content-Length")); assertEquals("bytes 1000-15782/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); testRequest(HttpMethod.GET, "/somedir/range.jpg", req -> req.headers().set("Range", "bytes=1000-5000000"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges")); assertEquals("14783", res.headers().get("Content-Length")); assertEquals("bytes 1000-15782/15783", res.headers().get("Content-Range")); }, 206, "Partial Content", null); }
@Test public void testRangeAwareRequestSegment() throws Exception { stat.setEnableRangeSupport(true); testRequest(HttpMethod.GET, "/somedir/range.bin", req -> req.headers().set("Range", "bytes=0-1023"), res -> { assertEquals("bytes", res.headers().get("Accept-Ranges"));