{"action":"created","comment":{"url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/comments/58996292","id":58996292,"diff_hunk":"@@ -44,7 +43,12 @@\n \n           onHeaders(res, function setHeaders() {\n             var session = null;\n-            var user = av.User.current();\n+            var user = res.user;\n+\n+            if (user === undefined) {","path":"middleware/cookie-session.js","position":30,"original_position":30,"commit_id":"3a19122e5c0e4d2f01f8dae11371089d8f48fb3c","original_commit_id":"3a19122e5c0e4d2f01f8dae11371089d8f48fb3c","user":{"login":"jysperm","id":1191561,"avatar_url":"https://avatars.githubusercontent.com/u/1191561?v=3","gravatar_id":"","url":"https://api.github.com/users/jysperm","html_url":"https://github.com/jysperm","followers_url":"https://api.github.com/users/jysperm/followers","following_url":"https://api.github.com/users/jysperm/following{/other_user}","gists_url":"https://api.github.com/users/jysperm/gists{/gist_id}","starred_url":"https://api.github.com/users/jysperm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jysperm/subscriptions","organizations_url":"https://api.github.com/users/jysperm/orgs","repos_url":"https://api.github.com/users/jysperm/repos","events_url":"https://api.github.com/users/jysperm/events{/privacy}","received_events_url":"https://api.github.com/users/jysperm/received_events","type":"User","site_admin":false},"body":"是的，null 和 undefined 的行为不一样，接下来准备改掉这里，见最新的评论","created_at":"2016-04-08T08:46:37Z","updated_at":"2016-04-08T08:46:37Z","html_url":"https://github.com/leancloud/leanengine-node-sdk/pull/45#discussion_r58996292","pull_request_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45","_links":{"self":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/comments/58996292"},"html":{"href":"https://github.com/leancloud/leanengine-node-sdk/pull/45#discussion_r58996292"},"pull_request":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45"}}},"pull_request":{"url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45","id":55852200,"html_url":"https://github.com/leancloud/leanengine-node-sdk/pull/45","diff_url":"https://github.com/leancloud/leanengine-node-sdk/pull/45.diff","patch_url":"https://github.com/leancloud/leanengine-node-sdk/pull/45.patch","issue_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/45","number":45,"state":"open","locked":false,"title":"Disable current user","user":{"login":"jysperm","id":1191561,"avatar_url":"https://avatars.githubusercontent.com/u/1191561?v=3","gravatar_id":"","url":"https://api.github.com/users/jysperm","html_url":"https://github.com/jysperm","followers_url":"https://api.github.com/users/jysperm/followers","following_url":"https://api.github.com/users/jysperm/following{/other_user}","gists_url":"https://api.github.com/users/jysperm/gists{/gist_id}","starred_url":"https://api.github.com/users/jysperm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jysperm/subscriptions","organizations_url":"https://api.github.com/users/jysperm/orgs","repos_url":"https://api.github.com/users/jysperm/repos","events_url":"https://api.github.com/users/jysperm/events{/privacy}","received_events_url":"https://api.github.com/users/jysperm/received_events","type":"User","site_admin":false},"body":"实现了 https://github.com/leancloud/leanengine-node-sdk/issues/38#issuecomment-167204370 中设计的改动。\r\n\r\n首先这个 PR 将依赖的 JS SDK 升级到了 1.x 版本，1.x 版本使用了 http/https 模块代替原来的 xmlhttprequest 模块来发请求，同时默认开启 keepAlive.\r\n\r\n为了减少和 JS SDK 重复的代码，删去了对 AV._ajax 的重写，这个重写的主要目的是修改 User Agent，因此打算等待 JS SDK 提供修改 User Agent 的配置项。\r\n\r\n* [ ] 所以在正式发布前需要完成几个 JS SDK 的修改 https://github.com/leancloud/javascript-sdk/issues/251\r\n\r\n## disableCurrentUser\r\n这个 PR 会默认启用 JS SDK 的 disableCurrentUser 选项：\r\n* [x] AV.User.logOut, AV.User.current, AV.User._saveCurrentUser 不会向 domain 和全局变量写入数据；AV.User._saveCurrentUser 在被调用时会抛出异常。\r\n* [x] Cookie Session 中间件将会从 request 和 response 对象上读取要写回的用户信息，而不是从 domain; 也不会向 domain 和全局变量写入数据，在没有 domain 的时候不会创建 domain\r\n\r\n## 从 request 和 response 对象上操作用户信息\r\n* [x] 重构了云函数的 request 和 response, 可以在所有的云函数和 Hook 中得到结构一致的 request 和 response 对象\r\n* [x] 新增 req.currentUser(), req.getSessionToken() 两个 API 用户从请求对象上获取来自的客户端的用户信息，这些方法在云函数和普通路由中均可使用\r\n* [x] 新增 res.currentUser()（和 req.currentUser() 的不同是它获取的是将要写回到客户端的用户）、res.saveCurrentUser()（设置要写回客户端的用户），这些方法在云函数和普通路由中均可使用\r\n\r\n## 测试\r\n* [x] 已通过所有现有测试\r\n* [x] 移除了之前对 AV.User.current 的测试（改为了只测 request 上的 user），因为在 disableCurrentUser 之后，这个测试总是失败的。\r\n* [x] 添加自动测试确认了 req.currentUser 等方法的行为\r\n\r\n## 文档和 Demo\r\n* [x] 文档中添加标题为「在多用户（Node.js）环境下使用 JS SDK 」的段落，介绍 JS SDK 中相关方法所打印的警告的含义、为什么多用户环境下不能使用 currentUser、Node SDK 之前是如何实现 currentUser 的以及存在哪些问题、新版本中应该如何从 request 和 response 对象上操作用户信息、升级时需要注意的检查清单。草稿在 https://github.com/leancloud/cloud-code/issues/761\r\n* [ ] 更新 node-js-getting-started 等示例项目的代码，目前先更新了一下 leanengine-todo-demo 这个项目： https://github.com/leancloud/leanengine-todo-demo/pull/1\r\n","created_at":"2016-01-13T04:03:22Z","updated_at":"2016-04-08T08:46:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bb2af9bcf5aae4babdd3f3dab0705883825bd218","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45/commits","review_comments_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45/comments","review_comment_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/45/comments","statuses_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/statuses/3a19122e5c0e4d2f01f8dae11371089d8f48fb3c","head":{"label":"jysperm:disable-current-user","ref":"disable-current-user","sha":"3a19122e5c0e4d2f01f8dae11371089d8f48fb3c","user":{"login":"jysperm","id":1191561,"avatar_url":"https://avatars.githubusercontent.com/u/1191561?v=3","gravatar_id":"","url":"https://api.github.com/users/jysperm","html_url":"https://github.com/jysperm","followers_url":"https://api.github.com/users/jysperm/followers","following_url":"https://api.github.com/users/jysperm/following{/other_user}","gists_url":"https://api.github.com/users/jysperm/gists{/gist_id}","starred_url":"https://api.github.com/users/jysperm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jysperm/subscriptions","organizations_url":"https://api.github.com/users/jysperm/orgs","repos_url":"https://api.github.com/users/jysperm/repos","events_url":"https://api.github.com/users/jysperm/events{/privacy}","received_events_url":"https://api.github.com/users/jysperm/received_events","type":"User","site_admin":false},"repo":{"id":44002396,"name":"leanengine-node-sdk","full_name":"jysperm/leanengine-node-sdk","owner":{"login":"jysperm","id":1191561,"avatar_url":"https://avatars.githubusercontent.com/u/1191561?v=3","gravatar_id":"","url":"https://api.github.com/users/jysperm","html_url":"https://github.com/jysperm","followers_url":"https://api.github.com/users/jysperm/followers","following_url":"https://api.github.com/users/jysperm/following{/other_user}","gists_url":"https://api.github.com/users/jysperm/gists{/gist_id}","starred_url":"https://api.github.com/users/jysperm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jysperm/subscriptions","organizations_url":"https://api.github.com/users/jysperm/orgs","repos_url":"https://api.github.com/users/jysperm/repos","events_url":"https://api.github.com/users/jysperm/events{/privacy}","received_events_url":"https://api.github.com/users/jysperm/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jysperm/leanengine-node-sdk","description":"LeanEngine node.js SDK","fork":true,"url":"https://api.github.com/repos/jysperm/leanengine-node-sdk","forks_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/forks","keys_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/teams","hooks_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/hooks","issue_events_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/events","assignees_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/tags","blobs_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/languages","stargazers_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/stargazers","contributors_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/contributors","subscribers_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/subscribers","subscription_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/subscription","commits_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/merges","archive_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/downloads","issues_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/labels{/name}","releases_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/jysperm/leanengine-node-sdk/deployments","created_at":"2015-10-10T08:41:21Z","updated_at":"2015-10-10T08:41:22Z","pushed_at":"2016-04-07T09:29:34Z","git_url":"git://github.com/jysperm/leanengine-node-sdk.git","ssh_url":"git@github.com:jysperm/leanengine-node-sdk.git","clone_url":"https://github.com/jysperm/leanengine-node-sdk.git","svn_url":"https://github.com/jysperm/leanengine-node-sdk","homepage":"https://leancloud.cn","size":133,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"leancloud:master","ref":"master","sha":"d870875ad8e6eafbb8a2497d0061478f3ef38dca","user":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"repo":{"id":36006623,"name":"leanengine-node-sdk","full_name":"leancloud/leanengine-node-sdk","owner":{"login":"leancloud","id":6660518,"avatar_url":"https://avatars.githubusercontent.com/u/6660518?v=3","gravatar_id":"","url":"https://api.github.com/users/leancloud","html_url":"https://github.com/leancloud","followers_url":"https://api.github.com/users/leancloud/followers","following_url":"https://api.github.com/users/leancloud/following{/other_user}","gists_url":"https://api.github.com/users/leancloud/gists{/gist_id}","starred_url":"https://api.github.com/users/leancloud/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leancloud/subscriptions","organizations_url":"https://api.github.com/users/leancloud/orgs","repos_url":"https://api.github.com/users/leancloud/repos","events_url":"https://api.github.com/users/leancloud/events{/privacy}","received_events_url":"https://api.github.com/users/leancloud/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/leancloud/leanengine-node-sdk","description":"LeanEngine node.js SDK","fork":false,"url":"https://api.github.com/repos/leancloud/leanengine-node-sdk","forks_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/forks","keys_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/teams","hooks_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/hooks","issue_events_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/events{/number}","events_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/events","assignees_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/assignees{/user}","branches_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/branches{/branch}","tags_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/tags","blobs_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/git/refs{/sha}","trees_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/statuses/{sha}","languages_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/languages","stargazers_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/stargazers","contributors_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/contributors","subscribers_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/subscribers","subscription_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/subscription","commits_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/commits{/sha}","git_commits_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/git/commits{/sha}","comments_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/comments{/number}","issue_comment_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/comments{/number}","contents_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/contents/{+path}","compare_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/merges","archive_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/downloads","issues_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues{/number}","pulls_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls{/number}","milestones_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/milestones{/number}","notifications_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/labels{/name}","releases_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/releases{/id}","deployments_url":"https://api.github.com/repos/leancloud/leanengine-node-sdk/deployments","created_at":"2015-05-21T10:29:57Z","updated_at":"2016-03-25T06:01:53Z","pushed_at":"2016-04-07T09:29:34Z","git_url":"git://github.com/leancloud/leanengine-node-sdk.git","ssh_url":"git@github.com:leancloud/leanengine-node-sdk.git","clone_url":"https://github.com/leancloud/leanengine-node-sdk.git","svn_url":"https://github.com/leancloud/leanengine-node-sdk","homepage":"https://leancloud.cn","size":146,"stargazers_count":20,"watchers_count":20,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":9,"forks":9,"open_issues":9,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45"},"html":{"href":"https://github.com/leancloud/leanengine-node-sdk/pull/45"},"issue":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/45"},"comments":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/issues/45/comments"},"review_comments":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45/comments"},"review_comment":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/pulls/45/commits"},"statuses":{"href":"https://api.github.com/repos/leancloud/leanengine-node-sdk/statuses/3a19122e5c0e4d2f01f8dae11371089d8f48fb3c"}}}}