{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/shelf/issues/60","repository_url":"https://api.github.com/repos/dart-lang/shelf","labels_url":"https://api.github.com/repos/dart-lang/shelf/issues/60/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/shelf/issues/60/comments","events_url":"https://api.github.com/repos/dart-lang/shelf/issues/60/events","html_url":"https://github.com/dart-lang/shelf/issues/60","id":184710909,"number":60,"title":"Status 204 No Content: Not spec conform","user":{"login":"dhenneke","id":720821,"avatar_url":"https://avatars.githubusercontent.com/u/720821?v=3","gravatar_id":"","url":"https://api.github.com/users/dhenneke","html_url":"https://github.com/dhenneke","followers_url":"https://api.github.com/users/dhenneke/followers","following_url":"https://api.github.com/users/dhenneke/following{/other_user}","gists_url":"https://api.github.com/users/dhenneke/gists{/gist_id}","starred_url":"https://api.github.com/users/dhenneke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dhenneke/subscriptions","organizations_url":"https://api.github.com/users/dhenneke/orgs","repos_url":"https://api.github.com/users/dhenneke/repos","events_url":"https://api.github.com/users/dhenneke/events{/privacy}","received_events_url":"https://api.github.com/users/dhenneke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-10-23T19:45:58Z","updated_at":"2016-10-24T19:47:54Z","closed_at":null,"body":"When responding to a HttpRequest with a 204 No Content status and no body, a body containing the number \"0\" is returned. This confuses some proxy servers (in case of keep alive). According to the spec:\r\n\r\n> The 204 response MUST NOT include a message-body, and thus is always\r\n   terminated by the first empty line after the header fields.\r\n   https://tools.ietf.org/html/rfc2616#section-10.2.5\r\n\r\nWe are using the following example code:\r\n\r\n```\r\nimport 'package:shelf/shelf.dart' as shelf;\r\nimport 'package:shelf/shelf_io.dart' as io;\r\n\r\nvoid main() {\r\n  var handler = const shelf.Pipeline().addMiddleware(shelf.logRequests())\r\n      .addHandler(_echoRequest);\r\n\r\n  io.serve(handler, '0.0.0.0', 8080).then((server) {\r\n    print('Serving at http://${server.address.host}:${server.port}');\r\n  });\r\n}\r\n\r\nshelf.Response _echoRequest(shelf.Request request) {\r\n  return new shelf.Response(204);\r\n}\r\n```\r\n\r\nWireshark shows the malformed result:\r\n![image](https://cloud.githubusercontent.com/assets/720821/19628861/fb1a2108-9967-11e6-9010-114292a89de7.png)\r\n\r\nWe debugged the cause:\r\n1. We don't supply a body to `new shelf.Response(204)` so it internally creates an empty array as body.\r\n2. On Response generation (in dart:io) the \"Transfer-Encoding\" header defaults to \"chunked\" and thus the framework adds the 0 as initial chunk length of 0.\r\n\r\nWe managed to circumvent the problem by manually forcing the \"Transfer-Encoding\" header to \"identity\" for the 204 status results in a shelf middleware. However this issue should be fixed in order to be conformant to RFC 2616. But we are not sure if the issue is located in shelf or in dart:io.\r\n\r\nUpdate: This is issue is also present for `new Response.notModified();` (i.e. status code 304)."},"comment":{"url":"https://api.github.com/repos/dart-lang/shelf/issues/comments/255845511","html_url":"https://github.com/dart-lang/shelf/issues/60#issuecomment-255845511","issue_url":"https://api.github.com/repos/dart-lang/shelf/issues/60","id":255845511,"user":{"login":"nex3","id":188,"avatar_url":"https://avatars.githubusercontent.com/u/188?v=3","gravatar_id":"","url":"https://api.github.com/users/nex3","html_url":"https://github.com/nex3","followers_url":"https://api.github.com/users/nex3/followers","following_url":"https://api.github.com/users/nex3/following{/other_user}","gists_url":"https://api.github.com/users/nex3/gists{/gist_id}","starred_url":"https://api.github.com/users/nex3/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nex3/subscriptions","organizations_url":"https://api.github.com/users/nex3/orgs","repos_url":"https://api.github.com/users/nex3/repos","events_url":"https://api.github.com/users/nex3/events{/privacy}","received_events_url":"https://api.github.com/users/nex3/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T19:47:54Z","updated_at":"2016-10-24T19:47:54Z","body":"This is really an issue in `dart:io`. It shouldn't force empty-bodied responses to be chunked, especially when they have a status code that disallows that. I've filed dart-lang/sdk#27660 to track that.\r\n\r\nWe can still work around this in shelf, though, so I'm keeping this issue open."}}
{"actor":{"display_login":"nex3"}}