I implement a REST API as follow. Browser - as a client - could not executes my javascripts given from mentioned REST and prints errors such as Refused to execute script from 'http://localhost:8083/vendor.js' because its MIME type ('') is not executable, and strict MIME type checking is enabled
. It means that MIME type is not set for response while I set content-type for response but it is applied.
@RequestMapping(value = "/{resoucePath:.+}", method = RequestMethod.GET)
public void getResouce(@PathVariable String resoucePath, HttpServletResponse response) {
String myPath = ...; // I set resource path here
File resouce = new File(myPath);
try {
InputStream is = new FileInputStream(resouce);
IOUtils.copy(is, response.getOutputStream());
response.setContentType(mimeTypesMap.getContentType(resouce));
response.flushBuffer();
} catch (IOException ex) {
// log error
throw new RuntimeException("IOError writing file to output stream", ex);
}
}
What is my mistake? Why content-type is not set in response?