{"action":"created","comment":{"url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/comments/48387674","id":48387674,"diff_hunk":"@@ -1,18 +1,68 @@\n ﻿using System;\n using System.Net.Http;\n+using System.Net.Http.Headers;\n using System.Runtime.InteropServices;\n using System.Security;\n using System.Text;\n+using System.Threading;\n+using System.Threading.Tasks;\n \n namespace Docker.DotNet.BasicAuth\n {\n     public class BasicAuthCredentials : Credentials\n     {\n-        private readonly HttpMessageHandler _handler;\n-        private readonly SecureString _username;\n-        private readonly SecureString _password;\n+        private class BasicAuthHandler : HttpClientHandler\n+        {\n+            SecureString _username;\n+            SecureString _password;\n+\n+            public BasicAuthHandler(SecureString username, SecureString password)\n+            {\n+                _username = username;\n+                _password = password;\n+            }\n+\n+            protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)\n+            {\n+                request.Headers.Authorization = new AuthenticationHeaderValue(\"Basic\", BuildParameters());\n+\n+                return base.SendAsync(request, cancellationToken);\n+            }\n+\n+            private string BuildParameters()\n+            {\n+                string authInfo = string.Format(\"{0}:{1}\", ConvertToUnsecureString(_username),\n+                    ConvertToUnsecureString(_password));\n+\n+                return Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));\n+            }\n+\n+            private static string ConvertToUnsecureString(SecureString secureString)\n+            {\n+                IntPtr unmanagedString = IntPtr.Zero;\n+                try\n+                {\n+                    unmanagedString = Marshal.SecureStringToGlobalAllocUnicode(secureString);\n+                    return Marshal.PtrToStringUni(unmanagedString);\n+                }\n+                finally\n+                {\n+                    Marshal.ZeroFreeGlobalAllocUnicode(unmanagedString);\n+                }\n+            }\n+        }\n+\n+        private readonly BasicAuthHandler _handler;","path":"Docker.DotNet.BasicAuth/BasicAuthCredentials.cs","position":null,"original_position":58,"commit_id":"7d82100cb3f70942ed09c6388518af43e7190c12","original_commit_id":"0d45a37cb39bfb96cd7e1ca2c340582d2e922216","user":{"login":"ItsVeryWindy","id":6949430,"avatar_url":"https://avatars.githubusercontent.com/u/6949430?v=3","gravatar_id":"","url":"https://api.github.com/users/ItsVeryWindy","html_url":"https://github.com/ItsVeryWindy","followers_url":"https://api.github.com/users/ItsVeryWindy/followers","following_url":"https://api.github.com/users/ItsVeryWindy/following{/other_user}","gists_url":"https://api.github.com/users/ItsVeryWindy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsVeryWindy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsVeryWindy/subscriptions","organizations_url":"https://api.github.com/users/ItsVeryWindy/orgs","repos_url":"https://api.github.com/users/ItsVeryWindy/repos","events_url":"https://api.github.com/users/ItsVeryWindy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsVeryWindy/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2015-12-23T23:45:04Z","updated_at":"2015-12-23T23:45:04Z","html_url":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42#discussion_r48387674","pull_request_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42","_links":{"self":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/comments/48387674"},"html":{"href":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42#discussion_r48387674"},"pull_request":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42","id":54509636,"html_url":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42","diff_url":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42.diff","patch_url":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42.patch","issue_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/42","number":42,"state":"open","locked":false,"title":"Fix for defect where streams are being closed prematurely","user":{"login":"ItsVeryWindy","id":6949430,"avatar_url":"https://avatars.githubusercontent.com/u/6949430?v=3","gravatar_id":"","url":"https://api.github.com/users/ItsVeryWindy","html_url":"https://github.com/ItsVeryWindy","followers_url":"https://api.github.com/users/ItsVeryWindy/followers","following_url":"https://api.github.com/users/ItsVeryWindy/following{/other_user}","gists_url":"https://api.github.com/users/ItsVeryWindy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsVeryWindy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsVeryWindy/subscriptions","organizations_url":"https://api.github.com/users/ItsVeryWindy/orgs","repos_url":"https://api.github.com/users/ItsVeryWindy/repos","events_url":"https://api.github.com/users/ItsVeryWindy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsVeryWindy/received_events","type":"User","site_admin":false},"body":"When calling methods that return a stream, the stream cannot be read from due to HttpClient being disposed, which results in any requests still in flight being disposed of.\r\n\r\nI've done some refactoring so that HttpClient has only one instance and then the credential instances inject a httpmessagehandler rather than being responsible for creating the HttpClient.\r\n\r\nBecause I've had to make it a single instance I've had to make changes to the way timeouts work, so instead of setting the timeout value on HttpClient I configure the cancellation token to timeout which behaviour wise is the same.\r\n\r\nI've also added configure await on awaited calls just as it's considered good practice.","created_at":"2015-12-23T21:48:53Z","updated_at":"2015-12-23T23:45:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"05865dd849a43e9eb5a8d5e6bc08186e6d0dd7a9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42/commits","review_comments_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42/comments","review_comment_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/42/comments","statuses_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/statuses/7d82100cb3f70942ed09c6388518af43e7190c12","head":{"label":"ItsVeryWindy:master","ref":"master","sha":"7d82100cb3f70942ed09c6388518af43e7190c12","user":{"login":"ItsVeryWindy","id":6949430,"avatar_url":"https://avatars.githubusercontent.com/u/6949430?v=3","gravatar_id":"","url":"https://api.github.com/users/ItsVeryWindy","html_url":"https://github.com/ItsVeryWindy","followers_url":"https://api.github.com/users/ItsVeryWindy/followers","following_url":"https://api.github.com/users/ItsVeryWindy/following{/other_user}","gists_url":"https://api.github.com/users/ItsVeryWindy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsVeryWindy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsVeryWindy/subscriptions","organizations_url":"https://api.github.com/users/ItsVeryWindy/orgs","repos_url":"https://api.github.com/users/ItsVeryWindy/repos","events_url":"https://api.github.com/users/ItsVeryWindy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsVeryWindy/received_events","type":"User","site_admin":false},"repo":{"id":48500257,"name":"Docker.DotNet","full_name":"ItsVeryWindy/Docker.DotNet","owner":{"login":"ItsVeryWindy","id":6949430,"avatar_url":"https://avatars.githubusercontent.com/u/6949430?v=3","gravatar_id":"","url":"https://api.github.com/users/ItsVeryWindy","html_url":"https://github.com/ItsVeryWindy","followers_url":"https://api.github.com/users/ItsVeryWindy/followers","following_url":"https://api.github.com/users/ItsVeryWindy/following{/other_user}","gists_url":"https://api.github.com/users/ItsVeryWindy/gists{/gist_id}","starred_url":"https://api.github.com/users/ItsVeryWindy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ItsVeryWindy/subscriptions","organizations_url":"https://api.github.com/users/ItsVeryWindy/orgs","repos_url":"https://api.github.com/users/ItsVeryWindy/repos","events_url":"https://api.github.com/users/ItsVeryWindy/events{/privacy}","received_events_url":"https://api.github.com/users/ItsVeryWindy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ItsVeryWindy/Docker.DotNet","description":":whale: .NET (C#) Client Library for Docker API","fork":true,"url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet","forks_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/forks","keys_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/teams","hooks_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/hooks","issue_events_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/issues/events{/number}","events_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/events","assignees_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/assignees{/user}","branches_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/branches{/branch}","tags_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/tags","blobs_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/git/refs{/sha}","trees_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/statuses/{sha}","languages_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/languages","stargazers_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/stargazers","contributors_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/contributors","subscribers_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/subscribers","subscription_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/subscription","commits_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/commits{/sha}","git_commits_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/git/commits{/sha}","comments_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/comments{/number}","issue_comment_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/issues/comments{/number}","contents_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/contents/{+path}","compare_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/merges","archive_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/downloads","issues_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/issues{/number}","pulls_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/pulls{/number}","milestones_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/milestones{/number}","notifications_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/labels{/name}","releases_url":"https://api.github.com/repos/ItsVeryWindy/Docker.DotNet/releases{/id}","created_at":"2015-12-23T16:29:38Z","updated_at":"2015-12-23T16:29:38Z","pushed_at":"2015-12-23T23:44:10Z","git_url":"git://github.com/ItsVeryWindy/Docker.DotNet.git","ssh_url":"git@github.com:ItsVeryWindy/Docker.DotNet.git","clone_url":"https://github.com/ItsVeryWindy/Docker.DotNet.git","svn_url":"https://github.com/ItsVeryWindy/Docker.DotNet","homepage":"https://www.nuget.org/packages/Docker.DotNet/","size":144,"stargazers_count":0,"watchers_count":0,"language":"C#","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":"ahmetalpbalkan:master","ref":"master","sha":"a36a5aaae1ac0c1ee24282f10161744f196bc18c","user":{"login":"ahmetalpbalkan","id":159209,"avatar_url":"https://avatars.githubusercontent.com/u/159209?v=3","gravatar_id":"","url":"https://api.github.com/users/ahmetalpbalkan","html_url":"https://github.com/ahmetalpbalkan","followers_url":"https://api.github.com/users/ahmetalpbalkan/followers","following_url":"https://api.github.com/users/ahmetalpbalkan/following{/other_user}","gists_url":"https://api.github.com/users/ahmetalpbalkan/gists{/gist_id}","starred_url":"https://api.github.com/users/ahmetalpbalkan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahmetalpbalkan/subscriptions","organizations_url":"https://api.github.com/users/ahmetalpbalkan/orgs","repos_url":"https://api.github.com/users/ahmetalpbalkan/repos","events_url":"https://api.github.com/users/ahmetalpbalkan/events{/privacy}","received_events_url":"https://api.github.com/users/ahmetalpbalkan/received_events","type":"User","site_admin":false},"repo":{"id":23337905,"name":"Docker.DotNet","full_name":"ahmetalpbalkan/Docker.DotNet","owner":{"login":"ahmetalpbalkan","id":159209,"avatar_url":"https://avatars.githubusercontent.com/u/159209?v=3","gravatar_id":"","url":"https://api.github.com/users/ahmetalpbalkan","html_url":"https://github.com/ahmetalpbalkan","followers_url":"https://api.github.com/users/ahmetalpbalkan/followers","following_url":"https://api.github.com/users/ahmetalpbalkan/following{/other_user}","gists_url":"https://api.github.com/users/ahmetalpbalkan/gists{/gist_id}","starred_url":"https://api.github.com/users/ahmetalpbalkan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahmetalpbalkan/subscriptions","organizations_url":"https://api.github.com/users/ahmetalpbalkan/orgs","repos_url":"https://api.github.com/users/ahmetalpbalkan/repos","events_url":"https://api.github.com/users/ahmetalpbalkan/events{/privacy}","received_events_url":"https://api.github.com/users/ahmetalpbalkan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ahmetalpbalkan/Docker.DotNet","description":":whale: .NET (C#) Client Library for Docker API","fork":false,"url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet","forks_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/forks","keys_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/teams","hooks_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/hooks","issue_events_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/events{/number}","events_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/events","assignees_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/assignees{/user}","branches_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/branches{/branch}","tags_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/tags","blobs_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/git/refs{/sha}","trees_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/statuses/{sha}","languages_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/languages","stargazers_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/stargazers","contributors_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/contributors","subscribers_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/subscribers","subscription_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/subscription","commits_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/commits{/sha}","git_commits_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/git/commits{/sha}","comments_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/comments{/number}","issue_comment_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/comments{/number}","contents_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/contents/{+path}","compare_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/merges","archive_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/downloads","issues_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues{/number}","pulls_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls{/number}","milestones_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/milestones{/number}","notifications_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/labels{/name}","releases_url":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/releases{/id}","created_at":"2014-08-26T03:47:17Z","updated_at":"2015-12-22T22:49:07Z","pushed_at":"2015-12-23T23:44:11Z","git_url":"git://github.com/ahmetalpbalkan/Docker.DotNet.git","ssh_url":"git@github.com:ahmetalpbalkan/Docker.DotNet.git","clone_url":"https://github.com/ahmetalpbalkan/Docker.DotNet.git","svn_url":"https://github.com/ahmetalpbalkan/Docker.DotNet","homepage":"https://www.nuget.org/packages/Docker.DotNet/","size":170,"stargazers_count":95,"watchers_count":95,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":21,"mirror_url":null,"open_issues_count":8,"forks":21,"open_issues":8,"watchers":95,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42"},"html":{"href":"https://github.com/ahmetalpbalkan/Docker.DotNet/pull/42"},"issue":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/42"},"comments":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/ahmetalpbalkan/Docker.DotNet/statuses/7d82100cb3f70942ed09c6388518af43e7190c12"}}}}