{"action":"created","comment":{"url":"https://api.github.com/repos/request/request/pulls/comments/23136567","id":23136567,"diff_hunk":"@@ -0,0 +1,135 @@\n+'use strict'\n+\n+var uuid = require('node-uuid')\n+  , helpers = require('./helpers')\n+\n+var md5 = helpers.md5\n+  , toBase64 = helpers.toBase64\n+\n+\n+function Auth (request) {\n+  this._request = request\n+\n+  this._hasAuth = undefined\n+  this._sentAuth = undefined\n+  this._bearer = undefined\n+  this._user = undefined\n+  this._pass = undefined\n+}\n+\n+Auth.prototype.basic = function (user, pass, sendImmediately) {\n+  var self = this\n+  if (typeof user !== 'string' || (pass !== undefined && typeof pass !== 'string')) {\n+    throw new Error('auth() received invalid user or password')\n+  }\n+  self._user = user\n+  self._pass = pass\n+  self._hasAuth = true\n+  var header = typeof pass !== 'undefined' ? user + ':' + pass : user\n+  if (sendImmediately || typeof sendImmediately === 'undefined') {\n+    self._request.setHeader('authorization', 'Basic ' + toBase64(header))\n+    self._sentAuth = true\n+  }\n+}\n+\n+Auth.prototype.bearer = function (bearer, sendImmediately) {\n+  var self = this\n+  self._bearer = bearer\n+  self._hasAuth = true\n+  if (sendImmediately || typeof sendImmediately === 'undefined') {\n+    if (typeof bearer === 'function') {\n+      bearer = bearer()\n+    }\n+    self._request.setHeader('authorization', 'Bearer ' + bearer)\n+    self._sentAuth = true\n+  }\n+}\n+\n+Auth.prototype._digest = function (authHeader) {","path":"lib/auth.js","position":48,"original_position":48,"commit_id":"a0ff4e1ea03c717bd78a6e4ca9e5700c52b0246b","original_commit_id":"a0ff4e1ea03c717bd78a6e4ca9e5700c52b0246b","user":{"login":"nylen","id":227022,"avatar_url":"https://avatars.githubusercontent.com/u/227022?v=3","gravatar_id":"","url":"https://api.github.com/users/nylen","html_url":"https://github.com/nylen","followers_url":"https://api.github.com/users/nylen/followers","following_url":"https://api.github.com/users/nylen/following{/other_user}","gists_url":"https://api.github.com/users/nylen/gists{/gist_id}","starred_url":"https://api.github.com/users/nylen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nylen/subscriptions","organizations_url":"https://api.github.com/users/nylen/orgs","repos_url":"https://api.github.com/users/nylen/repos","events_url":"https://api.github.com/users/nylen/events{/privacy}","received_events_url":"https://api.github.com/users/nylen/received_events","type":"User","site_admin":false},"body":"s/`_digest`/`digest`/ to better match the naming of the other functions","created_at":"2015-01-18T20:33:24Z","updated_at":"2015-01-18T20:33:24Z","html_url":"https://github.com/request/request/pull/1360#discussion_r23136567","pull_request_url":"https://api.github.com/repos/request/request/pulls/1360","_links":{"self":{"href":"https://api.github.com/repos/request/request/pulls/comments/23136567"},"html":{"href":"https://github.com/request/request/pull/1360#discussion_r23136567"},"pull_request":{"href":"https://api.github.com/repos/request/request/pulls/1360"}}},"pull_request":{"url":"https://api.github.com/repos/request/request/pulls/1360","id":27562704,"html_url":"https://github.com/request/request/pull/1360","diff_url":"https://github.com/request/request/pull/1360.diff","patch_url":"https://github.com/request/request/pull/1360.patch","issue_url":"https://api.github.com/repos/request/request/issues/1360","number":1360,"state":"open","locked":false,"title":"Refactor basic, bearer, digest auth logic into separate class","user":{"login":"simov","id":1694112,"avatar_url":"https://avatars.githubusercontent.com/u/1694112?v=3","gravatar_id":"","url":"https://api.github.com/users/simov","html_url":"https://github.com/simov","followers_url":"https://api.github.com/users/simov/followers","following_url":"https://api.github.com/users/simov/following{/other_user}","gists_url":"https://api.github.com/users/simov/gists{/gist_id}","starred_url":"https://api.github.com/users/simov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simov/subscriptions","organizations_url":"https://api.github.com/users/simov/orgs","repos_url":"https://api.github.com/users/simov/repos","events_url":"https://api.github.com/users/simov/events{/privacy}","received_events_url":"https://api.github.com/users/simov/received_events","type":"User","site_admin":false},"body":"**WIP**\r\n\r\nI moved the `auth` method logic into separate file. The `auth` method is split into two methods `basic` and `bearer`. Also I moved `_digest` and the part of the code in `onRequestResponse` related to these 3 methods.\r\n\r\nThe reasons to move exactly these functions is as follows: all private flags `_hasAuth`, ` _sentAuth` and private variables `_bearer`,` _user`, `_pass` are local for the `Auth` class. That way `request` now knows only about only 3 distinct methods `_auth.basic`, `_auth.bearer` and `_auth.response` versus 6 variables `_hasAuth`, `_sentAuth`, `_bearer`, `_user`, `_pass` and `_digest`\r\n\r\nThe `Auth` class keeps a pointer to the `request` instance, but only use it to modify the headers, as well as reading some values (as I said private variables related to the `Auth` class are not set in `request`)\r\n\r\nOther than that the code is mostly copy/pasted without changes, it certainly can be improved but I wanted to make this PR as short as possible. Also the `debug` call is currently commented out.\r\n\r\nPing @nylen @seanstrom @FredKSchott ","created_at":"2015-01-17T21:41:32Z","updated_at":"2015-01-18T20:33:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"59a3c9a573af3092bfe70a812b18f3cb9ad8f3fd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/request/request/pulls/1360/commits","review_comments_url":"https://api.github.com/repos/request/request/pulls/1360/comments","review_comment_url":"https://api.github.com/repos/request/request/pulls/comments/{number}","comments_url":"https://api.github.com/repos/request/request/issues/1360/comments","statuses_url":"https://api.github.com/repos/request/request/statuses/a0ff4e1ea03c717bd78a6e4ca9e5700c52b0246b","head":{"label":"simov:refactor-auth","ref":"refactor-auth","sha":"a0ff4e1ea03c717bd78a6e4ca9e5700c52b0246b","user":{"login":"simov","id":1694112,"avatar_url":"https://avatars.githubusercontent.com/u/1694112?v=3","gravatar_id":"","url":"https://api.github.com/users/simov","html_url":"https://github.com/simov","followers_url":"https://api.github.com/users/simov/followers","following_url":"https://api.github.com/users/simov/following{/other_user}","gists_url":"https://api.github.com/users/simov/gists{/gist_id}","starred_url":"https://api.github.com/users/simov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simov/subscriptions","organizations_url":"https://api.github.com/users/simov/orgs","repos_url":"https://api.github.com/users/simov/repos","events_url":"https://api.github.com/users/simov/events{/privacy}","received_events_url":"https://api.github.com/users/simov/received_events","type":"User","site_admin":false},"repo":{"id":25289791,"name":"request","full_name":"simov/request","owner":{"login":"simov","id":1694112,"avatar_url":"https://avatars.githubusercontent.com/u/1694112?v=3","gravatar_id":"","url":"https://api.github.com/users/simov","html_url":"https://github.com/simov","followers_url":"https://api.github.com/users/simov/followers","following_url":"https://api.github.com/users/simov/following{/other_user}","gists_url":"https://api.github.com/users/simov/gists{/gist_id}","starred_url":"https://api.github.com/users/simov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simov/subscriptions","organizations_url":"https://api.github.com/users/simov/orgs","repos_url":"https://api.github.com/users/simov/repos","events_url":"https://api.github.com/users/simov/events{/privacy}","received_events_url":"https://api.github.com/users/simov/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/simov/request","description":"Simplified HTTP request client.","fork":true,"url":"https://api.github.com/repos/simov/request","forks_url":"https://api.github.com/repos/simov/request/forks","keys_url":"https://api.github.com/repos/simov/request/keys{/key_id}","collaborators_url":"https://api.github.com/repos/simov/request/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/simov/request/teams","hooks_url":"https://api.github.com/repos/simov/request/hooks","issue_events_url":"https://api.github.com/repos/simov/request/issues/events{/number}","events_url":"https://api.github.com/repos/simov/request/events","assignees_url":"https://api.github.com/repos/simov/request/assignees{/user}","branches_url":"https://api.github.com/repos/simov/request/branches{/branch}","tags_url":"https://api.github.com/repos/simov/request/tags","blobs_url":"https://api.github.com/repos/simov/request/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/simov/request/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/simov/request/git/refs{/sha}","trees_url":"https://api.github.com/repos/simov/request/git/trees{/sha}","statuses_url":"https://api.github.com/repos/simov/request/statuses/{sha}","languages_url":"https://api.github.com/repos/simov/request/languages","stargazers_url":"https://api.github.com/repos/simov/request/stargazers","contributors_url":"https://api.github.com/repos/simov/request/contributors","subscribers_url":"https://api.github.com/repos/simov/request/subscribers","subscription_url":"https://api.github.com/repos/simov/request/subscription","commits_url":"https://api.github.com/repos/simov/request/commits{/sha}","git_commits_url":"https://api.github.com/repos/simov/request/git/commits{/sha}","comments_url":"https://api.github.com/repos/simov/request/comments{/number}","issue_comment_url":"https://api.github.com/repos/simov/request/issues/comments/{number}","contents_url":"https://api.github.com/repos/simov/request/contents/{+path}","compare_url":"https://api.github.com/repos/simov/request/compare/{base}...{head}","merges_url":"https://api.github.com/repos/simov/request/merges","archive_url":"https://api.github.com/repos/simov/request/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/simov/request/downloads","issues_url":"https://api.github.com/repos/simov/request/issues{/number}","pulls_url":"https://api.github.com/repos/simov/request/pulls{/number}","milestones_url":"https://api.github.com/repos/simov/request/milestones{/number}","notifications_url":"https://api.github.com/repos/simov/request/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/simov/request/labels{/name}","releases_url":"https://api.github.com/repos/simov/request/releases{/id}","created_at":"2014-10-16T06:43:16Z","updated_at":"2015-01-08T02:18:53Z","pushed_at":"2015-01-17T21:36:06Z","git_url":"git://github.com/simov/request.git","ssh_url":"git@github.com:simov/request.git","clone_url":"https://github.com/simov/request.git","svn_url":"https://github.com/simov/request","homepage":"","size":2014,"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":"request:master","ref":"master","sha":"f0b7f75e9ff40cd67d6f361c1448ee4df71de4f6","user":{"login":"request","id":730467,"avatar_url":"https://avatars.githubusercontent.com/u/730467?v=3","gravatar_id":"","url":"https://api.github.com/users/request","html_url":"https://github.com/request","followers_url":"https://api.github.com/users/request/followers","following_url":"https://api.github.com/users/request/following{/other_user}","gists_url":"https://api.github.com/users/request/gists{/gist_id}","starred_url":"https://api.github.com/users/request/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/request/subscriptions","organizations_url":"https://api.github.com/users/request/orgs","repos_url":"https://api.github.com/users/request/repos","events_url":"https://api.github.com/users/request/events{/privacy}","received_events_url":"https://api.github.com/users/request/received_events","type":"Organization","site_admin":false},"repo":{"id":1283503,"name":"request","full_name":"request/request","owner":{"login":"request","id":730467,"avatar_url":"https://avatars.githubusercontent.com/u/730467?v=3","gravatar_id":"","url":"https://api.github.com/users/request","html_url":"https://github.com/request","followers_url":"https://api.github.com/users/request/followers","following_url":"https://api.github.com/users/request/following{/other_user}","gists_url":"https://api.github.com/users/request/gists{/gist_id}","starred_url":"https://api.github.com/users/request/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/request/subscriptions","organizations_url":"https://api.github.com/users/request/orgs","repos_url":"https://api.github.com/users/request/repos","events_url":"https://api.github.com/users/request/events{/privacy}","received_events_url":"https://api.github.com/users/request/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/request/request","description":"Simplified HTTP request client.","fork":false,"url":"https://api.github.com/repos/request/request","forks_url":"https://api.github.com/repos/request/request/forks","keys_url":"https://api.github.com/repos/request/request/keys{/key_id}","collaborators_url":"https://api.github.com/repos/request/request/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/request/request/teams","hooks_url":"https://api.github.com/repos/request/request/hooks","issue_events_url":"https://api.github.com/repos/request/request/issues/events{/number}","events_url":"https://api.github.com/repos/request/request/events","assignees_url":"https://api.github.com/repos/request/request/assignees{/user}","branches_url":"https://api.github.com/repos/request/request/branches{/branch}","tags_url":"https://api.github.com/repos/request/request/tags","blobs_url":"https://api.github.com/repos/request/request/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/request/request/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/request/request/git/refs{/sha}","trees_url":"https://api.github.com/repos/request/request/git/trees{/sha}","statuses_url":"https://api.github.com/repos/request/request/statuses/{sha}","languages_url":"https://api.github.com/repos/request/request/languages","stargazers_url":"https://api.github.com/repos/request/request/stargazers","contributors_url":"https://api.github.com/repos/request/request/contributors","subscribers_url":"https://api.github.com/repos/request/request/subscribers","subscription_url":"https://api.github.com/repos/request/request/subscription","commits_url":"https://api.github.com/repos/request/request/commits{/sha}","git_commits_url":"https://api.github.com/repos/request/request/git/commits{/sha}","comments_url":"https://api.github.com/repos/request/request/comments{/number}","issue_comment_url":"https://api.github.com/repos/request/request/issues/comments/{number}","contents_url":"https://api.github.com/repos/request/request/contents/{+path}","compare_url":"https://api.github.com/repos/request/request/compare/{base}...{head}","merges_url":"https://api.github.com/repos/request/request/merges","archive_url":"https://api.github.com/repos/request/request/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/request/request/downloads","issues_url":"https://api.github.com/repos/request/request/issues{/number}","pulls_url":"https://api.github.com/repos/request/request/pulls{/number}","milestones_url":"https://api.github.com/repos/request/request/milestones{/number}","notifications_url":"https://api.github.com/repos/request/request/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/request/request/labels{/name}","releases_url":"https://api.github.com/repos/request/request/releases{/id}","created_at":"2011-01-23T01:25:14Z","updated_at":"2015-01-18T19:23:07Z","pushed_at":"2015-01-17T00:53:18Z","git_url":"git://github.com/request/request.git","ssh_url":"git@github.com:request/request.git","clone_url":"https://github.com/request/request.git","svn_url":"https://github.com/request/request","homepage":"","size":5484,"stargazers_count":6453,"watchers_count":6453,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":832,"mirror_url":null,"open_issues_count":74,"forks":832,"open_issues":74,"watchers":6453,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/request/request/pulls/1360"},"html":{"href":"https://github.com/request/request/pull/1360"},"issue":{"href":"https://api.github.com/repos/request/request/issues/1360"},"comments":{"href":"https://api.github.com/repos/request/request/issues/1360/comments"},"review_comments":{"href":"https://api.github.com/repos/request/request/pulls/1360/comments"},"review_comment":{"href":"https://api.github.com/repos/request/request/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/request/request/pulls/1360/commits"},"statuses":{"href":"https://api.github.com/repos/request/request/statuses/a0ff4e1ea03c717bd78a6e4ca9e5700c52b0246b"}}}}