{"action":"created","comment":{"url":"https://api.github.com/repos/akka/akka/pulls/comments/60193741","id":60193741,"diff_hunk":"@@ -57,202 +60,216 @@ private[http] final class BodyPartParser(defaultContentType: ContentType,\n     if (illegalHeaderWarnings) log.warning(errorInfo.withSummaryPrepended(\"Illegal multipart header\").formatPretty)\n   }\n \n-  private[this] var output = collection.immutable.Queue.empty[Output] // FIXME this probably is too wasteful\n-  private[this] var state: ByteString ⇒ StateResult = tryParseInitialBoundary\n-  private[this] var terminated = false\n-\n-  def warnOnIllegalHeader(errorInfo: ErrorInfo): Unit =\n-    if (illegalHeaderWarnings) log.warning(errorInfo.withSummaryPrepended(\"Illegal multipart header\").formatPretty)\n-\n-  override def onPush(input: ByteString, ctx: Context[Output]): SyncDirective =\n-    if (!terminated) {\n-      try state(input)\n-      catch {\n-        case e: ParsingException ⇒ fail(e.info)\n-        case NotEnoughDataException ⇒\n-          // we are missing a try/catch{continue} wrapper somewhere\n-          throw new IllegalStateException(\"unexpected NotEnoughDataException\", NotEnoughDataException)\n+  val in = Inlet[ByteString](\"BodyPartParser.in\")\n+  val out = Outlet[BodyPartParser.Output](\"BodyPartParser.out\")\n+\n+  override val shape = FlowShape(in, out)\n+\n+  override def createLogic(attributes: Attributes): GraphStageLogic =\n+    new GraphStageLogic(shape) with InHandler with OutHandler {\n+      private var output = collection.immutable.Queue.empty[Output]\n+      // FIXME this probably is too wasteful\n+      private var state: ByteString => StateResult = tryParseInitialBoundary\n+      private var terminated = false\n+\n+      override def onPush(): Unit = {\n+        if (!terminated) {\n+          val elem = grab(in)\n+          try state(elem)\n+          catch {\n+            case e: ParsingException => fail(e.info)\n+            case NotEnoughDataException =>\n+              // we are missing a try/catch{continue} wrapper somewhere\n+              throw new IllegalStateException(\"unexpected NotEnoughDataException\", NotEnoughDataException)\n+          }\n+          if (output.nonEmpty) push(out, dequeue())\n+          else if (!terminated) pull(in)\n+          else completeStage()\n+        } else completeStage()\n       }\n-      if (output.nonEmpty) ctx.push(dequeue())\n-      else if (!terminated) ctx.pull()\n-      else ctx.finish()\n-    } else ctx.finish()\n-\n-  override def onPull(ctx: Context[Output]): SyncDirective = {\n-    if (output.nonEmpty)\n-      ctx.push(dequeue())\n-    else if (ctx.isFinishing) {\n-      if (terminated) ctx.finish()\n-      else ctx.pushAndFinish(ParseError(ErrorInfo(\"Unexpected end of multipart entity\")))\n-    } else\n-      ctx.pull()\n-  }\n-\n-  override def onUpstreamFinish(ctx: Context[Output]): TerminationDirective = ctx.absorbTermination()\n-\n-  def tryParseInitialBoundary(input: ByteString): StateResult =\n-    // we don't use boyerMoore here because we are testing for the boundary *without* a\n-    // preceding CRLF and at a known location (the very beginning of the entity)\n-    try {\n-      if (boundary(input, 0)) {\n-        val ix = boundaryLength\n-        if (crlf(input, ix)) parseHeaderLines(input, ix + 2)\n-        else if (doubleDash(input, ix)) terminate()\n-        else parsePreamble(input, 0)\n-      } else parsePreamble(input, 0)\n-    } catch {\n-      case NotEnoughDataException ⇒ continue(input, 0)((newInput, _) ⇒ tryParseInitialBoundary(newInput))\n-    }\n \n-  def parsePreamble(input: ByteString, offset: Int): StateResult =\n-    try {\n-      @tailrec def rec(index: Int): StateResult = {\n-        val needleEnd = boyerMoore.nextIndex(input, index) + needle.length\n-        if (crlf(input, needleEnd)) parseHeaderLines(input, needleEnd + 2)\n-        else if (doubleDash(input, needleEnd)) terminate()\n-        else rec(needleEnd)\n+      override def onPull(): Unit = {\n+        if (output.nonEmpty)\n+          push(out, dequeue())\n+        else if (isClosed(in)) {\n+          if (!terminated) push(out, ParseError(ErrorInfo(\"Unexpected end of multipart entity\")))\n+          completeStage()\n+        } else pull(in)\n       }\n-      rec(offset)\n-    } catch {\n-      case NotEnoughDataException ⇒ continue(input.takeRight(needle.length + 2), 0)(parsePreamble)\n-    }\n \n-  @tailrec def parseHeaderLines(input: ByteString, lineStart: Int, headers: ListBuffer[HttpHeader] = ListBuffer[HttpHeader](),\n-                                headerCount: Int = 0, cth: Option[`Content-Type`] = None): StateResult = {\n-    def contentType =\n-      cth match {\n-        case Some(x) ⇒ x.contentType\n-        case None    ⇒ defaultContentType\n+      override def onUpstreamFinish(): Unit = {\n+        if (isAvailable(out)) onPull()","path":"akka-http-core/src/main/scala/akka/http/impl/engine/parsing/BodyPartParser.scala","position":131,"original_position":131,"commit_id":"b025545800ef3e1f974ef355f9abcf156135106e","original_commit_id":"b025545800ef3e1f974ef355f9abcf156135106e","user":{"login":"johanandren","id":666915,"avatar_url":"https://avatars.githubusercontent.com/u/666915?v=3","gravatar_id":"","url":"https://api.github.com/users/johanandren","html_url":"https://github.com/johanandren","followers_url":"https://api.github.com/users/johanandren/followers","following_url":"https://api.github.com/users/johanandren/following{/other_user}","gists_url":"https://api.github.com/users/johanandren/gists{/gist_id}","starred_url":"https://api.github.com/users/johanandren/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanandren/subscriptions","organizations_url":"https://api.github.com/users/johanandren/orgs","repos_url":"https://api.github.com/users/johanandren/repos","events_url":"https://api.github.com/users/johanandren/events{/privacy}","received_events_url":"https://api.github.com/users/johanandren/received_events","type":"User","site_admin":false},"body":"Different behavior from the original stage which did just absorb termination? We are not sure there has been a pull from downstream as upstream finishes, so if output is `nonEmpty` this would lead to trying to push to non-ready downstream.","created_at":"2016-04-19T08:51:36Z","updated_at":"2016-04-19T08:51:36Z","html_url":"https://github.com/akka/akka/pull/20356#discussion_r60193741","pull_request_url":"https://api.github.com/repos/akka/akka/pulls/20356","_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/comments/60193741"},"html":{"href":"https://github.com/akka/akka/pull/20356#discussion_r60193741"},"pull_request":{"href":"https://api.github.com/repos/akka/akka/pulls/20356"}}},"pull_request":{"url":"https://api.github.com/repos/akka/akka/pulls/20356","id":66866325,"html_url":"https://github.com/akka/akka/pull/20356","diff_url":"https://github.com/akka/akka/pull/20356.diff","patch_url":"https://github.com/akka/akka/pull/20356.patch","issue_url":"https://api.github.com/repos/akka/akka/issues/20356","number":20356,"state":"open","locked":false,"title":"Migrate BodyPartParser to GraphStage #20288.","user":{"login":"danxmoran","id":2755881,"avatar_url":"https://avatars.githubusercontent.com/u/2755881?v=3","gravatar_id":"","url":"https://api.github.com/users/danxmoran","html_url":"https://github.com/danxmoran","followers_url":"https://api.github.com/users/danxmoran/followers","following_url":"https://api.github.com/users/danxmoran/following{/other_user}","gists_url":"https://api.github.com/users/danxmoran/gists{/gist_id}","starred_url":"https://api.github.com/users/danxmoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danxmoran/subscriptions","organizations_url":"https://api.github.com/users/danxmoran/orgs","repos_url":"https://api.github.com/users/danxmoran/repos","events_url":"https://api.github.com/users/danxmoran/events{/privacy}","received_events_url":"https://api.github.com/users/danxmoran/received_events","type":"User","site_admin":false},"body":"Ref #20288.\r\n\r\n@johanandren here's BodyPartParser from #20327.  I'll open a follow-up with NaiveTake and ByteStringBatcher once this merges, to avoid adding noise with duplicate changes.","created_at":"2016-04-18T14:49:44Z","updated_at":"2016-04-19T08:51:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d31ea2651faba7d55a1f75127b706ff62c9e842","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/akka/akka/pulls/20356/commits","review_comments_url":"https://api.github.com/repos/akka/akka/pulls/20356/comments","review_comment_url":"https://api.github.com/repos/akka/akka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/akka/akka/issues/20356/comments","statuses_url":"https://api.github.com/repos/akka/akka/statuses/b025545800ef3e1f974ef355f9abcf156135106e","head":{"label":"danxmoran:danxmoran-20288-bodypartparser-to-gs","ref":"danxmoran-20288-bodypartparser-to-gs","sha":"b025545800ef3e1f974ef355f9abcf156135106e","user":{"login":"danxmoran","id":2755881,"avatar_url":"https://avatars.githubusercontent.com/u/2755881?v=3","gravatar_id":"","url":"https://api.github.com/users/danxmoran","html_url":"https://github.com/danxmoran","followers_url":"https://api.github.com/users/danxmoran/followers","following_url":"https://api.github.com/users/danxmoran/following{/other_user}","gists_url":"https://api.github.com/users/danxmoran/gists{/gist_id}","starred_url":"https://api.github.com/users/danxmoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danxmoran/subscriptions","organizations_url":"https://api.github.com/users/danxmoran/orgs","repos_url":"https://api.github.com/users/danxmoran/repos","events_url":"https://api.github.com/users/danxmoran/events{/privacy}","received_events_url":"https://api.github.com/users/danxmoran/received_events","type":"User","site_admin":false},"repo":{"id":50397237,"name":"akka","full_name":"danxmoran/akka","owner":{"login":"danxmoran","id":2755881,"avatar_url":"https://avatars.githubusercontent.com/u/2755881?v=3","gravatar_id":"","url":"https://api.github.com/users/danxmoran","html_url":"https://github.com/danxmoran","followers_url":"https://api.github.com/users/danxmoran/followers","following_url":"https://api.github.com/users/danxmoran/following{/other_user}","gists_url":"https://api.github.com/users/danxmoran/gists{/gist_id}","starred_url":"https://api.github.com/users/danxmoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danxmoran/subscriptions","organizations_url":"https://api.github.com/users/danxmoran/orgs","repos_url":"https://api.github.com/users/danxmoran/repos","events_url":"https://api.github.com/users/danxmoran/events{/privacy}","received_events_url":"https://api.github.com/users/danxmoran/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/danxmoran/akka","description":"Akka Project","fork":true,"url":"https://api.github.com/repos/danxmoran/akka","forks_url":"https://api.github.com/repos/danxmoran/akka/forks","keys_url":"https://api.github.com/repos/danxmoran/akka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/danxmoran/akka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/danxmoran/akka/teams","hooks_url":"https://api.github.com/repos/danxmoran/akka/hooks","issue_events_url":"https://api.github.com/repos/danxmoran/akka/issues/events{/number}","events_url":"https://api.github.com/repos/danxmoran/akka/events","assignees_url":"https://api.github.com/repos/danxmoran/akka/assignees{/user}","branches_url":"https://api.github.com/repos/danxmoran/akka/branches{/branch}","tags_url":"https://api.github.com/repos/danxmoran/akka/tags","blobs_url":"https://api.github.com/repos/danxmoran/akka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/danxmoran/akka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/danxmoran/akka/git/refs{/sha}","trees_url":"https://api.github.com/repos/danxmoran/akka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/danxmoran/akka/statuses/{sha}","languages_url":"https://api.github.com/repos/danxmoran/akka/languages","stargazers_url":"https://api.github.com/repos/danxmoran/akka/stargazers","contributors_url":"https://api.github.com/repos/danxmoran/akka/contributors","subscribers_url":"https://api.github.com/repos/danxmoran/akka/subscribers","subscription_url":"https://api.github.com/repos/danxmoran/akka/subscription","commits_url":"https://api.github.com/repos/danxmoran/akka/commits{/sha}","git_commits_url":"https://api.github.com/repos/danxmoran/akka/git/commits{/sha}","comments_url":"https://api.github.com/repos/danxmoran/akka/comments{/number}","issue_comment_url":"https://api.github.com/repos/danxmoran/akka/issues/comments{/number}","contents_url":"https://api.github.com/repos/danxmoran/akka/contents/{+path}","compare_url":"https://api.github.com/repos/danxmoran/akka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/danxmoran/akka/merges","archive_url":"https://api.github.com/repos/danxmoran/akka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/danxmoran/akka/downloads","issues_url":"https://api.github.com/repos/danxmoran/akka/issues{/number}","pulls_url":"https://api.github.com/repos/danxmoran/akka/pulls{/number}","milestones_url":"https://api.github.com/repos/danxmoran/akka/milestones{/number}","notifications_url":"https://api.github.com/repos/danxmoran/akka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/danxmoran/akka/labels{/name}","releases_url":"https://api.github.com/repos/danxmoran/akka/releases{/id}","deployments_url":"https://api.github.com/repos/danxmoran/akka/deployments","created_at":"2016-01-26T02:31:39Z","updated_at":"2016-01-26T02:31:50Z","pushed_at":"2016-04-18T14:46:18Z","git_url":"git://github.com/danxmoran/akka.git","ssh_url":"git@github.com:danxmoran/akka.git","clone_url":"https://github.com/danxmoran/akka.git","svn_url":"https://github.com/danxmoran/akka","homepage":"http://akka.io","size":192328,"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":"ade89edbb7b6d17db1a544a9c4674e910a9fec23","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}","deployments_url":"https://api.github.com/repos/akka/akka/deployments","created_at":"2009-02-16T12:51:54Z","updated_at":"2016-04-19T07:04:50Z","pushed_at":"2016-04-19T08:28:35Z","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":204552,"stargazers_count":5383,"watchers_count":5383,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1677,"mirror_url":null,"open_issues_count":728,"forks":1677,"open_issues":728,"watchers":5383,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/akka/akka/pulls/20356"},"html":{"href":"https://github.com/akka/akka/pull/20356"},"issue":{"href":"https://api.github.com/repos/akka/akka/issues/20356"},"comments":{"href":"https://api.github.com/repos/akka/akka/issues/20356/comments"},"review_comments":{"href":"https://api.github.com/repos/akka/akka/pulls/20356/comments"},"review_comment":{"href":"https://api.github.com/repos/akka/akka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/akka/akka/pulls/20356/commits"},"statuses":{"href":"https://api.github.com/repos/akka/akka/statuses/b025545800ef3e1f974ef355f9abcf156135106e"}}}}