HTTP响应截断

This commit is contained in:
yang
2024-08-26 16:56:32 +08:00
parent 83e71dc5d6
commit 1482809b0f

View File

@@ -436,6 +436,11 @@ public class CourseFileApi extends ApiBaseController {
response.reset();
//由于火狐和其他浏览器显示名称的方式不相同,需要进行不同的编码处理
if (agent.indexOf("FIREFOX") != -1) {//火狐浏览器
// 检查文件名中是否包含不允许的字符
if (fileName.matches(".*[\n\r;%].*")) {
throw new IllegalArgumentException("Filename contains illegal characters");
}
response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("GB2312"), "ISO-8859-1"));
} else {//其他浏览器
response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));