use of com.vaadin.flow.server.VaadinServletRequest in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method createRequestWithDestination.
private VaadinServletRequest createRequestWithDestination(String pathInfo, String fetchDest, String fetchMode) {
VaadinServletRequest req = createVaadinRequest(pathInfo);
Mockito.when(req.getHeader(Mockito.anyString())).thenAnswer(arg -> {
if ("Sec-Fetch-Dest".equals(arg.getArgument(0))) {
return fetchDest;
} else if ("Sec-Fetch-Mode".equals(arg.getArgument(0))) {
return fetchMode;
}
return null;
});
return req;
}
use of com.vaadin.flow.server.VaadinServletRequest in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method serviceWorkerRequest_canNotHandleRequest.
@Test
public void serviceWorkerRequest_canNotHandleRequest() {
IndexHtmlRequestHandler bootstrapHandler = new IndexHtmlRequestHandler();
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.when(request.getHeader(BootstrapHandler.SERVICE_WORKER_HEADER)).thenReturn("script");
Assert.assertFalse(bootstrapHandler.canHandleRequest(request));
}
use of com.vaadin.flow.server.VaadinServletRequest in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method synchronizedHandleRequest_badLocation_noUiCreated.
@Test
public void synchronizedHandleRequest_badLocation_noUiCreated() throws IOException {
final IndexHtmlRequestHandler bootstrapHandler = new IndexHtmlRequestHandler();
final VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.doAnswer(invocation -> "..**").when(request).getPathInfo();
final MockServletServiceSessionSetup.TestVaadinServletResponse response = mocks.createResponse();
final boolean value = bootstrapHandler.synchronizedHandleRequest(mocks.getSession(), request, response);
Assert.assertTrue("No further request handlers should be called", value);
Assert.assertEquals("Invalid status code reported", 400, response.getErrorCode());
Assert.assertEquals("Invalid message reported", "Invalid location: Relative path cannot contain .. segments", response.getErrorMessage());
}
use of com.vaadin.flow.server.VaadinServletRequest in project flow by vaadin.
the class IndexHtmlRequestHandlerTest method internal_request_no_bootstrap_page.
@Test
public void internal_request_no_bootstrap_page() {
VaadinServletRequest request = Mockito.mock(VaadinServletRequest.class);
Mockito.when(request.getPathInfo()).thenReturn(null);
Mockito.when(request.getParameter("v-r")).thenReturn("hello-foo-bar");
Assert.assertTrue(BootstrapHandler.isFrameworkInternalRequest(request));
Assert.assertFalse(indexHtmlRequestHandler.canHandleRequest(request));
Mockito.when(request.getParameter("v-r")).thenReturn("init");
Assert.assertTrue(BootstrapHandler.isFrameworkInternalRequest(request));
Assert.assertFalse(indexHtmlRequestHandler.canHandleRequest(request));
}
use of com.vaadin.flow.server.VaadinServletRequest in project flow by vaadin.
the class RemoveFallbackChunkInfo method handleRequest.
boolean handleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) {
VaadinServletRequest servletRequest = (VaadinServletRequest) request;
HttpServletRequest httpRequest = servletRequest.getHttpServletRequest();
String query = httpRequest.getQueryString();
if ("drop-fallback".equals(query)) {
// self check
FallbackChunk chunk = session.getService().getContext().getAttribute(FallbackChunk.class);
if (chunk == null) {
throw new RuntimeException("Vaadin context has no fallback chunk data");
}
// remove fallback chunk data to that the chunk won't be loaded
session.getService().getContext().removeAttribute(FallbackChunk.class);
}
return false;
}
Aggregations