{"action":"created","comment":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/comments/36181345","id":36181345,"diff_hunk":"@@ -0,0 +1,240 @@\n+// Copyright (c) Microsoft. All rights reserved.\n+// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n+\n+using System;\n+using System.IO;\n+using System.Runtime.InteropServices;\n+#if DEBUG\n+using System.Runtime.CompilerServices;\n+#endif\n+\n+using SafeCurlHandle = Interop.libcurl.SafeCurlHandle;\n+using curlioerr = Interop.libcurl.curlioerr;\n+using curliocmd = Interop.libcurl.curliocmd;\n+\n+namespace System.Net.Http\n+{\n+    internal partial class CurlHandler\n+    {\n+        private static readonly char[] s_LineEndings = new char[] { HttpRuleParser.CR, HttpRuleParser.LF };\n+        private static readonly string s_LineEndingDelimiter = \"\\r\\n\";\n+        private ulong CurlReceiveHeadersCallback(\n+            IntPtr buffer,\n+            ulong size,\n+            ulong nitems,\n+            IntPtr context)\n+        {\n+            return ExecuteCallback(buffer, size, nitems, context,\n+                (ptr, totalSize, state) =>\n+                {\n+                    state.CancellationToken.ThrowIfCancellationRequested();\n+\n+#if DEBUG\n+                    LogCurlBuffer(ptr, totalSize);\n+#endif\n+\n+                    // The callback is invoked once per header and multi-line\n+                    // headers get merged into a single line\n+                    string responseHeader = Marshal.PtrToStringAnsi(ptr).Trim(s_LineEndings).Trim();\n+                    HttpResponseMessage response = state.ResponseMessage;\n+\n+                    // If this is the final header, we are done\n+                    if (string.IsNullOrWhiteSpace(responseHeader))\n+                    {\n+                        state.ResponseMessage.SignalHeadersReceived();\n+                        return totalSize;\n+                    }\n+\n+                    // TODO: Understand scenarios where multiple sets of headers are received\n+                    if (!TryParseStatusLine(response, responseHeader))\n+                    {\n+                        int colonIndex = responseHeader.IndexOf(':');\n+\n+                        // Skip malformed header lines that are missing the colon character.\n+                        if (colonIndex > 0)\n+                        {\n+                            string headerName = responseHeader.Substring(0, colonIndex);\n+                            string headerValue = responseHeader.Substring(colonIndex + 1);\n+\n+                            if (!response.Headers.TryAddWithoutValidation(headerName, headerValue))\n+                            {\n+                                // TODO: Skip compression related headers\n+                                response.Content.Headers.TryAddWithoutValidation(headerName, headerValue);\n+                            }\n+                        }\n+                    }\n+                    return totalSize;\n+                });\n+        }\n+\n+        private ulong CurlReceiveBodyCallback(\n+            IntPtr buffer,\n+            ulong size,\n+            ulong nitems,\n+            IntPtr context)\n+        {\n+            return ExecuteCallback(buffer, size, nitems, context,\n+                (ptr, totalSize, state) =>\n+                {\n+#if DEBUG\n+                    LogCurlBuffer(ptr, totalSize);\n+#endif\n+\n+                    // TODO: Handle compression and chunked-mode\n+\n+                    var byteBuffer = new byte[totalSize];\n+                    Marshal.Copy(ptr, byteBuffer, 0, byteBuffer.Length);\n+                    Stream contentStream = state.ResponseMessage.ContentStream;\n+                    contentStream.Write(byteBuffer, 0, byteBuffer.Length);  // will block if no readers\n+                    contentStream.Flush();\n+                    return totalSize;\n+                });\n+        }\n+\n+\n+        private ulong CurlSendCallback(\n+            IntPtr buffer,\n+            ulong size,\n+            ulong nitems,\n+            IntPtr context)\n+        {\n+            return ExecuteCallback(buffer, size, nitems, context,\n+                (ptr, totalSize, state) =>\n+                {\n+                    state.CancellationToken.ThrowIfCancellationRequested();\n+                    Stream contentStream = state.RequestContentStream;\n+\n+                    // TODO: Handle chunked-mode\n+\n+                    int bytesRead = 0;\n+                    while (bytesRead < (int)totalSize)\n+                    {\n+                        state.CancellationToken.ThrowIfCancellationRequested();\n+                        var byteBuffer = new byte[totalSize];\n+                        int numBytes = contentStream.Read(byteBuffer, bytesRead, (int)totalSize - bytesRead);\n+                        if (numBytes == 0)\n+                        {\n+                            break;\n+                        }\n+                        Marshal.Copy(byteBuffer, bytesRead, new IntPtr(ptr.ToInt64() + bytesRead), numBytes);\n+                        bytesRead += numBytes;\n+                    }\n+#if DEBUG\n+                    LogCurlBuffer(ptr, (ulong)bytesRead);\n+#endif\n+                    return (ulong)bytesRead;\n+                });\n+        }\n+\n+        private int CurlSendIoCtlCallback(\n+            IntPtr handle,\n+            int cmd,\n+            IntPtr context)\n+        {\n+            if (cmd != curliocmd.CURLIOCMD_RESTARTREAD)\n+            {\n+                return curlioerr.CURLIOE_UNKNOWNCMD;\n+            }\n+\n+            GCHandle gch = GCHandle.FromIntPtr(context);\n+            var state = (RequestCompletionSource)gch.Target;\n+\n+            try\n+            {\n+                CheckDisposed();\n+                state.CancellationToken.ThrowIfCancellationRequested();\n+\n+                Stream contentStream = state.RequestContentStream;\n+                if (!contentStream.CanSeek)\n+                {\n+                    return curlioerr.CURLIOE_FAILRESTART;\n+                }\n+                contentStream.Seek(0, SeekOrigin.Begin);\n+                return curlioerr.CURLIOE_OK;\n+            }\n+            catch (Exception ex)\n+            {\n+                state.SavedException = ex;\n+#if DEBUG\n+                if (Logging.On) Logging.Exception(Logging.Http, this, \"CurlSendIoCtlCallback exception for \" + Logging.GetObjectLogHash(state.ResponseMessage.ContentStream) + \": \", ex);\n+#endif\n+                return curlioerr.CURLIOE_FAILRESTART; // Force curl_easy_perform to fail\n+            }\n+        }\n+\n+        private ulong ExecuteCallback(\n+            IntPtr buffer,\n+            ulong size,\n+            ulong nitems,\n+            IntPtr context,\n+            Func<IntPtr, ulong, RequestCompletionSource, ulong> callback)\n+        {\n+            size *= nitems;\n+            GCHandle gch = GCHandle.FromIntPtr(context);\n+            var state = (RequestCompletionSource)gch.Target;\n+\n+            try\n+            {\n+                CheckDisposed();\n+#if DEBUG\n+                if (Logging.On)\n+                {\n+                    Logging.PrintInfo(Logging.Http, this, \"Executecallback for \" + Logging.GetObjectLogHash(state.ResponseMessage.ContentStream) + \" with \" + ((size > 0) ? (size + \" bytes\") : \" no data\"));\n+                }\n+#endif\n+                return (size == 0) ? 0 : callback(buffer, size, state);\n+            }\n+            catch (Exception ex)\n+            {\n+                state.SavedException = ex;\n+#if DEBUG\n+                if (Logging.On) Logging.Exception(Logging.Http, this, \"Executecallback exception for \" + Logging.GetObjectLogHash(state.ResponseMessage.ContentStream) + \": \", ex);\n+#endif\n+                return (size > 0) ? size - 1 : 1; // Force curl_easy_perform to fail\n+            }\n+        }\n+\n+        private bool TryParseStatusLine(HttpResponseMessage response, string responseHeader)\n+        {\n+\n+            if (!responseHeader.StartsWith(\"HTTP/\", StringComparison.OrdinalIgnoreCase))\n+            {\n+                return false;\n+            }\n+            var tokens = responseHeader.Split(new char[] { ' ' });\n+            if (tokens.Length > 1)\n+            {\n+                response.StatusCode = (HttpStatusCode)int.Parse(tokens[1]);","path":"src/System.Net.Http/src/System/Net/Http/Unix/CurlCallbacks.cs","position":null,"original_position":207,"commit_id":"bd03e0fd1951b009868c2526dcf84a7b44d6d558","original_commit_id":"2947b37df924a0930bca79d2d234dd9174b6c5c3","user":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"body":"@stephentoub, I tried to go thru the code of Wininet HttpQueryInfoA but was not able to figure out things. Can I leave this as a TODO for now?","created_at":"2015-08-04T12:23:00Z","updated_at":"2015-08-04T12:23:00Z","html_url":"https://github.com/dotnet/corefx/pull/2597#discussion_r36181345","pull_request_url":"https://api.github.com/repos/dotnet/corefx/pulls/2597","_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments/36181345"},"html":{"href":"https://github.com/dotnet/corefx/pull/2597#discussion_r36181345"},"pull_request":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/2597"}}},"pull_request":{"url":"https://api.github.com/repos/dotnet/corefx/pulls/2597","id":41400082,"html_url":"https://github.com/dotnet/corefx/pull/2597","diff_url":"https://github.com/dotnet/corefx/pull/2597.diff","patch_url":"https://github.com/dotnet/corefx/pull/2597.patch","issue_url":"https://api.github.com/repos/dotnet/corefx/issues/2597","number":2597,"state":"open","locked":false,"title":"HttpClient xplat: Basic request and response processing","user":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"body":"- Also addressed some of the comments in https://github.com/dotnet/corefx/issues/2555","created_at":"2015-08-01T10:44:29Z","updated_at":"2015-08-04T12:23:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"02e2e21d9b8cdcc134f078de6c22e25f015dbedb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/dotnet/corefx/pulls/2597/commits","review_comments_url":"https://api.github.com/repos/dotnet/corefx/pulls/2597/comments","review_comment_url":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}","comments_url":"https://api.github.com/repos/dotnet/corefx/issues/2597/comments","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/bd03e0fd1951b009868c2526dcf84a7b44d6d558","head":{"label":"vijaykota:_feature","ref":"_feature","sha":"bd03e0fd1951b009868c2526dcf84a7b44d6d558","user":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"repo":{"id":39578675,"name":"corefx","full_name":"vijaykota/corefx","owner":{"login":"vijaykota","id":11638339,"avatar_url":"https://avatars.githubusercontent.com/u/11638339?v=3","gravatar_id":"","url":"https://api.github.com/users/vijaykota","html_url":"https://github.com/vijaykota","followers_url":"https://api.github.com/users/vijaykota/followers","following_url":"https://api.github.com/users/vijaykota/following{/other_user}","gists_url":"https://api.github.com/users/vijaykota/gists{/gist_id}","starred_url":"https://api.github.com/users/vijaykota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vijaykota/subscriptions","organizations_url":"https://api.github.com/users/vijaykota/orgs","repos_url":"https://api.github.com/users/vijaykota/repos","events_url":"https://api.github.com/users/vijaykota/events{/privacy}","received_events_url":"https://api.github.com/users/vijaykota/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vijaykota/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":true,"url":"https://api.github.com/repos/vijaykota/corefx","forks_url":"https://api.github.com/repos/vijaykota/corefx/forks","keys_url":"https://api.github.com/repos/vijaykota/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vijaykota/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vijaykota/corefx/teams","hooks_url":"https://api.github.com/repos/vijaykota/corefx/hooks","issue_events_url":"https://api.github.com/repos/vijaykota/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/vijaykota/corefx/events","assignees_url":"https://api.github.com/repos/vijaykota/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/vijaykota/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/vijaykota/corefx/tags","blobs_url":"https://api.github.com/repos/vijaykota/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vijaykota/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vijaykota/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/vijaykota/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vijaykota/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/vijaykota/corefx/languages","stargazers_url":"https://api.github.com/repos/vijaykota/corefx/stargazers","contributors_url":"https://api.github.com/repos/vijaykota/corefx/contributors","subscribers_url":"https://api.github.com/repos/vijaykota/corefx/subscribers","subscription_url":"https://api.github.com/repos/vijaykota/corefx/subscription","commits_url":"https://api.github.com/repos/vijaykota/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/vijaykota/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/vijaykota/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/vijaykota/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/vijaykota/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/vijaykota/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vijaykota/corefx/merges","archive_url":"https://api.github.com/repos/vijaykota/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vijaykota/corefx/downloads","issues_url":"https://api.github.com/repos/vijaykota/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/vijaykota/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/vijaykota/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/vijaykota/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vijaykota/corefx/labels{/name}","releases_url":"https://api.github.com/repos/vijaykota/corefx/releases{/id}","created_at":"2015-07-23T16:32:30Z","updated_at":"2015-07-23T16:32:47Z","pushed_at":"2015-08-04T12:16:07Z","git_url":"git://github.com/vijaykota/corefx.git","ssh_url":"git@github.com:vijaykota/corefx.git","clone_url":"https://github.com/vijaykota/corefx.git","svn_url":"https://github.com/vijaykota/corefx","homepage":"http://dotnet.github.io/core/","size":25959,"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":"dotnet:master","ref":"master","sha":"80f9caf6de552efd2fa8aee636dc5fab1197787b","user":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"repo":{"id":26295345,"name":"corefx","full_name":"dotnet/corefx","owner":{"login":"dotnet","id":9141961,"avatar_url":"https://avatars.githubusercontent.com/u/9141961?v=3","gravatar_id":"","url":"https://api.github.com/users/dotnet","html_url":"https://github.com/dotnet","followers_url":"https://api.github.com/users/dotnet/followers","following_url":"https://api.github.com/users/dotnet/following{/other_user}","gists_url":"https://api.github.com/users/dotnet/gists{/gist_id}","starred_url":"https://api.github.com/users/dotnet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dotnet/subscriptions","organizations_url":"https://api.github.com/users/dotnet/orgs","repos_url":"https://api.github.com/users/dotnet/repos","events_url":"https://api.github.com/users/dotnet/events{/privacy}","received_events_url":"https://api.github.com/users/dotnet/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/dotnet/corefx","description":"This repo contains the .NET Core foundational libraries, called CoreFX. It includes classes for collections, file systems, console, XML, async and many others.","fork":false,"url":"https://api.github.com/repos/dotnet/corefx","forks_url":"https://api.github.com/repos/dotnet/corefx/forks","keys_url":"https://api.github.com/repos/dotnet/corefx/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dotnet/corefx/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dotnet/corefx/teams","hooks_url":"https://api.github.com/repos/dotnet/corefx/hooks","issue_events_url":"https://api.github.com/repos/dotnet/corefx/issues/events{/number}","events_url":"https://api.github.com/repos/dotnet/corefx/events","assignees_url":"https://api.github.com/repos/dotnet/corefx/assignees{/user}","branches_url":"https://api.github.com/repos/dotnet/corefx/branches{/branch}","tags_url":"https://api.github.com/repos/dotnet/corefx/tags","blobs_url":"https://api.github.com/repos/dotnet/corefx/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dotnet/corefx/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dotnet/corefx/git/refs{/sha}","trees_url":"https://api.github.com/repos/dotnet/corefx/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dotnet/corefx/statuses/{sha}","languages_url":"https://api.github.com/repos/dotnet/corefx/languages","stargazers_url":"https://api.github.com/repos/dotnet/corefx/stargazers","contributors_url":"https://api.github.com/repos/dotnet/corefx/contributors","subscribers_url":"https://api.github.com/repos/dotnet/corefx/subscribers","subscription_url":"https://api.github.com/repos/dotnet/corefx/subscription","commits_url":"https://api.github.com/repos/dotnet/corefx/commits{/sha}","git_commits_url":"https://api.github.com/repos/dotnet/corefx/git/commits{/sha}","comments_url":"https://api.github.com/repos/dotnet/corefx/comments{/number}","issue_comment_url":"https://api.github.com/repos/dotnet/corefx/issues/comments{/number}","contents_url":"https://api.github.com/repos/dotnet/corefx/contents/{+path}","compare_url":"https://api.github.com/repos/dotnet/corefx/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dotnet/corefx/merges","archive_url":"https://api.github.com/repos/dotnet/corefx/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dotnet/corefx/downloads","issues_url":"https://api.github.com/repos/dotnet/corefx/issues{/number}","pulls_url":"https://api.github.com/repos/dotnet/corefx/pulls{/number}","milestones_url":"https://api.github.com/repos/dotnet/corefx/milestones{/number}","notifications_url":"https://api.github.com/repos/dotnet/corefx/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dotnet/corefx/labels{/name}","releases_url":"https://api.github.com/repos/dotnet/corefx/releases{/id}","created_at":"2014-11-06T23:42:48Z","updated_at":"2015-08-04T10:24:24Z","pushed_at":"2015-08-04T12:16:11Z","git_url":"git://github.com/dotnet/corefx.git","ssh_url":"git@github.com:dotnet/corefx.git","clone_url":"https://github.com/dotnet/corefx.git","svn_url":"https://github.com/dotnet/corefx","homepage":"http://dotnet.github.io/core/","size":57832,"stargazers_count":8164,"watchers_count":8164,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1709,"mirror_url":null,"open_issues_count":532,"forks":1709,"open_issues":532,"watchers":8164,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/2597"},"html":{"href":"https://github.com/dotnet/corefx/pull/2597"},"issue":{"href":"https://api.github.com/repos/dotnet/corefx/issues/2597"},"comments":{"href":"https://api.github.com/repos/dotnet/corefx/issues/2597/comments"},"review_comments":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/2597/comments"},"review_comment":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/dotnet/corefx/pulls/2597/commits"},"statuses":{"href":"https://api.github.com/repos/dotnet/corefx/statuses/bd03e0fd1951b009868c2526dcf84a7b44d6d558"}}}}