{"action":"created","comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments/54433756","id":54433756,"diff_hunk":"@@ -485,6 +511,10 @@ class HTTP::Client\n     end\n   end\n \n+  private def self.allowed_scheme?(uri : URI)\n+    uri.scheme =~ /https?/","path":"src/http/client/client.cr","position":38,"original_position":38,"commit_id":"7dcb25484adf4c78944bd966ee60cb46b4238a32","original_commit_id":"7dcb25484adf4c78944bd966ee60cb46b4238a32","user":{"login":"asterite","id":209371,"avatar_url":"https://avatars.githubusercontent.com/u/209371?v=3","gravatar_id":"","url":"https://api.github.com/users/asterite","html_url":"https://github.com/asterite","followers_url":"https://api.github.com/users/asterite/followers","following_url":"https://api.github.com/users/asterite/following{/other_user}","gists_url":"https://api.github.com/users/asterite/gists{/gist_id}","starred_url":"https://api.github.com/users/asterite/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asterite/subscriptions","organizations_url":"https://api.github.com/users/asterite/orgs","repos_url":"https://api.github.com/users/asterite/repos","events_url":"https://api.github.com/users/asterite/events{/privacy}","received_events_url":"https://api.github.com/users/asterite/received_events","type":"User","site_admin":false},"body":"Probably `uri.scheme == \"http\" || uri.scheme == \"https\"` is way better and faster (no need to allocate a regex, to create a match data, etc.). Inside the standard library we try to be as efficient as possible. Also faster is just embedding the condition inside the method. Also, the same logic is done in `self.exec`, so we can maybe move it to a `private def self.ssl?(uri) : Bool` that checks that the scheme is non-nil, and it's only \"http\" or \"https\", and returns `true` if it's \"https\", `false` otherwise. What do you think?","created_at":"2016-02-29T16:19:28Z","updated_at":"2016-02-29T16:19:28Z","html_url":"https://github.com/crystal-lang/crystal/pull/2213#discussion_r54433756","pull_request_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213","_links":{"self":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments/54433756"},"html":{"href":"https://github.com/crystal-lang/crystal/pull/2213#discussion_r54433756"},"pull_request":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213"}}},"pull_request":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213","id":60412573,"html_url":"https://github.com/crystal-lang/crystal/pull/2213","diff_url":"https://github.com/crystal-lang/crystal/pull/2213.diff","patch_url":"https://github.com/crystal-lang/crystal/pull/2213.patch","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2213","number":2213,"state":"open","locked":false,"title":"allow instantiation of URI client via URI","user":{"login":"plukevdh","id":16054,"avatar_url":"https://avatars.githubusercontent.com/u/16054?v=3","gravatar_id":"","url":"https://api.github.com/users/plukevdh","html_url":"https://github.com/plukevdh","followers_url":"https://api.github.com/users/plukevdh/followers","following_url":"https://api.github.com/users/plukevdh/following{/other_user}","gists_url":"https://api.github.com/users/plukevdh/gists{/gist_id}","starred_url":"https://api.github.com/users/plukevdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plukevdh/subscriptions","organizations_url":"https://api.github.com/users/plukevdh/orgs","repos_url":"https://api.github.com/users/plukevdh/repos","events_url":"https://api.github.com/users/plukevdh/events{/privacy}","received_events_url":"https://api.github.com/users/plukevdh/received_events","type":"User","site_admin":false},"body":"Provides docs and tests to demonstrate.\r\n\r\n- [x] Raise an exception if the schema is not \"http\" or \"https\"\r\n- [x] Explicitly document that other URI components, like path and query, are ignored using that constructor.\r\n- [x] Squash into a single commit","created_at":"2016-02-23T21:26:44Z","updated_at":"2016-02-29T16:19:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9167940a1d6b322b85b95676058d5bc317927d39","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213/commits","review_comments_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213/comments","review_comment_url":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/2213/comments","statuses_url":"https://api.github.com/repos/crystal-lang/crystal/statuses/7dcb25484adf4c78944bd966ee60cb46b4238a32","head":{"label":"plukevdh:http-client-from-uri","ref":"http-client-from-uri","sha":"7dcb25484adf4c78944bd966ee60cb46b4238a32","user":{"login":"plukevdh","id":16054,"avatar_url":"https://avatars.githubusercontent.com/u/16054?v=3","gravatar_id":"","url":"https://api.github.com/users/plukevdh","html_url":"https://github.com/plukevdh","followers_url":"https://api.github.com/users/plukevdh/followers","following_url":"https://api.github.com/users/plukevdh/following{/other_user}","gists_url":"https://api.github.com/users/plukevdh/gists{/gist_id}","starred_url":"https://api.github.com/users/plukevdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plukevdh/subscriptions","organizations_url":"https://api.github.com/users/plukevdh/orgs","repos_url":"https://api.github.com/users/plukevdh/repos","events_url":"https://api.github.com/users/plukevdh/events{/privacy}","received_events_url":"https://api.github.com/users/plukevdh/received_events","type":"User","site_admin":false},"repo":{"id":51598769,"name":"crystal","full_name":"plukevdh/crystal","owner":{"login":"plukevdh","id":16054,"avatar_url":"https://avatars.githubusercontent.com/u/16054?v=3","gravatar_id":"","url":"https://api.github.com/users/plukevdh","html_url":"https://github.com/plukevdh","followers_url":"https://api.github.com/users/plukevdh/followers","following_url":"https://api.github.com/users/plukevdh/following{/other_user}","gists_url":"https://api.github.com/users/plukevdh/gists{/gist_id}","starred_url":"https://api.github.com/users/plukevdh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/plukevdh/subscriptions","organizations_url":"https://api.github.com/users/plukevdh/orgs","repos_url":"https://api.github.com/users/plukevdh/repos","events_url":"https://api.github.com/users/plukevdh/events{/privacy}","received_events_url":"https://api.github.com/users/plukevdh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/plukevdh/crystal","description":"The Crystal Programming Language","fork":true,"url":"https://api.github.com/repos/plukevdh/crystal","forks_url":"https://api.github.com/repos/plukevdh/crystal/forks","keys_url":"https://api.github.com/repos/plukevdh/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/plukevdh/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/plukevdh/crystal/teams","hooks_url":"https://api.github.com/repos/plukevdh/crystal/hooks","issue_events_url":"https://api.github.com/repos/plukevdh/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/plukevdh/crystal/events","assignees_url":"https://api.github.com/repos/plukevdh/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/plukevdh/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/plukevdh/crystal/tags","blobs_url":"https://api.github.com/repos/plukevdh/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/plukevdh/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/plukevdh/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/plukevdh/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/plukevdh/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/plukevdh/crystal/languages","stargazers_url":"https://api.github.com/repos/plukevdh/crystal/stargazers","contributors_url":"https://api.github.com/repos/plukevdh/crystal/contributors","subscribers_url":"https://api.github.com/repos/plukevdh/crystal/subscribers","subscription_url":"https://api.github.com/repos/plukevdh/crystal/subscription","commits_url":"https://api.github.com/repos/plukevdh/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/plukevdh/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/plukevdh/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/plukevdh/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/plukevdh/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/plukevdh/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/plukevdh/crystal/merges","archive_url":"https://api.github.com/repos/plukevdh/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/plukevdh/crystal/downloads","issues_url":"https://api.github.com/repos/plukevdh/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/plukevdh/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/plukevdh/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/plukevdh/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/plukevdh/crystal/labels{/name}","releases_url":"https://api.github.com/repos/plukevdh/crystal/releases{/id}","deployments_url":"https://api.github.com/repos/plukevdh/crystal/deployments","created_at":"2016-02-12T15:57:37Z","updated_at":"2016-02-12T15:57:40Z","pushed_at":"2016-02-29T15:43:52Z","git_url":"git://github.com/plukevdh/crystal.git","ssh_url":"git@github.com:plukevdh/crystal.git","clone_url":"https://github.com/plukevdh/crystal.git","svn_url":"https://github.com/plukevdh/crystal","homepage":"http://crystal-lang.org","size":41205,"stargazers_count":0,"watchers_count":0,"language":"Crystal","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"crystal-lang:master","ref":"master","sha":"bf3e99b4fa4e64da4f117743d8fc54ec335ce88f","user":{"login":"crystal-lang","id":6539796,"avatar_url":"https://avatars.githubusercontent.com/u/6539796?v=3","gravatar_id":"","url":"https://api.github.com/users/crystal-lang","html_url":"https://github.com/crystal-lang","followers_url":"https://api.github.com/users/crystal-lang/followers","following_url":"https://api.github.com/users/crystal-lang/following{/other_user}","gists_url":"https://api.github.com/users/crystal-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/crystal-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crystal-lang/subscriptions","organizations_url":"https://api.github.com/users/crystal-lang/orgs","repos_url":"https://api.github.com/users/crystal-lang/repos","events_url":"https://api.github.com/users/crystal-lang/events{/privacy}","received_events_url":"https://api.github.com/users/crystal-lang/received_events","type":"Organization","site_admin":false},"repo":{"id":6887813,"name":"crystal","full_name":"crystal-lang/crystal","owner":{"login":"crystal-lang","id":6539796,"avatar_url":"https://avatars.githubusercontent.com/u/6539796?v=3","gravatar_id":"","url":"https://api.github.com/users/crystal-lang","html_url":"https://github.com/crystal-lang","followers_url":"https://api.github.com/users/crystal-lang/followers","following_url":"https://api.github.com/users/crystal-lang/following{/other_user}","gists_url":"https://api.github.com/users/crystal-lang/gists{/gist_id}","starred_url":"https://api.github.com/users/crystal-lang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crystal-lang/subscriptions","organizations_url":"https://api.github.com/users/crystal-lang/orgs","repos_url":"https://api.github.com/users/crystal-lang/repos","events_url":"https://api.github.com/users/crystal-lang/events{/privacy}","received_events_url":"https://api.github.com/users/crystal-lang/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crystal-lang/crystal","description":"The Crystal Programming Language","fork":false,"url":"https://api.github.com/repos/crystal-lang/crystal","forks_url":"https://api.github.com/repos/crystal-lang/crystal/forks","keys_url":"https://api.github.com/repos/crystal-lang/crystal/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crystal-lang/crystal/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crystal-lang/crystal/teams","hooks_url":"https://api.github.com/repos/crystal-lang/crystal/hooks","issue_events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/events{/number}","events_url":"https://api.github.com/repos/crystal-lang/crystal/events","assignees_url":"https://api.github.com/repos/crystal-lang/crystal/assignees{/user}","branches_url":"https://api.github.com/repos/crystal-lang/crystal/branches{/branch}","tags_url":"https://api.github.com/repos/crystal-lang/crystal/tags","blobs_url":"https://api.github.com/repos/crystal-lang/crystal/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crystal-lang/crystal/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crystal-lang/crystal/git/refs{/sha}","trees_url":"https://api.github.com/repos/crystal-lang/crystal/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crystal-lang/crystal/statuses/{sha}","languages_url":"https://api.github.com/repos/crystal-lang/crystal/languages","stargazers_url":"https://api.github.com/repos/crystal-lang/crystal/stargazers","contributors_url":"https://api.github.com/repos/crystal-lang/crystal/contributors","subscribers_url":"https://api.github.com/repos/crystal-lang/crystal/subscribers","subscription_url":"https://api.github.com/repos/crystal-lang/crystal/subscription","commits_url":"https://api.github.com/repos/crystal-lang/crystal/commits{/sha}","git_commits_url":"https://api.github.com/repos/crystal-lang/crystal/git/commits{/sha}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/comments{/number}","issue_comment_url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments{/number}","contents_url":"https://api.github.com/repos/crystal-lang/crystal/contents/{+path}","compare_url":"https://api.github.com/repos/crystal-lang/crystal/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crystal-lang/crystal/merges","archive_url":"https://api.github.com/repos/crystal-lang/crystal/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crystal-lang/crystal/downloads","issues_url":"https://api.github.com/repos/crystal-lang/crystal/issues{/number}","pulls_url":"https://api.github.com/repos/crystal-lang/crystal/pulls{/number}","milestones_url":"https://api.github.com/repos/crystal-lang/crystal/milestones{/number}","notifications_url":"https://api.github.com/repos/crystal-lang/crystal/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crystal-lang/crystal/labels{/name}","releases_url":"https://api.github.com/repos/crystal-lang/crystal/releases{/id}","deployments_url":"https://api.github.com/repos/crystal-lang/crystal/deployments","created_at":"2012-11-27T17:32:32Z","updated_at":"2016-02-28T18:38:01Z","pushed_at":"2016-02-29T15:43:54Z","git_url":"git://github.com/crystal-lang/crystal.git","ssh_url":"git@github.com:crystal-lang/crystal.git","clone_url":"https://github.com/crystal-lang/crystal.git","svn_url":"https://github.com/crystal-lang/crystal","homepage":"http://crystal-lang.org","size":42604,"stargazers_count":4405,"watchers_count":4405,"language":"Crystal","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":366,"mirror_url":null,"open_issues_count":333,"forks":366,"open_issues":333,"watchers":4405,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213"},"html":{"href":"https://github.com/crystal-lang/crystal/pull/2213"},"issue":{"href":"https://api.github.com/repos/crystal-lang/crystal/issues/2213"},"comments":{"href":"https://api.github.com/repos/crystal-lang/crystal/issues/2213/comments"},"review_comments":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213/comments"},"review_comment":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crystal-lang/crystal/pulls/2213/commits"},"statuses":{"href":"https://api.github.com/repos/crystal-lang/crystal/statuses/7dcb25484adf4c78944bd966ee60cb46b4238a32"}}}}