Express 静态文件中间件在 IE 含中文的 GET 请求时出现 Bad Request
发布于 12 年前 作者 jiyinyiyong 4812 次浏览 最后一次编辑是 9 年前

确切说是 soundmanager2 的 fallback 模式通过 Flash 请求一个文件 在 Chrome 里是正常的, 不确定是因为 Flash 请求还是 IE 内核的关系 我抓了 req.url 出来是下面这样, 以及对应的报错:

/s/mp3/%D7%B7%C3%CE%C8%CB.mp3
Error: Bad Request
    at SendStream.error (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/node_modules/send/lib/send.js:142:16)
    at SendStream.pipe (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/node_modules/send/lib/send.js:295:31)
    at Object.static (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/lib/middleware/static.js:83:8)
    at next (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at pass (/opt/app/feel-dev/server/node_modules/express/lib/router/index.js:108:24)
    at Router._dispatch (/opt/app/feel-dev/server/node_modules/express/lib/router/index.js:170:5)
    at Object.router (/opt/app/feel-dev/server/node_modules/express/lib/router/index.js:33:10)
    at next (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at Object.handle (/opt/app/feel-dev/server/server.coffee:16:12)
    at next (/opt/app/feel-dev/server/node_modules/express/node_modules/connect/lib/proto.js:190:15)

soundmanager2 的报错是

SMSound._onload(): "/s/mp3/追梦人.mp3" failed to load? 

express 服务器上的脚本片段是:

app.use (req, res, next) ->
  # req.url = decodeURI req.url
  show req.url
  next()

app.use '/s', express.static(__dirname + '/..')
app.use '/s', express.directory(__dirname + '/..')

这种错误好邪门的感觉 然后我尝试直接用 IE 访问 mp3 文件对应网址… 自动调用 Media Player 打开了 难道还是 Flash 问题… 不知道通过中间件有没有办法解决.?

回到顶部