【发布时间】:2015-10-09 17:00:49
【问题描述】:
简介
我有 spring MVC 应用程序,我正在从控制器加载图像。为了安全起见,我在我的 Spring 应用程序中添加了X-Content-Type-Options:nosniff
通过在springConfig xml中设置如下<security:content-type-options/>
问题:在这个 IE 没有加载控制器响应的图像之后。我怀疑响应中未设置内容类型。因为另一个响应 X-Content-Type-Options:nosniff 和 Content-Type:image/png; 的站点工作正常。
试一试 我试图更改我的控制器以设置内容类型。但它没有发生。
@RequestMapping(value = "/getUserImage" , produces = org.springframework.http.MediaType.IMAGE_PNG_VALUE)
public @ResponseBody
void getUserImage(
@RequestParam(value = "userId", required = false) int userId,
HttpServletRequest request, HttpServletResponse response) {
try {
//Get file and add it to response
IOUtils.copy(inputStream, response.getOutputStream());
response.getOutputStream().flush();
response.setContentType(org.springframework.http.MediaType.IMAGE_PNG_VALUE);
response.setHeader("Content-Type","image/png");
response.flushBuffer();
inputStream.close();
} catch (Exception e){
}
}
TRY2 我尝试在方法拦截器中以相同的方式添加响应头,但仍然没有运气。
但在 Chrome 和 Firefox 中同样适用。
【问题讨论】: