{"action":"created","comment":{"url":"https://api.github.com/repos/reactphp/http/pulls/comments/108059462","pull_request_review_id":29068055,"id":108059462,"diff_hunk":"@@ -210,58 +240,121 @@ Note that this value may be `null` if the request body size is unknown in\n advance because the request message uses chunked transfer encoding.\n \n ```php \n-$http = new Server($socket, function (RequestInterface $request, Response $response) {\n+$http = new Server($socket, function (RequestInterface $request) {\n     $size = $request->getBody()->getSize();\n     if ($size === null) {\n-        $response->writeHead(411, array('Content-Type' => 'text/plain'));\n-        $response->write('The request does not contain an explicit length.');\n-        $response->write('This server does not accept chunked transfer encoding.');\n-        $response->end();\n-        return;\n+        $body = 'The request does not contain an explicit length.';\n+        $body .= 'This server does not accept chunked transfer encoding.';\n+\n+        return new Response(\n+            411,\n+            array('Content-Type' => 'text/plain'),\n+            $body\n+        );\n     }\n-    $response->writeHead(200, array('Content-Type' => 'text/plain'));\n-    $response->end(\"Request body size: \" . $size . \" bytes\\n\");\n+\n+    return new Response(\n+        200,\n+        array('Content-Type' => 'text/plain'),\n+        \"Request body size: \" . $size . \" bytes\\n\"\n+    );\n });\n ```\n \n ### Response\n \n-The `Response` class is responsible for streaming the outgoing response body.\n+The callback function passed to the constructor of the [Server](#server)\n+is responsible to return process a response, which will be delivered to the client.\n+This function MUST return either the \n+[PSR-7 ResponseInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#33-psrhttpmessageresponseinterface)\n+object or a \n+[ReactPHP Promise](https://github.com/reactphp/promise#reactpromise)\n+which will resolve a `PSR-7 ResponseInterface` object.\n \n-It implements the `WritableStreamInterface`.\n+```php \n+$http = new Server($socket, function (RequestInterface $request, Response $response) {\n+    $body = \"The method of the request is: \" . $request->getMethod();\n+    $body .= \"The requested path is: \" . $request->getUri()->getPath();\n \n See also [example #3](examples) for more details.\n \n The constructor is internal, you SHOULD NOT call this yourself.\n The `Server` is responsible for emitting `Request` and `Response` objects.","path":"README.md","position":179,"original_position":179,"commit_id":"c0aef5da52404f458222acf3554c5f591c63395d","original_commit_id":"c0aef5da52404f458222acf3554c5f591c63395d","user":{"login":"WyriHaximus","id":147145,"avatar_url":"https://avatars1.githubusercontent.com/u/147145?v=3","gravatar_id":"","url":"https://api.github.com/users/WyriHaximus","html_url":"https://github.com/WyriHaximus","followers_url":"https://api.github.com/users/WyriHaximus/followers","following_url":"https://api.github.com/users/WyriHaximus/following{/other_user}","gists_url":"https://api.github.com/users/WyriHaximus/gists{/gist_id}","starred_url":"https://api.github.com/users/WyriHaximus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WyriHaximus/subscriptions","organizations_url":"https://api.github.com/users/WyriHaximus/orgs","repos_url":"https://api.github.com/users/WyriHaximus/repos","events_url":"https://api.github.com/users/WyriHaximus/events{/privacy}","received_events_url":"https://api.github.com/users/WyriHaximus/received_events","type":"User","site_admin":false},"body":"This line and the 3 lines above it are no longer relevant and ended up in middle of a code example, see https://github.com/legionth/http/blob/c0aef5da52404f458222acf3554c5f591c63395d/README.md#response","created_at":"2017-03-26T12:34:21Z","updated_at":"2017-03-26T12:40:53Z","html_url":"https://github.com/reactphp/http/pull/152#discussion_r108059462","pull_request_url":"https://api.github.com/repos/reactphp/http/pulls/152","_links":{"self":{"href":"https://api.github.com/repos/reactphp/http/pulls/comments/108059462"},"html":{"href":"https://github.com/reactphp/http/pull/152#discussion_r108059462"},"pull_request":{"href":"https://api.github.com/repos/reactphp/http/pulls/152"}}},"pull_request":{"url":"https://api.github.com/repos/reactphp/http/pulls/152","id":112614015,"html_url":"https://github.com/reactphp/http/pull/152","diff_url":"https://github.com/reactphp/http/pull/152.diff","patch_url":"https://github.com/reactphp/http/pull/152.patch","issue_url":"https://api.github.com/repos/reactphp/http/issues/152","number":152,"state":"open","locked":false,"title":"Replace Response class with PSR-7 Response class","user":{"login":"legionth","id":1578709,"avatar_url":"https://avatars3.githubusercontent.com/u/1578709?v=3","gravatar_id":"","url":"https://api.github.com/users/legionth","html_url":"https://github.com/legionth","followers_url":"https://api.github.com/users/legionth/followers","following_url":"https://api.github.com/users/legionth/following{/other_user}","gists_url":"https://api.github.com/users/legionth/gists{/gist_id}","starred_url":"https://api.github.com/users/legionth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionth/subscriptions","organizations_url":"https://api.github.com/users/legionth/orgs","repos_url":"https://api.github.com/users/legionth/repos","events_url":"https://api.github.com/users/legionth/events{/privacy}","received_events_url":"https://api.github.com/users/legionth/received_events","type":"User","site_admin":false},"body":"This is big PR. I recommend to try reviewing the single commits here.\r\n\r\nThe `Response` class will be replaced with an that implements the [PSR-7 ResponseInterface](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message.md#33-psrhttpmessageresponseinterface).\r\nSo the callback function only needs the request object to be called. A `PSR-7 Response` object will now be returned. Alternatively a [Promise](https://github.com/reactphp/promise#reactpromise) can be returned in this function, but this promise MUST resolve a `PSR-7 Response`. If the response need time be created, a promise must be used (checkout `examples/04-stream-request.php`).\r\n\r\nThe new `Response` extends from `RingCentral\\Psr7\\Response` but adds the possibility to add an [ReadstreamInterface implemnation](https://github.com/reactphp/stream#readablestreaminterface) as body.\r\n\r\n","created_at":"2017-03-26T04:27:46Z","updated_at":"2017-03-26T12:40:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e628795b6f1751e66d204524adccc371f170ed98","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/reactphp/http/pulls/152/commits","review_comments_url":"https://api.github.com/repos/reactphp/http/pulls/152/comments","review_comment_url":"https://api.github.com/repos/reactphp/http/pulls/comments{/number}","comments_url":"https://api.github.com/repos/reactphp/http/issues/152/comments","statuses_url":"https://api.github.com/repos/reactphp/http/statuses/c0aef5da52404f458222acf3554c5f591c63395d","head":{"label":"legionth:handle-psr7-responses","ref":"handle-psr7-responses","sha":"c0aef5da52404f458222acf3554c5f591c63395d","user":{"login":"legionth","id":1578709,"avatar_url":"https://avatars3.githubusercontent.com/u/1578709?v=3","gravatar_id":"","url":"https://api.github.com/users/legionth","html_url":"https://github.com/legionth","followers_url":"https://api.github.com/users/legionth/followers","following_url":"https://api.github.com/users/legionth/following{/other_user}","gists_url":"https://api.github.com/users/legionth/gists{/gist_id}","starred_url":"https://api.github.com/users/legionth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionth/subscriptions","organizations_url":"https://api.github.com/users/legionth/orgs","repos_url":"https://api.github.com/users/legionth/repos","events_url":"https://api.github.com/users/legionth/events{/privacy}","received_events_url":"https://api.github.com/users/legionth/received_events","type":"User","site_admin":false},"repo":{"id":81201374,"name":"http","full_name":"legionth/http","owner":{"login":"legionth","id":1578709,"avatar_url":"https://avatars3.githubusercontent.com/u/1578709?v=3","gravatar_id":"","url":"https://api.github.com/users/legionth","html_url":"https://github.com/legionth","followers_url":"https://api.github.com/users/legionth/followers","following_url":"https://api.github.com/users/legionth/following{/other_user}","gists_url":"https://api.github.com/users/legionth/gists{/gist_id}","starred_url":"https://api.github.com/users/legionth/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionth/subscriptions","organizations_url":"https://api.github.com/users/legionth/orgs","repos_url":"https://api.github.com/users/legionth/repos","events_url":"https://api.github.com/users/legionth/events{/privacy}","received_events_url":"https://api.github.com/users/legionth/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/legionth/http","description":"React HTTP server (unstable)","fork":true,"url":"https://api.github.com/repos/legionth/http","forks_url":"https://api.github.com/repos/legionth/http/forks","keys_url":"https://api.github.com/repos/legionth/http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/legionth/http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/legionth/http/teams","hooks_url":"https://api.github.com/repos/legionth/http/hooks","issue_events_url":"https://api.github.com/repos/legionth/http/issues/events{/number}","events_url":"https://api.github.com/repos/legionth/http/events","assignees_url":"https://api.github.com/repos/legionth/http/assignees{/user}","branches_url":"https://api.github.com/repos/legionth/http/branches{/branch}","tags_url":"https://api.github.com/repos/legionth/http/tags","blobs_url":"https://api.github.com/repos/legionth/http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/legionth/http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/legionth/http/git/refs{/sha}","trees_url":"https://api.github.com/repos/legionth/http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/legionth/http/statuses/{sha}","languages_url":"https://api.github.com/repos/legionth/http/languages","stargazers_url":"https://api.github.com/repos/legionth/http/stargazers","contributors_url":"https://api.github.com/repos/legionth/http/contributors","subscribers_url":"https://api.github.com/repos/legionth/http/subscribers","subscription_url":"https://api.github.com/repos/legionth/http/subscription","commits_url":"https://api.github.com/repos/legionth/http/commits{/sha}","git_commits_url":"https://api.github.com/repos/legionth/http/git/commits{/sha}","comments_url":"https://api.github.com/repos/legionth/http/comments{/number}","issue_comment_url":"https://api.github.com/repos/legionth/http/issues/comments{/number}","contents_url":"https://api.github.com/repos/legionth/http/contents/{+path}","compare_url":"https://api.github.com/repos/legionth/http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/legionth/http/merges","archive_url":"https://api.github.com/repos/legionth/http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/legionth/http/downloads","issues_url":"https://api.github.com/repos/legionth/http/issues{/number}","pulls_url":"https://api.github.com/repos/legionth/http/pulls{/number}","milestones_url":"https://api.github.com/repos/legionth/http/milestones{/number}","notifications_url":"https://api.github.com/repos/legionth/http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/legionth/http/labels{/name}","releases_url":"https://api.github.com/repos/legionth/http/releases{/id}","deployments_url":"https://api.github.com/repos/legionth/http/deployments","created_at":"2017-02-07T11:34:23Z","updated_at":"2017-02-07T11:34:25Z","pushed_at":"2017-03-26T04:02:56Z","git_url":"git://github.com/legionth/http.git","ssh_url":"git@github.com:legionth/http.git","clone_url":"https://github.com/legionth/http.git","svn_url":"https://github.com/legionth/http","homepage":"","size":313,"stargazers_count":0,"watchers_count":0,"language":"PHP","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":"reactphp:master","ref":"master","sha":"33061a2c954befaf74ae2db6e6489eff23017e23","user":{"login":"reactphp","id":1696866,"avatar_url":"https://avatars1.githubusercontent.com/u/1696866?v=3","gravatar_id":"","url":"https://api.github.com/users/reactphp","html_url":"https://github.com/reactphp","followers_url":"https://api.github.com/users/reactphp/followers","following_url":"https://api.github.com/users/reactphp/following{/other_user}","gists_url":"https://api.github.com/users/reactphp/gists{/gist_id}","starred_url":"https://api.github.com/users/reactphp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reactphp/subscriptions","organizations_url":"https://api.github.com/users/reactphp/orgs","repos_url":"https://api.github.com/users/reactphp/repos","events_url":"https://api.github.com/users/reactphp/events{/privacy}","received_events_url":"https://api.github.com/users/reactphp/received_events","type":"Organization","site_admin":false},"repo":{"id":4287609,"name":"http","full_name":"reactphp/http","owner":{"login":"reactphp","id":1696866,"avatar_url":"https://avatars1.githubusercontent.com/u/1696866?v=3","gravatar_id":"","url":"https://api.github.com/users/reactphp","html_url":"https://github.com/reactphp","followers_url":"https://api.github.com/users/reactphp/followers","following_url":"https://api.github.com/users/reactphp/following{/other_user}","gists_url":"https://api.github.com/users/reactphp/gists{/gist_id}","starred_url":"https://api.github.com/users/reactphp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/reactphp/subscriptions","organizations_url":"https://api.github.com/users/reactphp/orgs","repos_url":"https://api.github.com/users/reactphp/repos","events_url":"https://api.github.com/users/reactphp/events{/privacy}","received_events_url":"https://api.github.com/users/reactphp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/reactphp/http","description":"Event-driven, streaming plaintext HTTP and secure HTTPS server for ReactPHP.","fork":false,"url":"https://api.github.com/repos/reactphp/http","forks_url":"https://api.github.com/repos/reactphp/http/forks","keys_url":"https://api.github.com/repos/reactphp/http/keys{/key_id}","collaborators_url":"https://api.github.com/repos/reactphp/http/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/reactphp/http/teams","hooks_url":"https://api.github.com/repos/reactphp/http/hooks","issue_events_url":"https://api.github.com/repos/reactphp/http/issues/events{/number}","events_url":"https://api.github.com/repos/reactphp/http/events","assignees_url":"https://api.github.com/repos/reactphp/http/assignees{/user}","branches_url":"https://api.github.com/repos/reactphp/http/branches{/branch}","tags_url":"https://api.github.com/repos/reactphp/http/tags","blobs_url":"https://api.github.com/repos/reactphp/http/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/reactphp/http/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/reactphp/http/git/refs{/sha}","trees_url":"https://api.github.com/repos/reactphp/http/git/trees{/sha}","statuses_url":"https://api.github.com/repos/reactphp/http/statuses/{sha}","languages_url":"https://api.github.com/repos/reactphp/http/languages","stargazers_url":"https://api.github.com/repos/reactphp/http/stargazers","contributors_url":"https://api.github.com/repos/reactphp/http/contributors","subscribers_url":"https://api.github.com/repos/reactphp/http/subscribers","subscription_url":"https://api.github.com/repos/reactphp/http/subscription","commits_url":"https://api.github.com/repos/reactphp/http/commits{/sha}","git_commits_url":"https://api.github.com/repos/reactphp/http/git/commits{/sha}","comments_url":"https://api.github.com/repos/reactphp/http/comments{/number}","issue_comment_url":"https://api.github.com/repos/reactphp/http/issues/comments{/number}","contents_url":"https://api.github.com/repos/reactphp/http/contents/{+path}","compare_url":"https://api.github.com/repos/reactphp/http/compare/{base}...{head}","merges_url":"https://api.github.com/repos/reactphp/http/merges","archive_url":"https://api.github.com/repos/reactphp/http/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/reactphp/http/downloads","issues_url":"https://api.github.com/repos/reactphp/http/issues{/number}","pulls_url":"https://api.github.com/repos/reactphp/http/pulls{/number}","milestones_url":"https://api.github.com/repos/reactphp/http/milestones{/number}","notifications_url":"https://api.github.com/repos/reactphp/http/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/reactphp/http/labels{/name}","releases_url":"https://api.github.com/repos/reactphp/http/releases{/id}","deployments_url":"https://api.github.com/repos/reactphp/http/deployments","created_at":"2012-05-10T17:31:28Z","updated_at":"2017-03-23T20:29:43Z","pushed_at":"2017-03-26T04:27:46Z","git_url":"git://github.com/reactphp/http.git","ssh_url":"git@github.com:reactphp/http.git","clone_url":"https://github.com/reactphp/http.git","svn_url":"https://github.com/reactphp/http","homepage":"","size":294,"stargazers_count":136,"watchers_count":136,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":54,"mirror_url":null,"open_issues_count":19,"forks":54,"open_issues":19,"watchers":136,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/reactphp/http/pulls/152"},"html":{"href":"https://github.com/reactphp/http/pull/152"},"issue":{"href":"https://api.github.com/repos/reactphp/http/issues/152"},"comments":{"href":"https://api.github.com/repos/reactphp/http/issues/152/comments"},"review_comments":{"href":"https://api.github.com/repos/reactphp/http/pulls/152/comments"},"review_comment":{"href":"https://api.github.com/repos/reactphp/http/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/reactphp/http/pulls/152/commits"},"statuses":{"href":"https://api.github.com/repos/reactphp/http/statuses/c0aef5da52404f458222acf3554c5f591c63395d"}}}}
{"actor":{"display_login":"WyriHaximus"}}