{"action":"created","comment":{"url":"https://api.github.com/repos/bean00/http-server/pulls/comments/165722965","pull_request_review_id":93712751,"id":165722965,"diff_hunk":"@@ -1,41 +1,78 @@\n package com.bean00;\n \n-import java.io.BufferedReader;\n import java.io.IOException;\n-import java.io.PrintWriter;\n+import java.io.Writer;\n+import java.nio.file.Files;\n+import java.nio.file.Path;\n+import java.nio.file.Paths;\n \n public class MessageController {\n-    private RequestParser parser;\n-    private PrintWriter out;\n-    private RequestInterpreter interpreter = new RequestInterpreter();\n \n-    public MessageController(BufferedReader in, PrintWriter out) {\n-        parser = new RequestParser(in);\n+    public Response processRequest(Request request) throws IOException {\n+        // get the full path\n+        String requestURL = request.getRequestURL();\n+        Path path = getFullPath(requestURL);\n+\n+        // set helpful booleans\n+        boolean rootDirectoryWasRequested = requestURL.equals(\"/\");\n+        boolean fileCanBeFound = checkIfFileCanBeFound(path);\n+\n+        // get the contents of the file (as a byte array)\n+        byte[] body = getBodyFromFile(path, fileCanBeFound);\n \n-        this.out = out;\n+        // create the appropriate response\n+        Response response = buildResponse(rootDirectoryWasRequested, fileCanBeFound, body);\n+\n+        return response;\n     }\n \n-    public Request getRequest() throws IOException {\n-        Request request = parser.parseRequest();\n+    public void writeResponse(Response response, Writer out) throws IOException {\n+        String responseString = response.toString();\n \n-        return request;\n+        out.write(responseString);\n+        out.flush();\n     }\n \n-    public Response interpretRequest(Request request) {\n-        String requestURL = request.getRequestURL();\n+    private Path getFullPath(String requestURL) {\n+        String pathToPublic = \"/Users/jonchin/8th-Light/projects/java-server/cob_spec/public\";\n \n-        // *Note: shouldn't be choosing status code based on the requestURL\n-        int statusCode = interpreter.chooseStatusCode(requestURL);\n-        Response response = new Response(statusCode);\n+        Path path = Paths.get(pathToPublic, requestURL);\n \n-        return response;\n+        return path;\n     }\n \n-    public void writeResponse(Response response) {\n-        String responseString = response.toString();\n+    private boolean checkIfFileCanBeFound(Path path) {\n+        boolean fileExists = Files.exists(path);\n+        boolean pathPointsToDirectory = Files.isDirectory(path);\n \n-        out.print(responseString);\n-        out.flush();\n+        boolean fileCanBeFound = fileExists && !pathPointsToDirectory;\n+\n+        return fileCanBeFound;\n+    }\n+\n+    private byte[] getBodyFromFile(Path path, boolean fileCanBeFound) throws IOException {\n+        byte[] body = new byte[0];\n+\n+        if (fileCanBeFound) {\n+            body = Files.readAllBytes(path);\n+        }\n+\n+        return body;\n+    }\n+\n+    private Response buildResponse(boolean rootDirectoryWasRequested,","path":"src/main/java/com/bean00/MessageController.java","position":83,"original_position":84,"commit_id":"212ed615f86999583cb80208a8211b9452666d06","original_commit_id":"52c74e559f549928cf449721bf63ee35faafa127","user":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2018-02-02T18:32:20Z","updated_at":"2018-02-02T18:32:20Z","html_url":"https://github.com/bean00/http-server/pull/5#discussion_r165722965","pull_request_url":"https://api.github.com/repos/bean00/http-server/pulls/5","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/bean00/http-server/pulls/comments/165722965"},"html":{"href":"https://github.com/bean00/http-server/pull/5#discussion_r165722965"},"pull_request":{"href":"https://api.github.com/repos/bean00/http-server/pulls/5"}},"in_reply_to_id":165528426},"pull_request":{"url":"https://api.github.com/repos/bean00/http-server/pulls/5","id":166616872,"html_url":"https://github.com/bean00/http-server/pull/5","diff_url":"https://github.com/bean00/http-server/pull/5.diff","patch_url":"https://github.com/bean00/http-server/pull/5.patch","issue_url":"https://api.github.com/repos/bean00/http-server/issues/5","number":5,"state":"open","locked":false,"title":"Feat/file-contents","user":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"body":"### MessageController.java\r\n- I'm planning on extracting out the private methods used in `processRequest` into a separate class called `ResponseBuilder` or `ResponseFactory`, that does the work of creating a `Response` object\r\n  - *Note: This will be implemented when more functionality is added to `processRequest`\r\n- I'd also like to add a layer of abstraction between the low-level OS and my application, regarding dealing with Files and Paths (so I can swap out the low-level implementation, using a Windows OS or some other way of getting the contents of the body)\r\n  - *Note: I will fix this next time something is done w/ the file system (Media Types?)\r\n\r\n### Logging\r\n- I also plan on eventually using a Logging framework to improve how I write output to the console (instead of using `println` statements). I'm not sure how critical is it to implement this now, but if you'd like it to be included in this PR then I can do it.\r\n  - *Note: for now I'll remove the `println` statements, and next time I need to debug I'll implement `toString` for `Request` and print out at that point","created_at":"2018-02-01T18:32:21Z","updated_at":"2018-02-02T18:32:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d472b955d15a096e238ed05092b7cdf6043702ee","assignee":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"assignees":[{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false}],"requested_reviewers":[{"login":"jdesrosiers","id":716571,"avatar_url":"https://avatars1.githubusercontent.com/u/716571?v=4","gravatar_id":"","url":"https://api.github.com/users/jdesrosiers","html_url":"https://github.com/jdesrosiers","followers_url":"https://api.github.com/users/jdesrosiers/followers","following_url":"https://api.github.com/users/jdesrosiers/following{/other_user}","gists_url":"https://api.github.com/users/jdesrosiers/gists{/gist_id}","starred_url":"https://api.github.com/users/jdesrosiers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jdesrosiers/subscriptions","organizations_url":"https://api.github.com/users/jdesrosiers/orgs","repos_url":"https://api.github.com/users/jdesrosiers/repos","events_url":"https://api.github.com/users/jdesrosiers/events{/privacy}","received_events_url":"https://api.github.com/users/jdesrosiers/received_events","type":"User","site_admin":false}],"requested_teams":[],"milestone":null,"commits_url":"https://api.github.com/repos/bean00/http-server/pulls/5/commits","review_comments_url":"https://api.github.com/repos/bean00/http-server/pulls/5/comments","review_comment_url":"https://api.github.com/repos/bean00/http-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bean00/http-server/issues/5/comments","statuses_url":"https://api.github.com/repos/bean00/http-server/statuses/212ed615f86999583cb80208a8211b9452666d06","head":{"label":"bean00:feat/file-contents","ref":"feat/file-contents","sha":"212ed615f86999583cb80208a8211b9452666d06","user":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"repo":{"id":116852919,"name":"http-server","full_name":"bean00/http-server","owner":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bean00/http-server","description":"An HTTP server written in Java","fork":false,"url":"https://api.github.com/repos/bean00/http-server","forks_url":"https://api.github.com/repos/bean00/http-server/forks","keys_url":"https://api.github.com/repos/bean00/http-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bean00/http-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bean00/http-server/teams","hooks_url":"https://api.github.com/repos/bean00/http-server/hooks","issue_events_url":"https://api.github.com/repos/bean00/http-server/issues/events{/number}","events_url":"https://api.github.com/repos/bean00/http-server/events","assignees_url":"https://api.github.com/repos/bean00/http-server/assignees{/user}","branches_url":"https://api.github.com/repos/bean00/http-server/branches{/branch}","tags_url":"https://api.github.com/repos/bean00/http-server/tags","blobs_url":"https://api.github.com/repos/bean00/http-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bean00/http-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bean00/http-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/bean00/http-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bean00/http-server/statuses/{sha}","languages_url":"https://api.github.com/repos/bean00/http-server/languages","stargazers_url":"https://api.github.com/repos/bean00/http-server/stargazers","contributors_url":"https://api.github.com/repos/bean00/http-server/contributors","subscribers_url":"https://api.github.com/repos/bean00/http-server/subscribers","subscription_url":"https://api.github.com/repos/bean00/http-server/subscription","commits_url":"https://api.github.com/repos/bean00/http-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/bean00/http-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/bean00/http-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/bean00/http-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/bean00/http-server/contents/{+path}","compare_url":"https://api.github.com/repos/bean00/http-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bean00/http-server/merges","archive_url":"https://api.github.com/repos/bean00/http-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bean00/http-server/downloads","issues_url":"https://api.github.com/repos/bean00/http-server/issues{/number}","pulls_url":"https://api.github.com/repos/bean00/http-server/pulls{/number}","milestones_url":"https://api.github.com/repos/bean00/http-server/milestones{/number}","notifications_url":"https://api.github.com/repos/bean00/http-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bean00/http-server/labels{/name}","releases_url":"https://api.github.com/repos/bean00/http-server/releases{/id}","deployments_url":"https://api.github.com/repos/bean00/http-server/deployments","created_at":"2018-01-09T18:14:24Z","updated_at":"2018-01-09T18:15:57Z","pushed_at":"2018-02-02T18:29:59Z","git_url":"git://github.com/bean00/http-server.git","ssh_url":"git@github.com:bean00/http-server.git","clone_url":"https://github.com/bean00/http-server.git","svn_url":"https://github.com/bean00/http-server","homepage":null,"size":27,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"bean00:master","ref":"master","sha":"d492efe0f7b5d75e76d0eb4c0537a7d4c233b635","user":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"repo":{"id":116852919,"name":"http-server","full_name":"bean00/http-server","owner":{"login":"bean00","id":13635808,"avatar_url":"https://avatars2.githubusercontent.com/u/13635808?v=4","gravatar_id":"","url":"https://api.github.com/users/bean00","html_url":"https://github.com/bean00","followers_url":"https://api.github.com/users/bean00/followers","following_url":"https://api.github.com/users/bean00/following{/other_user}","gists_url":"https://api.github.com/users/bean00/gists{/gist_id}","starred_url":"https://api.github.com/users/bean00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bean00/subscriptions","organizations_url":"https://api.github.com/users/bean00/orgs","repos_url":"https://api.github.com/users/bean00/repos","events_url":"https://api.github.com/users/bean00/events{/privacy}","received_events_url":"https://api.github.com/users/bean00/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bean00/http-server","description":"An HTTP server written in Java","fork":false,"url":"https://api.github.com/repos/bean00/http-server","forks_url":"https://api.github.com/repos/bean00/http-server/forks","keys_url":"https://api.github.com/repos/bean00/http-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bean00/http-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bean00/http-server/teams","hooks_url":"https://api.github.com/repos/bean00/http-server/hooks","issue_events_url":"https://api.github.com/repos/bean00/http-server/issues/events{/number}","events_url":"https://api.github.com/repos/bean00/http-server/events","assignees_url":"https://api.github.com/repos/bean00/http-server/assignees{/user}","branches_url":"https://api.github.com/repos/bean00/http-server/branches{/branch}","tags_url":"https://api.github.com/repos/bean00/http-server/tags","blobs_url":"https://api.github.com/repos/bean00/http-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bean00/http-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bean00/http-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/bean00/http-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bean00/http-server/statuses/{sha}","languages_url":"https://api.github.com/repos/bean00/http-server/languages","stargazers_url":"https://api.github.com/repos/bean00/http-server/stargazers","contributors_url":"https://api.github.com/repos/bean00/http-server/contributors","subscribers_url":"https://api.github.com/repos/bean00/http-server/subscribers","subscription_url":"https://api.github.com/repos/bean00/http-server/subscription","commits_url":"https://api.github.com/repos/bean00/http-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/bean00/http-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/bean00/http-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/bean00/http-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/bean00/http-server/contents/{+path}","compare_url":"https://api.github.com/repos/bean00/http-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bean00/http-server/merges","archive_url":"https://api.github.com/repos/bean00/http-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bean00/http-server/downloads","issues_url":"https://api.github.com/repos/bean00/http-server/issues{/number}","pulls_url":"https://api.github.com/repos/bean00/http-server/pulls{/number}","milestones_url":"https://api.github.com/repos/bean00/http-server/milestones{/number}","notifications_url":"https://api.github.com/repos/bean00/http-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bean00/http-server/labels{/name}","releases_url":"https://api.github.com/repos/bean00/http-server/releases{/id}","deployments_url":"https://api.github.com/repos/bean00/http-server/deployments","created_at":"2018-01-09T18:14:24Z","updated_at":"2018-01-09T18:15:57Z","pushed_at":"2018-02-02T18:29:59Z","git_url":"git://github.com/bean00/http-server.git","ssh_url":"git@github.com:bean00/http-server.git","clone_url":"https://github.com/bean00/http-server.git","svn_url":"https://github.com/bean00/http-server","homepage":null,"size":27,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bean00/http-server/pulls/5"},"html":{"href":"https://github.com/bean00/http-server/pull/5"},"issue":{"href":"https://api.github.com/repos/bean00/http-server/issues/5"},"comments":{"href":"https://api.github.com/repos/bean00/http-server/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/bean00/http-server/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/bean00/http-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bean00/http-server/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/bean00/http-server/statuses/212ed615f86999583cb80208a8211b9452666d06"}},"author_association":"OWNER"}}
{"actor":{"display_login":"bean00"}}