{"action":"created","comment":{"url":"https://api.github.com/repos/twitter/finagle/pulls/comments/85768565","pull_request_review_id":6461152,"id":85768565,"diff_hunk":"@@ -36,13 +39,57 @@ private[codec] object ResponseConformanceFilter extends SimpleFilter[Request, Re\n   private[this] def validate(req: Request, rep: Response): Unit = {\n     if (req.method == Method.Head) {\n       handleHeadResponse(req, rep)\n+    } else if (mustNotIncludeMessageBody(rep.status)) {\n+      handleNoMessageResponse(rep)\n     } else if (rep.isChunked) {\n       handleChunkedResponse(rep)\n     } else {\n       handleFullyBufferedResponse(rep)\n     }\n   }\n \n+  /**\n+   * 1. To conform to the RFC, a message body is removed if a status code is either 1xx, 204 or 304.\n+   *\n+   * RFC7230 section-3.3: (https://tools.ietf.org/html/rfc7230#section-3.3)\n+   * \"All 1xx (Informational), 204 (No Content), and 304 (Not Modified) responses do not include a message body.\"\n+   *\n+   * 2. Additionally, a Content-Length header field is dropped for 1xx and 204 responses as described in RFC7230\n+   * section-3.3.2. It, however, is allowed to send a Content-Length header field in a 304 response. To follow\n+   * the section, we don't remove the header field from a 304 response but its value is not checked nor corrected.\n+   *\n+   * RFC7230 section-3.3.2: (https://tools.ietf.org/html/rfc7230#section-3.3.2)\n+   * \"A server MUST NOT send a Content-Length header field in any response with a status code of 1xx (Informational)\n+   * or 204 (No Content).\"\n+   *\n+   * \"A server MAY send a Content-Length header field in a 304 (Not Modified) response to a conditional GET request\n+   * (Section 4.1 of [RFC7232]); a server MUST NOT send Content-Length in such a response unless its field-value equals\n+   * the decimal number of octets that would have been sent in the payload body of a 200 (OK) response to the same\n+   * request.\"\n+   */\n+  private[this] def handleNoMessageResponse(rep: Response): Unit = {\n+      if (rep.getContent() != ChannelBuffers.EMPTY_BUFFER) {\n+        rep.clearContent()\n+        logger.error(\n+          \"Response with a status code of %d must not have a body-message thus the content has been removed.\",\n+          rep.statusCode)\n+      }\n+\n+      rep.status match {\n+        case Continue | SwitchingProtocols | Processing | NoContent if rep.contentLength.isDefined =>\n+          rep.headerMap.remove(Fields.ContentLength)\n+          logger.error(\n+            \"Response with a status code of %d must not have a Content-Length header field thus the field has been removed.\",\n+            rep.statusCode)\n+        case _ =>\n+      }\n+  }\n+\n+  private def mustNotIncludeMessageBody(status: Status): Boolean = status match {","path":"finagle-http/src/main/scala/com/twitter/finagle/http/codec/ResponseConformanceFilter.scala","position":65,"original_position":65,"commit_id":"b291e46904e99de9aa39a2a8c23d78e94c678e1f","original_commit_id":"b291e46904e99de9aa39a2a8c23d78e94c678e1f","user":{"login":"bryce-anderson","id":2948506,"avatar_url":"https://avatars.githubusercontent.com/u/2948506?v=3","gravatar_id":"","url":"https://api.github.com/users/bryce-anderson","html_url":"https://github.com/bryce-anderson","followers_url":"https://api.github.com/users/bryce-anderson/followers","following_url":"https://api.github.com/users/bryce-anderson/following{/other_user}","gists_url":"https://api.github.com/users/bryce-anderson/gists{/gist_id}","starred_url":"https://api.github.com/users/bryce-anderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bryce-anderson/subscriptions","organizations_url":"https://api.github.com/users/bryce-anderson/orgs","repos_url":"https://api.github.com/users/bryce-anderson/repos","events_url":"https://api.github.com/users/bryce-anderson/events{/privacy}","received_events_url":"https://api.github.com/users/bryce-anderson/received_events","type":"User","site_admin":false},"body":"This has the same 1xx problem as above.\r\nMaybe this is worth it, maybe its not, but it seems to me that this pattern match could be reused with a special case for `NotModified`. Eg\r\n```scala\r\nprivate def mustNotHaveLengthHeader(status: Status) = \r\n  status != NotModified && mostNotIncludeMessageBody(status)\r\n```\r\n\r\nMaybe that is getting too convoluted, so use discretion with that suggestion.","created_at":"2016-10-31T15:51:41Z","updated_at":"2016-10-31T15:57:20Z","html_url":"https://github.com/twitter/finagle/pull/521#discussion_r85768565","pull_request_url":"https://api.github.com/repos/twitter/finagle/pulls/521","_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments/85768565"},"html":{"href":"https://github.com/twitter/finagle/pull/521#discussion_r85768565"},"pull_request":{"href":"https://api.github.com/repos/twitter/finagle/pulls/521"}}},"pull_request":{"url":"https://api.github.com/repos/twitter/finagle/pulls/521","id":75206132,"html_url":"https://github.com/twitter/finagle/pull/521","diff_url":"https://github.com/twitter/finagle/pull/521.diff","patch_url":"https://github.com/twitter/finagle/pull/521.patch","issue_url":"https://api.github.com/repos/twitter/finagle/issues/521","number":521,"state":"open","locked":false,"title":"finagle-http: Remove body (and Content-Length) from 1xx, 204 and 304 responses","user":{"login":"monkey-mas","id":5261677,"avatar_url":"https://avatars.githubusercontent.com/u/5261677?v=3","gravatar_id":"","url":"https://api.github.com/users/monkey-mas","html_url":"https://github.com/monkey-mas","followers_url":"https://api.github.com/users/monkey-mas/followers","following_url":"https://api.github.com/users/monkey-mas/following{/other_user}","gists_url":"https://api.github.com/users/monkey-mas/gists{/gist_id}","starred_url":"https://api.github.com/users/monkey-mas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkey-mas/subscriptions","organizations_url":"https://api.github.com/users/monkey-mas/orgs","repos_url":"https://api.github.com/users/monkey-mas/repos","events_url":"https://api.github.com/users/monkey-mas/events{/privacy}","received_events_url":"https://api.github.com/users/monkey-mas/received_events","type":"User","site_admin":false},"body":"Problem\n\n~~We currently have two problems. Firstly, as described in [RFC2616](https://tools.ietf.org/html/rfc2616) and\n[RFC7231](https://tools.ietf.org/html/rfc7231), 204 and 304 responses must not contain a message-body. This\nrequirement was not enforced in finagle, i.e., a message-body can be\nadded. Moreover, a Content-Length header field can be added to these responses,\nwhich is not allowed as mentioned in [RFC7230#section-3.3.2](https://tools.ietf.org/html/rfc7230#section-3.3.2).~~\n\n```\nWe currently have two problems. Firstly, as described in RFC2616 and\nRFC7230, 1xx, 204 and 304 responses must not contain a message-body. This\nrequirement was not enforced in finagle, i.e., a message-body can be\nadded. Moreover, a Content-Length header field can be added to 1xx and\n204 responses, which is not allowed as mentioned in RFC7230#section-3.3.2.\n```\n\nSolution\n\n~~First of all, we have to clear a message-body, which we call content in finagle,\nif the response status code is either 204 or 304 to satisfy RFC7231. Secondly,\nwe need to make sure not to add a Content-Length header field in a 204 response\nto follow RFC7230#section-3.3.2. With regard to a 304 response, a server may\nsend a Content-Length header as mentioned in the same section. Thus it'd be\nbetter for us to allow users to set the field with a value of 0 if they like.\nMost importantly, [we make sure that these things are achieved and the new system\nis bugwards-compatible by provding a new filter](https://github.com/twitter/finagle/pull/521#issuecomment-228566007).~~\n\n```\nFirstly, we have to clear a message-body, which we call content in finagle,\nif the response status code is either 1xx, 204 or 304 to satisfy RFC7230.\nThen, we need to remove a Content-Length header field in 1xx and 204 responses\nto follow RFC7230#section-3.3.2. With regard to a 304 response, we don't\nintentionally remove it even though a Content-Length header field is set.\n```\n\nResult\n\nWe follow the specification of RFC with regard to a message-header and\nmessage-body except that we have not added some header fields required in a\nresponse with status code 304 to satisfy [RFC7232#section-4.1](https://tools.ietf.org/html/rfc7232#section-4.1); Any of the\nfollowing header fields must be generated: Cache-Control, Content-Location,\nDate, ETag, Expires, and Vary.\n~~As we achieve this by creating a new filter and set it to [Http.scala](https://github.com/monkey-mas/finagle/blob/finagle-6.35.0/finagle-http/src/main/scala/com/twitter/finagle/Http.scala#L298-L304), users\nwho are not willing to make use of the functionality can easily disable it\nby removing the filter.~~\n","created_at":"2016-06-25T14:39:33Z","updated_at":"2016-10-31T15:57:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f157df821ae5cbfa5f96e8eff469505ac3688ccd","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/twitter/finagle/pulls/521/commits","review_comments_url":"https://api.github.com/repos/twitter/finagle/pulls/521/comments","review_comment_url":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twitter/finagle/issues/521/comments","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/b291e46904e99de9aa39a2a8c23d78e94c678e1f","head":{"label":"monkey-mas:fix-body-and-header-in-204-and-304","ref":"fix-body-and-header-in-204-and-304","sha":"b291e46904e99de9aa39a2a8c23d78e94c678e1f","user":{"login":"monkey-mas","id":5261677,"avatar_url":"https://avatars.githubusercontent.com/u/5261677?v=3","gravatar_id":"","url":"https://api.github.com/users/monkey-mas","html_url":"https://github.com/monkey-mas","followers_url":"https://api.github.com/users/monkey-mas/followers","following_url":"https://api.github.com/users/monkey-mas/following{/other_user}","gists_url":"https://api.github.com/users/monkey-mas/gists{/gist_id}","starred_url":"https://api.github.com/users/monkey-mas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkey-mas/subscriptions","organizations_url":"https://api.github.com/users/monkey-mas/orgs","repos_url":"https://api.github.com/users/monkey-mas/repos","events_url":"https://api.github.com/users/monkey-mas/events{/privacy}","received_events_url":"https://api.github.com/users/monkey-mas/received_events","type":"User","site_admin":false},"repo":{"id":61439509,"name":"finagle","full_name":"monkey-mas/finagle","owner":{"login":"monkey-mas","id":5261677,"avatar_url":"https://avatars.githubusercontent.com/u/5261677?v=3","gravatar_id":"","url":"https://api.github.com/users/monkey-mas","html_url":"https://github.com/monkey-mas","followers_url":"https://api.github.com/users/monkey-mas/followers","following_url":"https://api.github.com/users/monkey-mas/following{/other_user}","gists_url":"https://api.github.com/users/monkey-mas/gists{/gist_id}","starred_url":"https://api.github.com/users/monkey-mas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monkey-mas/subscriptions","organizations_url":"https://api.github.com/users/monkey-mas/orgs","repos_url":"https://api.github.com/users/monkey-mas/repos","events_url":"https://api.github.com/users/monkey-mas/events{/privacy}","received_events_url":"https://api.github.com/users/monkey-mas/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/monkey-mas/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":true,"url":"https://api.github.com/repos/monkey-mas/finagle","forks_url":"https://api.github.com/repos/monkey-mas/finagle/forks","keys_url":"https://api.github.com/repos/monkey-mas/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monkey-mas/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monkey-mas/finagle/teams","hooks_url":"https://api.github.com/repos/monkey-mas/finagle/hooks","issue_events_url":"https://api.github.com/repos/monkey-mas/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/monkey-mas/finagle/events","assignees_url":"https://api.github.com/repos/monkey-mas/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/monkey-mas/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/monkey-mas/finagle/tags","blobs_url":"https://api.github.com/repos/monkey-mas/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monkey-mas/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monkey-mas/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/monkey-mas/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monkey-mas/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/monkey-mas/finagle/languages","stargazers_url":"https://api.github.com/repos/monkey-mas/finagle/stargazers","contributors_url":"https://api.github.com/repos/monkey-mas/finagle/contributors","subscribers_url":"https://api.github.com/repos/monkey-mas/finagle/subscribers","subscription_url":"https://api.github.com/repos/monkey-mas/finagle/subscription","commits_url":"https://api.github.com/repos/monkey-mas/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/monkey-mas/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/monkey-mas/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/monkey-mas/finagle/issues/comments{/number}","contents_url":"https://api.github.com/repos/monkey-mas/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/monkey-mas/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monkey-mas/finagle/merges","archive_url":"https://api.github.com/repos/monkey-mas/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monkey-mas/finagle/downloads","issues_url":"https://api.github.com/repos/monkey-mas/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/monkey-mas/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/monkey-mas/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/monkey-mas/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monkey-mas/finagle/labels{/name}","releases_url":"https://api.github.com/repos/monkey-mas/finagle/releases{/id}","deployments_url":"https://api.github.com/repos/monkey-mas/finagle/deployments","created_at":"2016-06-18T15:22:09Z","updated_at":"2016-06-18T15:22:14Z","pushed_at":"2016-10-31T14:36:38Z","git_url":"git://github.com/monkey-mas/finagle.git","ssh_url":"git@github.com:monkey-mas/finagle.git","clone_url":"https://github.com/monkey-mas/finagle.git","svn_url":"https://github.com/monkey-mas/finagle","homepage":"http://twitter.github.io/finagle","size":39266,"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":"develop"}},"base":{"label":"twitter:develop","ref":"develop","sha":"792498babeb42a22827b7577639654d2cc0e6474","user":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"repo":{"id":1007362,"name":"finagle","full_name":"twitter/finagle","owner":{"login":"twitter","id":50278,"avatar_url":"https://avatars.githubusercontent.com/u/50278?v=3","gravatar_id":"","url":"https://api.github.com/users/twitter","html_url":"https://github.com/twitter","followers_url":"https://api.github.com/users/twitter/followers","following_url":"https://api.github.com/users/twitter/following{/other_user}","gists_url":"https://api.github.com/users/twitter/gists{/gist_id}","starred_url":"https://api.github.com/users/twitter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twitter/subscriptions","organizations_url":"https://api.github.com/users/twitter/orgs","repos_url":"https://api.github.com/users/twitter/repos","events_url":"https://api.github.com/users/twitter/events{/privacy}","received_events_url":"https://api.github.com/users/twitter/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twitter/finagle","description":"A fault tolerant, protocol-agnostic RPC system","fork":false,"url":"https://api.github.com/repos/twitter/finagle","forks_url":"https://api.github.com/repos/twitter/finagle/forks","keys_url":"https://api.github.com/repos/twitter/finagle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twitter/finagle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twitter/finagle/teams","hooks_url":"https://api.github.com/repos/twitter/finagle/hooks","issue_events_url":"https://api.github.com/repos/twitter/finagle/issues/events{/number}","events_url":"https://api.github.com/repos/twitter/finagle/events","assignees_url":"https://api.github.com/repos/twitter/finagle/assignees{/user}","branches_url":"https://api.github.com/repos/twitter/finagle/branches{/branch}","tags_url":"https://api.github.com/repos/twitter/finagle/tags","blobs_url":"https://api.github.com/repos/twitter/finagle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twitter/finagle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twitter/finagle/git/refs{/sha}","trees_url":"https://api.github.com/repos/twitter/finagle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twitter/finagle/statuses/{sha}","languages_url":"https://api.github.com/repos/twitter/finagle/languages","stargazers_url":"https://api.github.com/repos/twitter/finagle/stargazers","contributors_url":"https://api.github.com/repos/twitter/finagle/contributors","subscribers_url":"https://api.github.com/repos/twitter/finagle/subscribers","subscription_url":"https://api.github.com/repos/twitter/finagle/subscription","commits_url":"https://api.github.com/repos/twitter/finagle/commits{/sha}","git_commits_url":"https://api.github.com/repos/twitter/finagle/git/commits{/sha}","comments_url":"https://api.github.com/repos/twitter/finagle/comments{/number}","issue_comment_url":"https://api.github.com/repos/twitter/finagle/issues/comments{/number}","contents_url":"https://api.github.com/repos/twitter/finagle/contents/{+path}","compare_url":"https://api.github.com/repos/twitter/finagle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twitter/finagle/merges","archive_url":"https://api.github.com/repos/twitter/finagle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twitter/finagle/downloads","issues_url":"https://api.github.com/repos/twitter/finagle/issues{/number}","pulls_url":"https://api.github.com/repos/twitter/finagle/pulls{/number}","milestones_url":"https://api.github.com/repos/twitter/finagle/milestones{/number}","notifications_url":"https://api.github.com/repos/twitter/finagle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twitter/finagle/labels{/name}","releases_url":"https://api.github.com/repos/twitter/finagle/releases{/id}","deployments_url":"https://api.github.com/repos/twitter/finagle/deployments","created_at":"2010-10-19T22:10:09Z","updated_at":"2016-10-31T06:45:20Z","pushed_at":"2016-10-31T14:36:39Z","git_url":"git://github.com/twitter/finagle.git","ssh_url":"git@github.com:twitter/finagle.git","clone_url":"https://github.com/twitter/finagle.git","svn_url":"https://github.com/twitter/finagle","homepage":"http://twitter.github.io/finagle","size":48658,"stargazers_count":5170,"watchers_count":5170,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":979,"mirror_url":null,"open_issues_count":33,"forks":979,"open_issues":33,"watchers":5170,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/twitter/finagle/pulls/521"},"html":{"href":"https://github.com/twitter/finagle/pull/521"},"issue":{"href":"https://api.github.com/repos/twitter/finagle/issues/521"},"comments":{"href":"https://api.github.com/repos/twitter/finagle/issues/521/comments"},"review_comments":{"href":"https://api.github.com/repos/twitter/finagle/pulls/521/comments"},"review_comment":{"href":"https://api.github.com/repos/twitter/finagle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twitter/finagle/pulls/521/commits"},"statuses":{"href":"https://api.github.com/repos/twitter/finagle/statuses/b291e46904e99de9aa39a2a8c23d78e94c678e1f"}}}}
{"actor":{"display_login":"bryce-anderson"}}