use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServing.
@Test
void byteServing() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=2-4");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.PARTIAL_CONTENT, res.getStatus());
assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
assertNull(res.getHeaders().get("Content-Disposition"));
final byte[] responseBody = ((ByteSource) res.getBody()).read();
final byte[] mediaBytesData = mediaBytes.read();
assertEquals(3, responseBody.length);
assertArrayEquals(new byte[] { mediaBytesData[2], mediaBytesData[3], mediaBytesData[4] }, responseBody);
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServingInvalidRange.
@Test
void byteServingInvalidRange() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=many");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.REQUESTED_RANGE_NOT_SATISFIABLE, res.getStatus());
assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
assertNull(res.getBody());
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServingSuffixLength.
@Test
void byteServingSuffixLength() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=-3");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.PARTIAL_CONTENT, res.getStatus());
assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
assertNull(res.getHeaders().get("Content-Disposition"));
final byte[] responseBody = ((ByteSource) res.getBody()).read();
final byte[] mediaBytesData = mediaBytes.read();
assertEquals(4, responseBody.length);
assertArrayEquals(new byte[] { mediaBytesData[3], mediaBytesData[4], mediaBytesData[5], mediaBytesData[6] }, responseBody);
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method cacheHeader_fingerprint_missmatch.
@Test
void cacheHeader_fingerprint_missmatch() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456:123456/logo.png");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertThat(res.getHeaders()).doesNotContainKey("Cache-Control");
}
use of com.enonic.xp.portal.PortalResponse in project xp by enonic.
the class AttachmentHandlerTest method byteServingSuffixFrom.
@Test
void byteServingSuffixFrom() throws Exception {
this.request.setEndpointPath("/_/attachment/inline/123456/logo.png");
this.request.getHeaders().put("Range", "bytes=4-");
final PortalResponse res = (PortalResponse) this.handler.handle(this.request, PortalResponse.create().build(), null);
assertNotNull(res);
assertEquals(HttpStatus.PARTIAL_CONTENT, res.getStatus());
assertEquals(MediaType.PNG.withoutParameters(), res.getContentType());
assertEquals("bytes", res.getHeaders().get("accept-ranges"));
assertNull(res.getHeaders().get("Content-Disposition"));
final byte[] responseBody = ((ByteSource) res.getBody()).read();
final byte[] mediaBytesData = mediaBytes.read();
assertEquals(3, responseBody.length);
assertArrayEquals(new byte[] { mediaBytesData[4], mediaBytesData[5], mediaBytesData[6] }, responseBody);
}
Aggregations