{"action":"created","comment":{"url":"https://api.github.com/repos/Bl41r/http_server/pulls/comments/75780416","id":75780416,"diff_hunk":"@@ -45,13 +50,49 @@ def parse_request(req):\n     if \"host\" not in req_tuple[1]:\n         raise HTTPException(\"417\", \"Expectation Failed\", \"<h1>Requires host header</h1>\")\n \n-    uri = req_tuple[0].split()[1]   # for clarity\n+    uri = (req_tuple[0].split()[1])   # for clarity\n     return uri\n \n \n+def sanitize_uri(parsed_uri):\n+    parsed_uri = re.sub('\\.\\.', '', parsed_uri)\n+    parsed_uri = re.sub('~', '', parsed_uri)\n+    return parsed_uri\n+\n+\n+def resolve_uri(parsed_uri):\n+    root = u\"./webroot\"\n+    parsed_uri = root + parsed_uri\n+    parsed_uri = sanitize_uri(parsed_uri)\n+    try:\n+        file_type = mimetypes.guess_type(parsed_uri)\n+        f = io.open(parsed_uri, encoding=file_type[1])\n+        body = f.read()\n+        f.close()\n+        file_size = os.path.getsize(parsed_uri)\n+        return (file_type[0], body, file_size)\n+    except IsADirectoryError:\n+        if os.path.exists(parsed_uri):\n+            filenames = os.listdir(parsed_uri)\n+            body = ''\n+            for filename in filenames:\n+                path = os.path.join(parsed_uri, filename)\n+                body += \"<h1>\" + path + \"</h1>\\n\"\n+            body += '</html>'\n+            return (\"text/directory\", body, 0)","path":"src/server.py","position":57,"original_position":57,"commit_id":"bf1e13a1caddc42457d88a5f0dd6ad4d81295a8b","original_commit_id":"bf1e13a1caddc42457d88a5f0dd6ad4d81295a8b","user":{"login":"cewing","id":417109,"avatar_url":"https://avatars.githubusercontent.com/u/417109?v=3","gravatar_id":"","url":"https://api.github.com/users/cewing","html_url":"https://github.com/cewing","followers_url":"https://api.github.com/users/cewing/followers","following_url":"https://api.github.com/users/cewing/following{/other_user}","gists_url":"https://api.github.com/users/cewing/gists{/gist_id}","starred_url":"https://api.github.com/users/cewing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cewing/subscriptions","organizations_url":"https://api.github.com/users/cewing/orgs","repos_url":"https://api.github.com/users/cewing/repos","events_url":"https://api.github.com/users/cewing/events{/privacy}","received_events_url":"https://api.github.com/users/cewing/received_events","type":"User","site_admin":false},"body":"is 0 correct as the size of the body here?  and since you are returning html, shouldn't the mimetype be `text/html`?","created_at":"2016-08-22T23:46:27Z","updated_at":"2016-08-22T23:46:27Z","html_url":"https://github.com/Bl41r/http_server/pull/7#discussion_r75780416","pull_request_url":"https://api.github.com/repos/Bl41r/http_server/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/comments/75780416"},"html":{"href":"https://github.com/Bl41r/http_server/pull/7#discussion_r75780416"},"pull_request":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/Bl41r/http_server/pulls/7","id":82131450,"html_url":"https://github.com/Bl41r/http_server/pull/7","diff_url":"https://github.com/Bl41r/http_server/pull/7.diff","patch_url":"https://github.com/Bl41r/http_server/pull/7.patch","issue_url":"https://api.github.com/repos/Bl41r/http_server/issues/7","number":7,"state":"closed","locked":false,"title":"Step3","user":{"login":"vbenavente","id":15848808,"avatar_url":"https://avatars.githubusercontent.com/u/15848808?v=3","gravatar_id":"","url":"https://api.github.com/users/vbenavente","html_url":"https://github.com/vbenavente","followers_url":"https://api.github.com/users/vbenavente/followers","following_url":"https://api.github.com/users/vbenavente/following{/other_user}","gists_url":"https://api.github.com/users/vbenavente/gists{/gist_id}","starred_url":"https://api.github.com/users/vbenavente/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vbenavente/subscriptions","organizations_url":"https://api.github.com/users/vbenavente/orgs","repos_url":"https://api.github.com/users/vbenavente/repos","events_url":"https://api.github.com/users/vbenavente/events{/privacy}","received_events_url":"https://api.github.com/users/vbenavente/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-22T03:56:45Z","updated_at":"2016-08-22T23:46:27Z","closed_at":"2016-08-22T04:03:29Z","merged_at":"2016-08-22T04:03:29Z","merge_commit_sha":"c8a06d492921e4a9cf0d67bf6d7dc250d824dc39","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Bl41r/http_server/pulls/7/commits","review_comments_url":"https://api.github.com/repos/Bl41r/http_server/pulls/7/comments","review_comment_url":"https://api.github.com/repos/Bl41r/http_server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Bl41r/http_server/issues/7/comments","statuses_url":"https://api.github.com/repos/Bl41r/http_server/statuses/bf1e13a1caddc42457d88a5f0dd6ad4d81295a8b","head":{"label":"Bl41r:step3","ref":"step3","sha":"bf1e13a1caddc42457d88a5f0dd6ad4d81295a8b","user":{"login":"Bl41r","id":18507197,"avatar_url":"https://avatars.githubusercontent.com/u/18507197?v=3","gravatar_id":"","url":"https://api.github.com/users/Bl41r","html_url":"https://github.com/Bl41r","followers_url":"https://api.github.com/users/Bl41r/followers","following_url":"https://api.github.com/users/Bl41r/following{/other_user}","gists_url":"https://api.github.com/users/Bl41r/gists{/gist_id}","starred_url":"https://api.github.com/users/Bl41r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bl41r/subscriptions","organizations_url":"https://api.github.com/users/Bl41r/orgs","repos_url":"https://api.github.com/users/Bl41r/repos","events_url":"https://api.github.com/users/Bl41r/events{/privacy}","received_events_url":"https://api.github.com/users/Bl41r/received_events","type":"User","site_admin":false},"repo":{"id":65770623,"name":"http_server","full_name":"Bl41r/http_server","owner":{"login":"Bl41r","id":18507197,"avatar_url":"https://avatars.githubusercontent.com/u/18507197?v=3","gravatar_id":"","url":"https://api.github.com/users/Bl41r","html_url":"https://github.com/Bl41r","followers_url":"https://api.github.com/users/Bl41r/followers","following_url":"https://api.github.com/users/Bl41r/following{/other_user}","gists_url":"https://api.github.com/users/Bl41r/gists{/gist_id}","starred_url":"https://api.github.com/users/Bl41r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bl41r/subscriptions","organizations_url":"https://api.github.com/users/Bl41r/orgs","repos_url":"https://api.github.com/users/Bl41r/repos","events_url":"https://api.github.com/users/Bl41r/events{/privacy}","received_events_url":"https://api.github.com/users/Bl41r/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bl41r/http_server","description":"An http server written in Python","fork":false,"url":"https://api.github.com/repos/Bl41r/http_server","forks_url":"https://api.github.com/repos/Bl41r/http_server/forks","keys_url":"https://api.github.com/repos/Bl41r/http_server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bl41r/http_server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bl41r/http_server/teams","hooks_url":"https://api.github.com/repos/Bl41r/http_server/hooks","issue_events_url":"https://api.github.com/repos/Bl41r/http_server/issues/events{/number}","events_url":"https://api.github.com/repos/Bl41r/http_server/events","assignees_url":"https://api.github.com/repos/Bl41r/http_server/assignees{/user}","branches_url":"https://api.github.com/repos/Bl41r/http_server/branches{/branch}","tags_url":"https://api.github.com/repos/Bl41r/http_server/tags","blobs_url":"https://api.github.com/repos/Bl41r/http_server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bl41r/http_server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bl41r/http_server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bl41r/http_server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bl41r/http_server/statuses/{sha}","languages_url":"https://api.github.com/repos/Bl41r/http_server/languages","stargazers_url":"https://api.github.com/repos/Bl41r/http_server/stargazers","contributors_url":"https://api.github.com/repos/Bl41r/http_server/contributors","subscribers_url":"https://api.github.com/repos/Bl41r/http_server/subscribers","subscription_url":"https://api.github.com/repos/Bl41r/http_server/subscription","commits_url":"https://api.github.com/repos/Bl41r/http_server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bl41r/http_server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bl41r/http_server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bl41r/http_server/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bl41r/http_server/contents/{+path}","compare_url":"https://api.github.com/repos/Bl41r/http_server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bl41r/http_server/merges","archive_url":"https://api.github.com/repos/Bl41r/http_server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bl41r/http_server/downloads","issues_url":"https://api.github.com/repos/Bl41r/http_server/issues{/number}","pulls_url":"https://api.github.com/repos/Bl41r/http_server/pulls{/number}","milestones_url":"https://api.github.com/repos/Bl41r/http_server/milestones{/number}","notifications_url":"https://api.github.com/repos/Bl41r/http_server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bl41r/http_server/labels{/name}","releases_url":"https://api.github.com/repos/Bl41r/http_server/releases{/id}","deployments_url":"https://api.github.com/repos/Bl41r/http_server/deployments","created_at":"2016-08-15T22:58:44Z","updated_at":"2016-08-20T02:41:41Z","pushed_at":"2016-08-22T04:38:54Z","git_url":"git://github.com/Bl41r/http_server.git","ssh_url":"git@github.com:Bl41r/http_server.git","clone_url":"https://github.com/Bl41r/http_server.git","svn_url":"https://github.com/Bl41r/http_server","homepage":null,"size":199,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"Bl41r:master","ref":"master","sha":"21b4091bfe2fe9ad87810364f05bdce9c6cbce52","user":{"login":"Bl41r","id":18507197,"avatar_url":"https://avatars.githubusercontent.com/u/18507197?v=3","gravatar_id":"","url":"https://api.github.com/users/Bl41r","html_url":"https://github.com/Bl41r","followers_url":"https://api.github.com/users/Bl41r/followers","following_url":"https://api.github.com/users/Bl41r/following{/other_user}","gists_url":"https://api.github.com/users/Bl41r/gists{/gist_id}","starred_url":"https://api.github.com/users/Bl41r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bl41r/subscriptions","organizations_url":"https://api.github.com/users/Bl41r/orgs","repos_url":"https://api.github.com/users/Bl41r/repos","events_url":"https://api.github.com/users/Bl41r/events{/privacy}","received_events_url":"https://api.github.com/users/Bl41r/received_events","type":"User","site_admin":false},"repo":{"id":65770623,"name":"http_server","full_name":"Bl41r/http_server","owner":{"login":"Bl41r","id":18507197,"avatar_url":"https://avatars.githubusercontent.com/u/18507197?v=3","gravatar_id":"","url":"https://api.github.com/users/Bl41r","html_url":"https://github.com/Bl41r","followers_url":"https://api.github.com/users/Bl41r/followers","following_url":"https://api.github.com/users/Bl41r/following{/other_user}","gists_url":"https://api.github.com/users/Bl41r/gists{/gist_id}","starred_url":"https://api.github.com/users/Bl41r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bl41r/subscriptions","organizations_url":"https://api.github.com/users/Bl41r/orgs","repos_url":"https://api.github.com/users/Bl41r/repos","events_url":"https://api.github.com/users/Bl41r/events{/privacy}","received_events_url":"https://api.github.com/users/Bl41r/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Bl41r/http_server","description":"An http server written in Python","fork":false,"url":"https://api.github.com/repos/Bl41r/http_server","forks_url":"https://api.github.com/repos/Bl41r/http_server/forks","keys_url":"https://api.github.com/repos/Bl41r/http_server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Bl41r/http_server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Bl41r/http_server/teams","hooks_url":"https://api.github.com/repos/Bl41r/http_server/hooks","issue_events_url":"https://api.github.com/repos/Bl41r/http_server/issues/events{/number}","events_url":"https://api.github.com/repos/Bl41r/http_server/events","assignees_url":"https://api.github.com/repos/Bl41r/http_server/assignees{/user}","branches_url":"https://api.github.com/repos/Bl41r/http_server/branches{/branch}","tags_url":"https://api.github.com/repos/Bl41r/http_server/tags","blobs_url":"https://api.github.com/repos/Bl41r/http_server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Bl41r/http_server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Bl41r/http_server/git/refs{/sha}","trees_url":"https://api.github.com/repos/Bl41r/http_server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Bl41r/http_server/statuses/{sha}","languages_url":"https://api.github.com/repos/Bl41r/http_server/languages","stargazers_url":"https://api.github.com/repos/Bl41r/http_server/stargazers","contributors_url":"https://api.github.com/repos/Bl41r/http_server/contributors","subscribers_url":"https://api.github.com/repos/Bl41r/http_server/subscribers","subscription_url":"https://api.github.com/repos/Bl41r/http_server/subscription","commits_url":"https://api.github.com/repos/Bl41r/http_server/commits{/sha}","git_commits_url":"https://api.github.com/repos/Bl41r/http_server/git/commits{/sha}","comments_url":"https://api.github.com/repos/Bl41r/http_server/comments{/number}","issue_comment_url":"https://api.github.com/repos/Bl41r/http_server/issues/comments{/number}","contents_url":"https://api.github.com/repos/Bl41r/http_server/contents/{+path}","compare_url":"https://api.github.com/repos/Bl41r/http_server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Bl41r/http_server/merges","archive_url":"https://api.github.com/repos/Bl41r/http_server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Bl41r/http_server/downloads","issues_url":"https://api.github.com/repos/Bl41r/http_server/issues{/number}","pulls_url":"https://api.github.com/repos/Bl41r/http_server/pulls{/number}","milestones_url":"https://api.github.com/repos/Bl41r/http_server/milestones{/number}","notifications_url":"https://api.github.com/repos/Bl41r/http_server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Bl41r/http_server/labels{/name}","releases_url":"https://api.github.com/repos/Bl41r/http_server/releases{/id}","deployments_url":"https://api.github.com/repos/Bl41r/http_server/deployments","created_at":"2016-08-15T22:58:44Z","updated_at":"2016-08-20T02:41:41Z","pushed_at":"2016-08-22T04:38:54Z","git_url":"git://github.com/Bl41r/http_server.git","ssh_url":"git@github.com:Bl41r/http_server.git","clone_url":"https://github.com/Bl41r/http_server.git","svn_url":"https://github.com/Bl41r/http_server","homepage":null,"size":199,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/7"},"html":{"href":"https://github.com/Bl41r/http_server/pull/7"},"issue":{"href":"https://api.github.com/repos/Bl41r/http_server/issues/7"},"comments":{"href":"https://api.github.com/repos/Bl41r/http_server/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Bl41r/http_server/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/Bl41r/http_server/statuses/bf1e13a1caddc42457d88a5f0dd6ad4d81295a8b"}}}}
{"actor":{"display_login":"cewing"}}