It then sets the resource path and MIME type in the shared state for the JS connector to read, which sets the source of the MEJS player. Simple enough.
I’d like to try this fix but can’t figure out how to set HTTP headers for the VaadinResponse, specifically targeting responses to requests for resources my connector registers. Is this possible? Any other ideas on what’s going on here?
For those interested I did this by implementing a simple Filter. It isn’t very targeted and adds the header to all requests for any connector resource, but it does fix the problem.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
final HttpServletRequest httpRequest = (HttpServletRequest) request;
final HttpServletResponse httpResponse = (HttpServletResponse) response;
final String requestUri = httpRequest.getRequestURI();
if (requestUri.matches("/.*APP/connector/[0-9]
+/[0-9]
+/0/.*")) {
httpResponse.addHeader("Accept-Ranges", "bytes");
}
chain.doFilter(request, response);
}
Could there be any harmful side effects? I’m also not sure if it’s a good idea to package this in with the addon or provide sample code to users needing this functionality.
After a closer look at the methods exposed by AbstractJavaScriptComponent I found the best solution is to override handleConnectorRequest. Wish I would have found this sonner!
You can obviously target specific connector resources with this. In my implementation I also catch IOExceptions which occur when the client aborts connections to a resource - these were thrown each time the source of the player changed. Hope this helps someone.