static void validateDataAndHeader(HttpRequest request, List<String> supportedContentTypes) {
        if (request.getData() == null)
            throw new BadRequestException("Request contains no data");

        String header = request.getHeader(ApplicationApiHandler.contentTypeHeader);
        if (header == null)
            throw new BadRequestException("Request contains no " + ApplicationApiHandler.contentTypeHeader + " header");

        ContentType contentType = ContentType.parse(header);
        if ( ! supportedContentTypes.contains(contentType.getMimeType()))
            throw new BadRequestException("Request contains invalid " + ApplicationApiHandler.contentTypeHeader +
                                                  " header (" + contentType.getMimeType() + "), only '[" +
                                                  String.join(", ", supportedContentTypes) + "]' are supported");
    }
@Test
    public void require_that_content_type_is_parsed_correctly() throws FileNotFoundException {
        HttpRequest request = post(new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8)),
                                   Map.of("Content-Type", "multipart/form-data; charset=ISO-8859-1; boundary=g5gJAzUWl_t6"),
                                   Map.of());

        // Valid header should validate ok
        SessionCreateHandler.validateDataAndHeader(request, List.of(ContentType.MULTIPART_FORM_DATA.getMimeType()));

        // Accepting only application/json should fail:
        try {
            SessionCreateHandler.validateDataAndHeader(request, List.of(ContentType.APPLICATION_JSON.getMimeType()));
            fail("Request contained invalid content type, but validated ok");
        } catch (Exception expected) {}
    }