{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/50415250","id":50415250,"diff_hunk":"@@ -149,6 +133,90 @@ private[http] object OutgoingConnectionBlueprint {\n \n   import ParserOutput._\n \n+  private final class ResponsePrep(parserSettings: ParserSettings, eagerClose: Boolean)\n+    extends GraphStage[FlowShape[ResponseOutput, HttpResponse]] {\n+\n+    private val in = Inlet[ResponseOutput](\"ResponsePrep.in\")\n+    private val out = Outlet[HttpResponse](\"ResponsePrep.out\")\n+\n+    val shape = new FlowShape(in, out)\n+\n+    override def createLogic(effectiveAttributes: Attributes) = new GraphStageLogic(shape) {\n+      private val idle = new InHandler {\n+        def onPush(): Unit = grab(in) match {\n+          case ResponseStart(statusCode, protocol, headers, entityCreator, _) ⇒\n+            val entity = createEntity(entityCreator) withSizeLimit parserSettings.maxContentLength\n+            push(out, HttpResponse(statusCode, headers, entity, protocol))\n+\n+          case MessageStartError(_, info) ⇒\n+            throw IllegalResponseException(info)\n+        }\n+      }\n+\n+      private val waitForMessageEnd = new InHandler {\n+        def onPush(): Unit = grab(in) match {\n+          case MessageEnd ⇒ setHandler(in, idle)\n+        }\n+      }\n+\n+      setHandler(in, idle)\n+\n+      private def createEntity(creator: EntityCreator[ResponseOutput, ResponseEntity]): ResponseEntity = {\n+        creator match {\n+          case StrictEntityCreator(entity) ⇒\n+            pull(in)\n+            setHandler(in, waitForMessageEnd)\n+            entity\n+\n+          case StreamedEntityCreator(creator) ⇒\n+            val entitySource = new SubSourceOutlet[ResponseOutput](\"EntitySource\")\n+            var responseCancelled = false\n+\n+            entitySource.setHandler(new OutHandler {\n+              override def onPull(): Unit = pull(in)\n+\n+              override def onDownstreamFinish(): Unit = {\n+                responseCancelled = true\n+                if (isClosed(in)) completeStage()\n+                else {\n+                  // Start draining\n+                  if (!hasBeenPulled(in)) pull(in)\n+                }\n+              }\n+            })\n+\n+            setHandler(in, new InHandler {\n+              override def onPush(): Unit = grab(in) match {\n+                case MessageEnd ⇒\n+                  entitySource.complete()\n+                  setHandler(in, idle)\n+                  responseCancelled = false\n+\n+                case messagePart ⇒\n+                  if (responseCancelled) {\n+                    if (eagerClose) completeStage()","path":"akka-http-core/src/main/scala/akka/http/impl/engine/client/OutgoingConnectionBlueprint.scala","position":119,"original_position":119,"commit_id":"822c72c601e429cd37dede90519ea9625b210b7b","original_commit_id":"822c72c601e429cd37dede90519ea9625b210b7b","user":{"login":"rkuhn","id":470469,"avatar_url":"https://avatars.githubusercontent.com/u/470469?v=3","gravatar_id":"","url":"https://api.github.com/users/rkuhn","html_url":"https://github.com/rkuhn","followers_url":"https://api.github.com/users/rkuhn/followers","following_url":"https://api.github.com/users/rkuhn/following{/other_user}","gists_url":"https://api.github.com/users/rkuhn/gists{/gist_id}","starred_url":"https://api.github.com/users/rkuhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rkuhn/subscriptions","organizations_url":"https://api.github.com/users/rkuhn/orgs","repos_url":"https://api.github.com/users/rkuhn/repos","events_url":"https://api.github.com/users/rkuhn/events{/privacy}","received_events_url":"https://api.github.com/users/rkuhn/received_events","type":"User","site_admin":false},"body":"all completions must be accompanied by closing the entitySource as well, else we leak it","created_at":"2016-01-21T15:31:39Z","updated_at":"2016-01-21T15:31:39Z","html_url":"https://github.com/akka/akka/pull/19528#discussion_r50415250","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/19528","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/50415250"},"html":{"href":"https://github.com/akka/akka/pull/19528#discussion_r50415250"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/19528"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/19528","id":56575692,"html_url":"https://github.com/akka/akka/pull/19528","diff_url":"https://github.com/akka/akka/pull/19528.diff","patch_url":"https://github.com/akka/akka/pull/19528.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/19528","number":19528,"state":"open","locked":false,"title":"Http: [WIP] HttpResponse cancellation","user":{"login":"ataraxer","id":1394955,"avatar_url":"https://avatars.githubusercontent.com/u/1394955?v=3","gravatar_id":"","url":"https://api.github.com/users/ataraxer","html_url":"https://github.com/ataraxer","followers_url":"https://api.github.com/users/ataraxer/followers","following_url":"https://api.github.com/users/ataraxer/following{/other_user}","gists_url":"https://api.github.com/users/ataraxer/gists{/gist_id}","starred_url":"https://api.github.com/users/ataraxer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ataraxer/subscriptions","organizations_url":"https://api.github.com/users/ataraxer/orgs","repos_url":"https://api.github.com/users/ataraxer/repos","events_url":"https://api.github.com/users/ataraxer/events{/privacy}","received_events_url":"https://api.github.com/users/ataraxer/received_events","type":"User","site_admin":false},"body":"Here's an attempt to solve issues #18010 and #18203.\r\n\r\nFirst commit can be treated as a simpler version of the solution, which involves adding `eagerClose` flag to `splitWhen` in order to define how substream cancelation should be treated: by draining the remaining elements in order to prevent stalling (current behaviour) or cancelling the stage altogether.\r\n\r\nSecond one introduces custom stage instead of `splitWhen/prefixAndTail` pipeline, which would allow to add `eagerClose` flag to `outgoingConnection` without adding flag to `splitWhen`/`splitAt` if this change isn't plausible.\r\n\r\nI used https://github.com/akka/akka/commit/ced5aa7ddcac1408e08ed159da9a04fecfad18ed as a reference, however there are some slight changes which will be marked in comments to particular lines.","created_at":"2016-01-20T08:08:48Z","updated_at":"2016-01-21T15:31:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"09953a88aa8334e909781c649cbc1c3336daf65f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/19528/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/19528/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/19528/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/822c72c601e429cd37dede90519ea9625b210b7b","head":{"label":"ataraxer:wip-http-response-cancellation","ref":"wip-http-response-cancellation","sha":"822c72c601e429cd37dede90519ea9625b210b7b","user":{"login":"ataraxer","id":1394955,"avatar_url":"https://avatars.githubusercontent.com/u/1394955?v=3","gravatar_id":"","url":"https://api.github.com/users/ataraxer","html_url":"https://github.com/ataraxer","followers_url":"https://api.github.com/users/ataraxer/followers","following_url":"https://api.github.com/users/ataraxer/following{/other_user}","gists_url":"https://api.github.com/users/ataraxer/gists{/gist_id}","starred_url":"https://api.github.com/users/ataraxer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ataraxer/subscriptions","organizations_url":"https://api.github.com/users/ataraxer/orgs","repos_url":"https://api.github.com/users/ataraxer/repos","events_url":"https://api.github.com/users/ataraxer/events{/privacy}","received_events_url":"https://api.github.com/users/ataraxer/received_events","type":"User","site_admin":false},"repo":{"id":32074531,"name":"akka","full_name":"ataraxer/akka","owner":{"login":"ataraxer","id":1394955,"avatar_url":"https://avatars.githubusercontent.com/u/1394955?v=3","gravatar_id":"","url":"https://api.github.com/users/ataraxer","html_url":"https://github.com/ataraxer","followers_url":"https://api.github.com/users/ataraxer/followers","following_url":"https://api.github.com/users/ataraxer/following{/other_user}","gists_url":"https://api.github.com/users/ataraxer/gists{/gist_id}","starred_url":"https://api.github.com/users/ataraxer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ataraxer/subscriptions","organizations_url":"https://api.github.com/users/ataraxer/orgs","repos_url":"https://api.github.com/users/ataraxer/repos","events_url":"https://api.github.com/users/ataraxer/events{/privacy}","received_events_url":"https://api.github.com/users/ataraxer/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ataraxer/akka","description":"Akka Project","fork":true,"url":"https://api.github.com/repos/ataraxer/akka","forks_url":"https://api.github.com/repos/ataraxer/akka/forks","keys_url":"https://api.github.com/repos/ataraxer/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ataraxer/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ataraxer/akka/teams","hooks_url":"https://api.github.com/repos/ataraxer/akka/hooks","issue_events_url":"https://api.github.com/repos/ataraxer/akka/issues/events{/number}","events_url":"https://api.github.com/repos/ataraxer/akka/events","assignees_url":"https://api.github.com/repos/ataraxer/akka/assignees{/user}","branches_url":"https://api.github.com/repos/ataraxer/akka/branches{/branch}","tags_url":"https://api.github.com/repos/ataraxer/akka/tags","blobs_url":"https://api.github.com/repos/ataraxer/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ataraxer/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ataraxer/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/ataraxer/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ataraxer/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/ataraxer/akka/languages","stargazers_url":"https://api.github.com/repos/ataraxer/akka/stargazers","contributors_url":"https://api.github.com/repos/ataraxer/akka/contributors","subscribers_url":"https://api.github.com/repos/ataraxer/akka/subscribers","subscription_url":"https://api.github.com/repos/ataraxer/akka/subscription","commits_url":"https://api.github.com/repos/ataraxer/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/ataraxer/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/ataraxer/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/ataraxer/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/ataraxer/akka/contents/{+path}","compare_url":"https://api.github.com/repos/ataraxer/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ataraxer/akka/merges","archive_url":"https://api.github.com/repos/ataraxer/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ataraxer/akka/downloads","issues_url":"https://api.github.com/repos/ataraxer/akka/issues{/number}","pulls_url":"https://api.github.com/repos/ataraxer/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/ataraxer/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/ataraxer/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ataraxer/akka/labels{/name}","releases_url":"https://api.github.com/repos/ataraxer/akka/releases{/id}","created_at":"2015-03-12T11:59:23Z","updated_at":"2015-03-12T11:59:31Z","pushed_at":"2016-01-21T10:37:02Z","git_url":"git://github.com/ataraxer/akka.git","ssh_url":"git@github.com:ataraxer/akka.git","clone_url":"https://github.com/ataraxer/akka.git","svn_url":"https://github.com/ataraxer/akka","homepage":"http://akka.io","size":172638,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"akka:master","ref":"master","sha":"17c9493e26dc4f25c9221d969dc2d498ed046b02","user":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"repo":{"id":130013,"name":"akka","full_name":"akka/akka","owner":{"login":"akka","id":1496237,"avatar_url":"https://avatars.githubusercontent.com/u/1496237?v=3","gravatar_id":"","url":"https://api.github.com/users/akka","html_url":"https://github.com/akka","followers_url":"https://api.github.com/users/akka/followers","following_url":"https://api.github.com/users/akka/following{/other_user}","gists_url":"https://api.github.com/users/akka/gists{/gist_id}","starred_url":"https://api.github.com/users/akka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akka/subscriptions","organizations_url":"https://api.github.com/users/akka/orgs","repos_url":"https://api.github.com/users/akka/repos","events_url":"https://api.github.com/users/akka/events{/privacy}","received_events_url":"https://api.github.com/users/akka/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/akka/akka","description":"Akka Project","fork":false,"url":"https://api.github.com/repos/akka/akka","forks_url":"https://api.github.com/repos/akka/akka/forks","keys_url":"https://api.github.com/repos/akka/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akka/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akka/akka/teams","hooks_url":"https://api.github.com/repos/akka/akka/hooks","issue_events_url":"https://api.github.com/repos/akka/akka/issues/events{/number}","events_url":"https://api.github.com/repos/akka/akka/events","assignees_url":"https://api.github.com/repos/akka/akka/assignees{/user}","branches_url":"https://api.github.com/repos/akka/akka/branches{/branch}","tags_url":"https://api.github.com/repos/akka/akka/tags","blobs_url":"https://api.github.com/repos/akka/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akka/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akka/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/akka/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akka/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/akka/akka/languages","stargazers_url":"https://api.github.com/repos/akka/akka/stargazers","contributors_url":"https://api.github.com/repos/akka/akka/contributors","subscribers_url":"https://api.github.com/repos/akka/akka/subscribers","subscription_url":"https://api.github.com/repos/akka/akka/subscription","commits_url":"https://api.github.com/repos/akka/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/akka/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/akka/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/akka/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/akka/akka/contents/{+path}","compare_url":"https://api.github.com/repos/akka/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akka/akka/merges","archive_url":"https://api.github.com/repos/akka/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akka/akka/downloads","issues_url":"https://api.github.com/repos/akka/akka/issues{/number}","pulls_url":"https://api.github.com/repos/akka/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/akka/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/akka/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akka/akka/labels{/name}","releases_url":"https://api.github.com/repos/akka/akka/releases{/id}","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-01-21T15:16:03Z","pushed_at":"2016-01-21T15:20:43Z","git_url":"git://github.com/akka/akka.git","ssh_url":"git@github.com:akka/akka.git","clone_url":"https://github.com/akka/akka.git","svn_url":"https://github.com/akka/akka","homepage":"http://akka.io","size":182580,"stargazers_count":4991,"watchers_count":4991,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1521,"mirror_url":null,"open_issues_count":853,"forks":1521,"open_issues":853,"watchers":4991,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/19528"},"html":{"href":"https://github.com/akka/akka/pull/19528"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/19528"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/19528/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/19528/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/19528/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/822c72c601e429cd37dede90519ea9625b210b7b"}}}}