{"action":"created","comment":{"url":"https://api.github.com/repos/rust-net-web/tide/pulls/comments/232931627","pull_request_review_id":174233887,"id":232931627,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMjkzMTYyNw==","diff_hunk":"@@ -0,0 +1,53 @@\n+use futures::future::FutureObj;\n+\n+use http::{\n+    header::{HeaderValue, IntoHeaderName},\n+    HeaderMap, HttpTryFrom,\n+};\n+\n+use crate::{head::Head, Middleware, Response};\n+\n+#[derive(Clone, Default)]\n+pub struct DefaultHeaders {\n+    headers: HeaderMap,\n+}\n+\n+impl DefaultHeaders {\n+    pub fn new() -> DefaultHeaders {\n+        DefaultHeaders::default()\n+    }\n+\n+    #[inline]\n+    #[cfg_attr(feature = \"cargo-clippy\", allow(clippy::match_wild_err_arm))]\n+    pub fn header<K, V>(mut self, key: K, value: V) -> Self\n+    where\n+        K: IntoHeaderName,\n+        HeaderValue: HttpTryFrom<V>,\n+    {\n+        match HeaderValue::try_from(value) {\n+            Ok(value) => {\n+                self.headers.append(key, value);\n+            }\n+            Err(_) => {\n+                panic!(\"Cannot create default header. Please check your default header values.\")","path":"src/middleware/default_headers.rs","position":32,"original_position":32,"commit_id":"6a77bd82022603e0beb89120d859a7b13ce1529d","original_commit_id":"6a77bd82022603e0beb89120d859a7b13ce1529d","user":{"login":"tirr-c","id":2322996,"node_id":"MDQ6VXNlcjIzMjI5OTY=","avatar_url":"https://avatars1.githubusercontent.com/u/2322996?v=4","gravatar_id":"","url":"https://api.github.com/users/tirr-c","html_url":"https://github.com/tirr-c","followers_url":"https://api.github.com/users/tirr-c/followers","following_url":"https://api.github.com/users/tirr-c/following{/other_user}","gists_url":"https://api.github.com/users/tirr-c/gists{/gist_id}","starred_url":"https://api.github.com/users/tirr-c/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tirr-c/subscriptions","organizations_url":"https://api.github.com/users/tirr-c/orgs","repos_url":"https://api.github.com/users/tirr-c/repos","events_url":"https://api.github.com/users/tirr-c/events{/privacy}","received_events_url":"https://api.github.com/users/tirr-c/received_events","type":"User","site_admin":false},"body":"How about using `.expect()` on `try_from`? We don't need clippy attr then :)","created_at":"2018-11-13T08:13:39Z","updated_at":"2018-11-13T08:18:10Z","html_url":"https://github.com/rust-net-web/tide/pull/42#discussion_r232931627","pull_request_url":"https://api.github.com/repos/rust-net-web/tide/pulls/42","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/comments/232931627"},"html":{"href":"https://github.com/rust-net-web/tide/pull/42#discussion_r232931627"},"pull_request":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/42"}}},"pull_request":{"url":"https://api.github.com/repos/rust-net-web/tide/pulls/42","id":229994789,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI5OTk0Nzg5","html_url":"https://github.com/rust-net-web/tide/pull/42","diff_url":"https://github.com/rust-net-web/tide/pull/42.diff","patch_url":"https://github.com/rust-net-web/tide/pull/42.patch","issue_url":"https://api.github.com/repos/rust-net-web/tide/issues/42","number":42,"state":"open","locked":false,"title":"Feature: Default Headers Middleware","user":{"login":"tzilist","id":14153237,"node_id":"MDQ6VXNlcjE0MTUzMjM3","avatar_url":"https://avatars0.githubusercontent.com/u/14153237?v=4","gravatar_id":"","url":"https://api.github.com/users/tzilist","html_url":"https://github.com/tzilist","followers_url":"https://api.github.com/users/tzilist/followers","following_url":"https://api.github.com/users/tzilist/following{/other_user}","gists_url":"https://api.github.com/users/tzilist/gists{/gist_id}","starred_url":"https://api.github.com/users/tzilist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzilist/subscriptions","organizations_url":"https://api.github.com/users/tzilist/orgs","repos_url":"https://api.github.com/users/tzilist/repos","events_url":"https://api.github.com/users/tzilist/events{/privacy}","received_events_url":"https://api.github.com/users/tzilist/received_events","type":"User","site_admin":false},"body":"PR is to add the ability to create default headers for every request. This is more or less taken from actix-web!\r\n\r\nI am also trying to add the method `headers` which lets you specify a Vec of headers, e.g.\r\n\r\n```rust\r\nlet mut app = tide::App::new(());\r\n\r\napp.middleware(\r\n  DefaultHeaders::new()\r\n    .headers(vec!(\r\n      [\"X-Version\", \"1.0.0\"],\r\n      [\"X-Server\", \"Tide\"]\r\n     ))\r\n);\r\n```\r\n\r\nAs opposed to:\r\n\r\n```rust\r\nlet mut app = tide::App::new(());\r\n\r\napp.middleware(\r\n  DefaultHeaders::new()\r\n    .header(\"X-Version\", \"1.0.0\")\r\n    .header(\"X-Server\", \"Tide\")\r\n);\r\n```\r\nNot sure which one is more clear? Currently the latter is what is implemented. If it's decided that the other way is better, I can work on implementing it.","created_at":"2018-11-12T01:22:04Z","updated_at":"2018-11-13T08:18:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"32c877401afecbe0eb65581209eb64aac7e92467","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rust-net-web/tide/pulls/42/commits","review_comments_url":"https://api.github.com/repos/rust-net-web/tide/pulls/42/comments","review_comment_url":"https://api.github.com/repos/rust-net-web/tide/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-net-web/tide/issues/42/comments","statuses_url":"https://api.github.com/repos/rust-net-web/tide/statuses/6a77bd82022603e0beb89120d859a7b13ce1529d","head":{"label":"tzilist:feat-default-headers","ref":"feat-default-headers","sha":"6a77bd82022603e0beb89120d859a7b13ce1529d","user":{"login":"tzilist","id":14153237,"node_id":"MDQ6VXNlcjE0MTUzMjM3","avatar_url":"https://avatars0.githubusercontent.com/u/14153237?v=4","gravatar_id":"","url":"https://api.github.com/users/tzilist","html_url":"https://github.com/tzilist","followers_url":"https://api.github.com/users/tzilist/followers","following_url":"https://api.github.com/users/tzilist/following{/other_user}","gists_url":"https://api.github.com/users/tzilist/gists{/gist_id}","starred_url":"https://api.github.com/users/tzilist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzilist/subscriptions","organizations_url":"https://api.github.com/users/tzilist/orgs","repos_url":"https://api.github.com/users/tzilist/repos","events_url":"https://api.github.com/users/tzilist/events{/privacy}","received_events_url":"https://api.github.com/users/tzilist/received_events","type":"User","site_admin":false},"repo":{"id":156828374,"node_id":"MDEwOlJlcG9zaXRvcnkxNTY4MjgzNzQ=","name":"tide","full_name":"tzilist/tide","private":false,"owner":{"login":"tzilist","id":14153237,"node_id":"MDQ6VXNlcjE0MTUzMjM3","avatar_url":"https://avatars0.githubusercontent.com/u/14153237?v=4","gravatar_id":"","url":"https://api.github.com/users/tzilist","html_url":"https://github.com/tzilist","followers_url":"https://api.github.com/users/tzilist/followers","following_url":"https://api.github.com/users/tzilist/following{/other_user}","gists_url":"https://api.github.com/users/tzilist/gists{/gist_id}","starred_url":"https://api.github.com/users/tzilist/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tzilist/subscriptions","organizations_url":"https://api.github.com/users/tzilist/orgs","repos_url":"https://api.github.com/users/tzilist/repos","events_url":"https://api.github.com/users/tzilist/events{/privacy}","received_events_url":"https://api.github.com/users/tzilist/received_events","type":"User","site_admin":false},"html_url":"https://github.com/tzilist/tide","description":"(wip) Modular web framework","fork":true,"url":"https://api.github.com/repos/tzilist/tide","forks_url":"https://api.github.com/repos/tzilist/tide/forks","keys_url":"https://api.github.com/repos/tzilist/tide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tzilist/tide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tzilist/tide/teams","hooks_url":"https://api.github.com/repos/tzilist/tide/hooks","issue_events_url":"https://api.github.com/repos/tzilist/tide/issues/events{/number}","events_url":"https://api.github.com/repos/tzilist/tide/events","assignees_url":"https://api.github.com/repos/tzilist/tide/assignees{/user}","branches_url":"https://api.github.com/repos/tzilist/tide/branches{/branch}","tags_url":"https://api.github.com/repos/tzilist/tide/tags","blobs_url":"https://api.github.com/repos/tzilist/tide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tzilist/tide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tzilist/tide/git/refs{/sha}","trees_url":"https://api.github.com/repos/tzilist/tide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tzilist/tide/statuses/{sha}","languages_url":"https://api.github.com/repos/tzilist/tide/languages","stargazers_url":"https://api.github.com/repos/tzilist/tide/stargazers","contributors_url":"https://api.github.com/repos/tzilist/tide/contributors","subscribers_url":"https://api.github.com/repos/tzilist/tide/subscribers","subscription_url":"https://api.github.com/repos/tzilist/tide/subscription","commits_url":"https://api.github.com/repos/tzilist/tide/commits{/sha}","git_commits_url":"https://api.github.com/repos/tzilist/tide/git/commits{/sha}","comments_url":"https://api.github.com/repos/tzilist/tide/comments{/number}","issue_comment_url":"https://api.github.com/repos/tzilist/tide/issues/comments{/number}","contents_url":"https://api.github.com/repos/tzilist/tide/contents/{+path}","compare_url":"https://api.github.com/repos/tzilist/tide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tzilist/tide/merges","archive_url":"https://api.github.com/repos/tzilist/tide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tzilist/tide/downloads","issues_url":"https://api.github.com/repos/tzilist/tide/issues{/number}","pulls_url":"https://api.github.com/repos/tzilist/tide/pulls{/number}","milestones_url":"https://api.github.com/repos/tzilist/tide/milestones{/number}","notifications_url":"https://api.github.com/repos/tzilist/tide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tzilist/tide/labels{/name}","releases_url":"https://api.github.com/repos/tzilist/tide/releases{/id}","deployments_url":"https://api.github.com/repos/tzilist/tide/deployments","created_at":"2018-11-09T07:51:54Z","updated_at":"2018-11-11T23:01:20Z","pushed_at":"2018-11-13T07:34:44Z","git_url":"git://github.com/tzilist/tide.git","ssh_url":"git@github.com:tzilist/tide.git","clone_url":"https://github.com/tzilist/tide.git","svn_url":"https://github.com/tzilist/tide","homepage":null,"size":61,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-net-web:master","ref":"master","sha":"2995b4405dc9b54ea28063fa04425cdc27c4b4ba","user":{"login":"rust-net-web","id":42340655,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyMzQwNjU1","avatar_url":"https://avatars0.githubusercontent.com/u/42340655?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-net-web","html_url":"https://github.com/rust-net-web","followers_url":"https://api.github.com/users/rust-net-web/followers","following_url":"https://api.github.com/users/rust-net-web/following{/other_user}","gists_url":"https://api.github.com/users/rust-net-web/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-net-web/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-net-web/subscriptions","organizations_url":"https://api.github.com/users/rust-net-web/orgs","repos_url":"https://api.github.com/users/rust-net-web/repos","events_url":"https://api.github.com/users/rust-net-web/events{/privacy}","received_events_url":"https://api.github.com/users/rust-net-web/received_events","type":"Organization","site_admin":false},"repo":{"id":144025834,"node_id":"MDEwOlJlcG9zaXRvcnkxNDQwMjU4MzQ=","name":"tide","full_name":"rust-net-web/tide","private":false,"owner":{"login":"rust-net-web","id":42340655,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQyMzQwNjU1","avatar_url":"https://avatars0.githubusercontent.com/u/42340655?v=4","gravatar_id":"","url":"https://api.github.com/users/rust-net-web","html_url":"https://github.com/rust-net-web","followers_url":"https://api.github.com/users/rust-net-web/followers","following_url":"https://api.github.com/users/rust-net-web/following{/other_user}","gists_url":"https://api.github.com/users/rust-net-web/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-net-web/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-net-web/subscriptions","organizations_url":"https://api.github.com/users/rust-net-web/orgs","repos_url":"https://api.github.com/users/rust-net-web/repos","events_url":"https://api.github.com/users/rust-net-web/events{/privacy}","received_events_url":"https://api.github.com/users/rust-net-web/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rust-net-web/tide","description":"(wip) Modular web framework","fork":false,"url":"https://api.github.com/repos/rust-net-web/tide","forks_url":"https://api.github.com/repos/rust-net-web/tide/forks","keys_url":"https://api.github.com/repos/rust-net-web/tide/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-net-web/tide/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-net-web/tide/teams","hooks_url":"https://api.github.com/repos/rust-net-web/tide/hooks","issue_events_url":"https://api.github.com/repos/rust-net-web/tide/issues/events{/number}","events_url":"https://api.github.com/repos/rust-net-web/tide/events","assignees_url":"https://api.github.com/repos/rust-net-web/tide/assignees{/user}","branches_url":"https://api.github.com/repos/rust-net-web/tide/branches{/branch}","tags_url":"https://api.github.com/repos/rust-net-web/tide/tags","blobs_url":"https://api.github.com/repos/rust-net-web/tide/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-net-web/tide/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-net-web/tide/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-net-web/tide/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-net-web/tide/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-net-web/tide/languages","stargazers_url":"https://api.github.com/repos/rust-net-web/tide/stargazers","contributors_url":"https://api.github.com/repos/rust-net-web/tide/contributors","subscribers_url":"https://api.github.com/repos/rust-net-web/tide/subscribers","subscription_url":"https://api.github.com/repos/rust-net-web/tide/subscription","commits_url":"https://api.github.com/repos/rust-net-web/tide/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-net-web/tide/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-net-web/tide/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-net-web/tide/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-net-web/tide/contents/{+path}","compare_url":"https://api.github.com/repos/rust-net-web/tide/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-net-web/tide/merges","archive_url":"https://api.github.com/repos/rust-net-web/tide/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-net-web/tide/downloads","issues_url":"https://api.github.com/repos/rust-net-web/tide/issues{/number}","pulls_url":"https://api.github.com/repos/rust-net-web/tide/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-net-web/tide/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-net-web/tide/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-net-web/tide/labels{/name}","releases_url":"https://api.github.com/repos/rust-net-web/tide/releases{/id}","deployments_url":"https://api.github.com/repos/rust-net-web/tide/deployments","created_at":"2018-08-08T14:32:04Z","updated_at":"2018-11-13T04:54:04Z","pushed_at":"2018-11-13T07:34:45Z","git_url":"git://github.com/rust-net-web/tide.git","ssh_url":"git@github.com:rust-net-web/tide.git","clone_url":"https://github.com/rust-net-web/tide.git","svn_url":"https://github.com/rust-net-web/tide","homepage":null,"size":53,"stargazers_count":115,"watchers_count":115,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":16,"mirror_url":null,"archived":false,"open_issues_count":30,"license":{"key":"other","name":"Other","spdx_id":"NOASSERTION","url":null,"node_id":"MDc6TGljZW5zZTA="},"forks":16,"open_issues":30,"watchers":115,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/42"},"html":{"href":"https://github.com/rust-net-web/tide/pull/42"},"issue":{"href":"https://api.github.com/repos/rust-net-web/tide/issues/42"},"comments":{"href":"https://api.github.com/repos/rust-net-web/tide/issues/42/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/42/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-net-web/tide/pulls/42/commits"},"statuses":{"href":"https://api.github.com/repos/rust-net-web/tide/statuses/6a77bd82022603e0beb89120d859a7b13ce1529d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tirr-c"}}