Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Demo里的BUG #37

Merged
merged 3 commits into from
Oct 31, 2018
Merged

修复Demo里的BUG #37

merged 3 commits into from
Oct 31, 2018

Conversation

haochuan9421
Copy link
Contributor

  1. 修复因没有记录policyStr而导致的expiredTime无效问题。你判断了tempKeysCache.expiredTime - Date.now() / 1000 > 30tempKeysCache.policyStr === policyStr这两个条件,但empKeysCache.policyStr自始至终都是'',所以过期时间并没有效果,这样即使没过期,依然会再次请求。

  2. 修复 [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client 的报错. 如果你需要设置404的状态码,使用res.status(404)即可,res.writeHead(404);res.send('404 Not Found')会导致Cannot set headers after they are sent to the client 的报错

@carsonxu carsonxu merged commit 198bb79 into tencentyun:master Oct 31, 2018
@carsonxu
Copy link
Collaborator

感谢提交

@haochuan9421
Copy link
Contributor Author

  1. 之前我误以为你Demo里403的错误是因为计算签名不对而导致的,后来仔细看了一下并不是,所以把这个PR关闭了。定位到真的原因其实是你把req.query.query写成了req.query.method导致的,对照了一下PHP的代码,这里你可能希望取到请求体或者查询字符串里的pathnamemethodqueryheaders这些字段,但是可能是笔误吧,才出现了上述的错误,导致后面计算签名时并没有得到正确的签名结果。
  2. 我还给encodeURIComponent(policyStr)后面添加了.replace(/\*/g,'%2A'),这是因为 JS 的encodeURIComponent('*')或者encodeURI('*')的结果依然是'*',而PHP的是urlencode('*')的结果是'%2A',两种语言还是有所差异的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants