{"action":"created","comment":{"url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/comments/37001026","id":37001026,"diff_hunk":"@@ -0,0 +1,124 @@\n+﻿using System;\n+using System.Collections.Generic;\n+using System.Globalization;\n+using System.IO;\n+using System.Net;\n+using System.Text;\n+\n+namespace NuGet.CommandLine\n+{\n+    /// <remarks>\n+    /// Based on the blog post by Travis Illig at http://www.paraesthesia.com/archive/2009/12/16/posting-multipartform-data-using-.net-webrequest.aspx\n+    /// </remarks>\n+    public class MultipartWebRequest\n+    {\n+        private const string FormDataTemplate = \"--{0}\\r\\nContent-Disposition: form-data; name=\\\"{1}\\\"\\r\\n\\r\\n{2}\\r\\n\";\n+        private const string FileTemplate = \"--{0}\\r\\nContent-Disposition: form-data; name=\\\"{1}\\\"; filename=\\\"{2}\\\"\\r\\nContent-Type: {3}\\r\\n\\r\\n\";\n+        private readonly Dictionary<string, string> _formData;\n+\n+        private readonly List<PostFileData> _files;\n+\n+        public MultipartWebRequest()\n+            : this(new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase))\n+        {\n+        }\n+\n+        public MultipartWebRequest(Dictionary<string, string> formData)\n+        {\n+            _formData = formData;\n+            _files = new List<PostFileData>();\n+        }\n+\n+        public void AddFormData(string key, string value)\n+        {\n+            _formData.Add(key, value);\n+        }\n+\n+        public void AddFile(Func<Stream> fileFactory, string fieldName, long length, string contentType = \"application/octet-stream\")\n+        {\n+            _files.Add(new PostFileData\n+            {\n+                FileFactory = fileFactory,\n+                FieldName = fieldName,\n+                ContentType = contentType,\n+                ContentLength = length\n+            });\n+        }\n+\n+        public void CreateMultipartRequest(WebRequest request)\n+        {\n+            string boundary = \"---------------------------\" + DateTime.Now.Ticks.ToString(\"x\", CultureInfo.InvariantCulture);\n+            request.ContentType = \"multipart/form-data; boundary=\" + boundary;\n+            request.ContentLength = CalculateContentLength(boundary);\n+\n+            using (Stream stream = request.GetRequestStream())\n+            {\n+                foreach (var item in _formData)\n+                {\n+                    string header = String.Format(CultureInfo.InvariantCulture, FormDataTemplate, boundary, item.Key, item.Value);\n+                    byte[] headerBytes = Encoding.UTF8.GetBytes(header);\n+                    stream.Write(headerBytes, 0, headerBytes.Length);\n+                }\n+\n+                byte[] newlineBytes = Encoding.UTF8.GetBytes(\"\\r\\n\");\n+                foreach (var file in _files)\n+                {\n+                    string header = String.Format(CultureInfo.InvariantCulture, FileTemplate, boundary, file.FieldName, file.FieldName, file.ContentType);\n+                    byte[] headerBytes = Encoding.UTF8.GetBytes(header);\n+                    stream.Write(headerBytes, 0, headerBytes.Length);\n+\n+                    Stream fileStream = file.FileFactory();\n+                    fileStream.CopyTo(stream, bufferSize: 4 * 1024);\n+                    fileStream.Close();\n+                    stream.Write(newlineBytes, 0, newlineBytes.Length);\n+                }\n+\n+                string trailer = String.Format(CultureInfo.InvariantCulture, \"--{0}--\", boundary);\n+                byte[] trailerBytes = Encoding.UTF8.GetBytes(trailer);\n+                stream.Write(trailerBytes, 0, trailerBytes.Length);\n+            }\n+        }\n+\n+        private long CalculateContentLength(string boundary)\n+        {\n+            long totalContentLength = 0;\n+\n+            foreach (var item in _formData)\n+            {\n+                string header = String.Format(CultureInfo.InvariantCulture, FormDataTemplate, boundary, item.Key, item.Value);\n+                byte[] headerBytes = Encoding.UTF8.GetBytes(header);\n+\n+                totalContentLength += headerBytes.Length;\n+            }\n+\n+            byte[] newlineBytes = Encoding.UTF8.GetBytes(\"\\r\\n\");","path":"src/NuGet.CommandLine/MultipartWebRequest.cs","position":94,"original_position":94,"commit_id":"8c89351c1249fae543292fb168dd72ae62c20476","original_commit_id":"8c89351c1249fae543292fb168dd72ae62c20476","user":{"login":"feiling","id":2679220,"avatar_url":"https://avatars.githubusercontent.com/u/2679220?v=3","gravatar_id":"","url":"https://api.github.com/users/feiling","html_url":"https://github.com/feiling","followers_url":"https://api.github.com/users/feiling/followers","following_url":"https://api.github.com/users/feiling/following{/other_user}","gists_url":"https://api.github.com/users/feiling/gists{/gist_id}","starred_url":"https://api.github.com/users/feiling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feiling/subscriptions","organizations_url":"https://api.github.com/users/feiling/orgs","repos_url":"https://api.github.com/users/feiling/repos","events_url":"https://api.github.com/users/feiling/events{/privacy}","received_events_url":"https://api.github.com/users/feiling/received_events","type":"User","site_admin":false},"body":"Also, we need to use \"\\r\\n\" here.","created_at":"2015-08-13T17:27:23Z","updated_at":"2015-08-13T17:27:23Z","html_url":"https://github.com/NuGet/NuGet.PackageManagement/pull/65#discussion_r37001026","pull_request_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65","_links":{"self":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/comments/37001026"},"html":{"href":"https://github.com/NuGet/NuGet.PackageManagement/pull/65#discussion_r37001026"},"pull_request":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65"}}},"pull_request":{"url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65","id":42376234,"html_url":"https://github.com/NuGet/NuGet.PackageManagement/pull/65","diff_url":"https://github.com/NuGet/NuGet.PackageManagement/pull/65.diff","patch_url":"https://github.com/NuGet/NuGet.PackageManagement/pull/65.patch","issue_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/65","number":65,"state":"open","locked":false,"title":"Fix NuGet/Home#776: MultipartWebRequest::CreateMultipartRequest should us \"\\r\\n\" explicitly and not Environment.NewLine","user":{"login":"feiling","id":2679220,"avatar_url":"https://avatars.githubusercontent.com/u/2679220?v=3","gravatar_id":"","url":"https://api.github.com/users/feiling","html_url":"https://github.com/feiling","followers_url":"https://api.github.com/users/feiling/followers","following_url":"https://api.github.com/users/feiling/following{/other_user}","gists_url":"https://api.github.com/users/feiling/gists{/gist_id}","starred_url":"https://api.github.com/users/feiling/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/feiling/subscriptions","organizations_url":"https://api.github.com/users/feiling/orgs","repos_url":"https://api.github.com/users/feiling/repos","events_url":"https://api.github.com/users/feiling/events{/privacy}","received_events_url":"https://api.github.com/users/feiling/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-08-13T17:25:52Z","updated_at":"2015-08-13T17:27:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32d7c64d26a768292b6efe4f731df0c88e595f92","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65/commits","review_comments_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65/comments","review_comment_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/65/comments","statuses_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/statuses/8c89351c1249fae543292fb168dd72ae62c20476","head":{"label":"NuGet:fix_776","ref":"fix_776","sha":"8c89351c1249fae543292fb168dd72ae62c20476","user":{"login":"NuGet","id":968310,"avatar_url":"https://avatars.githubusercontent.com/u/968310?v=3","gravatar_id":"","url":"https://api.github.com/users/NuGet","html_url":"https://github.com/NuGet","followers_url":"https://api.github.com/users/NuGet/followers","following_url":"https://api.github.com/users/NuGet/following{/other_user}","gists_url":"https://api.github.com/users/NuGet/gists{/gist_id}","starred_url":"https://api.github.com/users/NuGet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NuGet/subscriptions","organizations_url":"https://api.github.com/users/NuGet/orgs","repos_url":"https://api.github.com/users/NuGet/repos","events_url":"https://api.github.com/users/NuGet/events{/privacy}","received_events_url":"https://api.github.com/users/NuGet/received_events","type":"Organization","site_admin":false},"repo":{"id":26662893,"name":"NuGet.PackageManagement","full_name":"NuGet/NuGet.PackageManagement","owner":{"login":"NuGet","id":968310,"avatar_url":"https://avatars.githubusercontent.com/u/968310?v=3","gravatar_id":"","url":"https://api.github.com/users/NuGet","html_url":"https://github.com/NuGet","followers_url":"https://api.github.com/users/NuGet/followers","following_url":"https://api.github.com/users/NuGet/following{/other_user}","gists_url":"https://api.github.com/users/NuGet/gists{/gist_id}","starred_url":"https://api.github.com/users/NuGet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NuGet/subscriptions","organizations_url":"https://api.github.com/users/NuGet/orgs","repos_url":"https://api.github.com/users/NuGet/repos","events_url":"https://api.github.com/users/NuGet/events{/privacy}","received_events_url":"https://api.github.com/users/NuGet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NuGet/NuGet.PackageManagement","description":"Reading and writing manifests of installed packages","fork":false,"url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement","forks_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/forks","keys_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/teams","hooks_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/hooks","issue_events_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/events{/number}","events_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/events","assignees_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/assignees{/user}","branches_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/branches{/branch}","tags_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/tags","blobs_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/refs{/sha}","trees_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/statuses/{sha}","languages_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/languages","stargazers_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/stargazers","contributors_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/contributors","subscribers_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/subscribers","subscription_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/subscription","commits_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/commits{/sha}","git_commits_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/commits{/sha}","comments_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/comments{/number}","issue_comment_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/comments{/number}","contents_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/contents/{+path}","compare_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/merges","archive_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/downloads","issues_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues{/number}","pulls_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls{/number}","milestones_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/milestones{/number}","notifications_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/labels{/name}","releases_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/releases{/id}","created_at":"2014-11-14T23:55:44Z","updated_at":"2015-07-06T08:59:40Z","pushed_at":"2015-08-13T17:25:54Z","git_url":"git://github.com/NuGet/NuGet.PackageManagement.git","ssh_url":"git@github.com:NuGet/NuGet.PackageManagement.git","clone_url":"https://github.com/NuGet/NuGet.PackageManagement.git","svn_url":"https://github.com/NuGet/NuGet.PackageManagement","homepage":null,"size":5973,"stargazers_count":8,"watchers_count":8,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":9,"forks":8,"open_issues":9,"watchers":8,"default_branch":"dev"}},"base":{"label":"NuGet:dev","ref":"dev","sha":"e9fd1f55e78ac5923161cdac8f3d62afc8bb9b1c","user":{"login":"NuGet","id":968310,"avatar_url":"https://avatars.githubusercontent.com/u/968310?v=3","gravatar_id":"","url":"https://api.github.com/users/NuGet","html_url":"https://github.com/NuGet","followers_url":"https://api.github.com/users/NuGet/followers","following_url":"https://api.github.com/users/NuGet/following{/other_user}","gists_url":"https://api.github.com/users/NuGet/gists{/gist_id}","starred_url":"https://api.github.com/users/NuGet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NuGet/subscriptions","organizations_url":"https://api.github.com/users/NuGet/orgs","repos_url":"https://api.github.com/users/NuGet/repos","events_url":"https://api.github.com/users/NuGet/events{/privacy}","received_events_url":"https://api.github.com/users/NuGet/received_events","type":"Organization","site_admin":false},"repo":{"id":26662893,"name":"NuGet.PackageManagement","full_name":"NuGet/NuGet.PackageManagement","owner":{"login":"NuGet","id":968310,"avatar_url":"https://avatars.githubusercontent.com/u/968310?v=3","gravatar_id":"","url":"https://api.github.com/users/NuGet","html_url":"https://github.com/NuGet","followers_url":"https://api.github.com/users/NuGet/followers","following_url":"https://api.github.com/users/NuGet/following{/other_user}","gists_url":"https://api.github.com/users/NuGet/gists{/gist_id}","starred_url":"https://api.github.com/users/NuGet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NuGet/subscriptions","organizations_url":"https://api.github.com/users/NuGet/orgs","repos_url":"https://api.github.com/users/NuGet/repos","events_url":"https://api.github.com/users/NuGet/events{/privacy}","received_events_url":"https://api.github.com/users/NuGet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NuGet/NuGet.PackageManagement","description":"Reading and writing manifests of installed packages","fork":false,"url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement","forks_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/forks","keys_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/teams","hooks_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/hooks","issue_events_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/events{/number}","events_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/events","assignees_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/assignees{/user}","branches_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/branches{/branch}","tags_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/tags","blobs_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/refs{/sha}","trees_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/statuses/{sha}","languages_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/languages","stargazers_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/stargazers","contributors_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/contributors","subscribers_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/subscribers","subscription_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/subscription","commits_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/commits{/sha}","git_commits_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/git/commits{/sha}","comments_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/comments{/number}","issue_comment_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/comments{/number}","contents_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/contents/{+path}","compare_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/merges","archive_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/downloads","issues_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues{/number}","pulls_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls{/number}","milestones_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/milestones{/number}","notifications_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/labels{/name}","releases_url":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/releases{/id}","created_at":"2014-11-14T23:55:44Z","updated_at":"2015-07-06T08:59:40Z","pushed_at":"2015-08-13T17:25:54Z","git_url":"git://github.com/NuGet/NuGet.PackageManagement.git","ssh_url":"git@github.com:NuGet/NuGet.PackageManagement.git","clone_url":"https://github.com/NuGet/NuGet.PackageManagement.git","svn_url":"https://github.com/NuGet/NuGet.PackageManagement","homepage":null,"size":5973,"stargazers_count":8,"watchers_count":8,"language":"C#","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":9,"forks":8,"open_issues":9,"watchers":8,"default_branch":"dev"}},"_links":{"self":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65"},"html":{"href":"https://github.com/NuGet/NuGet.PackageManagement/pull/65"},"issue":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/65"},"comments":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/issues/65/comments"},"review_comments":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65/comments"},"review_comment":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/pulls/65/commits"},"statuses":{"href":"https://api.github.com/repos/NuGet/NuGet.PackageManagement/statuses/8c89351c1249fae543292fb168dd72ae62c20476"}}}}