{"action":"created","comment":{"url":"https://api.github.com/repos/cybergeek94/multipart/pulls/comments/57087277","id":57087277,"diff_hunk":"@@ -1,43 +1,56 @@\n extern crate tiny_http;\n extern crate multipart;\n \n+use std::fs::File;\n+use std::io::{Error, Read};\n use multipart::server::{Multipart, Entries, SaveResult};\n use tiny_http::{Response, StatusCode, Request};\n fn main() {\n     // Starting a server on `localhost:80`\n-    let server = tiny_http::Server::http(\"localhost:80\").unwrap();\n+    let server = tiny_http::Server::http(\"localhost:80\").expect(\"Could not bind localhost:80\");\n     loop {\n         // This blocks until the next request is received\n         let mut request = server.recv().unwrap();\n-        process_multipart(&mut request).unwrap();\n-\n-        // Answering with an HTTP OK and a string\n-        let response_string = \"Multipart data is received!\".as_bytes();\n-        let response = Response::new(StatusCode(200),\n-                                     vec![],\n-                                     response_string,\n-                                     Some(response_string.len()),\n-                                     None);\n-        request.respond(response).unwrap();\n+\n+        // Processes a request and returns response or an occured error\n+        let result = process_request(&mut request);\n+        let resp = match result {\n+            Ok(resp) => resp,\n+            Err(e) => {\n+                println!(\"An error has occured during request proccessing: {:?}\", e);\n+                build_response(500, \"The received data was not correctly proccessed on the server\")\n+            }\n+        };\n+\n+        // Answers with a response to a client\n+        request.respond(resp).unwrap();\n     }\n }\n \n-fn process_multipart(request: &mut Request) -> Result<(), Error> {\n+/// Processes a request and returns response or an occured error.\n+fn process_request<'a, 'b>(request: &'a mut Request) -> Result<Response<&'b [u8]>, Error> {","path":"samples/tiny_http/src/main.rs","position":43,"original_position":43,"commit_id":"197109d6709d20dcff343d11549f6906ddafd5f5","original_commit_id":"197109d6709d20dcff343d11549f6906ddafd5f5","user":{"login":"White-Oak","id":2813216,"avatar_url":"https://avatars.githubusercontent.com/u/2813216?v=3","gravatar_id":"","url":"https://api.github.com/users/White-Oak","html_url":"https://github.com/White-Oak","followers_url":"https://api.github.com/users/White-Oak/followers","following_url":"https://api.github.com/users/White-Oak/following{/other_user}","gists_url":"https://api.github.com/users/White-Oak/gists{/gist_id}","starred_url":"https://api.github.com/users/White-Oak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/White-Oak/subscriptions","organizations_url":"https://api.github.com/users/White-Oak/orgs","repos_url":"https://api.github.com/users/White-Oak/repos","events_url":"https://api.github.com/users/White-Oak/events{/privacy}","received_events_url":"https://api.github.com/users/White-Oak/received_events","type":"User","site_admin":false},"body":"I was trying to form error messages, but I couldn't, because of lifetimes. That's why they weren't `static`.\r\n\r\nAnd didn't know about the first case of elision, thanks!","created_at":"2016-03-22T23:24:24Z","updated_at":"2016-03-22T23:24:24Z","html_url":"https://github.com/cybergeek94/multipart/pull/31#discussion_r57087277","pull_request_url":"https://api.github.com/repos/cybergeek94/multipart/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/comments/57087277"},"html":{"href":"https://github.com/cybergeek94/multipart/pull/31#discussion_r57087277"},"pull_request":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/cybergeek94/multipart/pulls/31","id":63474747,"html_url":"https://github.com/cybergeek94/multipart/pull/31","diff_url":"https://github.com/cybergeek94/multipart/pull/31.diff","patch_url":"https://github.com/cybergeek94/multipart/pull/31.patch","issue_url":"https://api.github.com/repos/cybergeek94/multipart/issues/31","number":31,"state":"closed","locked":false,"title":"tiny_http sample","user":{"login":"White-Oak","id":2813216,"avatar_url":"https://avatars.githubusercontent.com/u/2813216?v=3","gravatar_id":"","url":"https://api.github.com/users/White-Oak","html_url":"https://github.com/White-Oak","followers_url":"https://api.github.com/users/White-Oak/followers","following_url":"https://api.github.com/users/White-Oak/following{/other_user}","gists_url":"https://api.github.com/users/White-Oak/gists{/gist_id}","starred_url":"https://api.github.com/users/White-Oak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/White-Oak/subscriptions","organizations_url":"https://api.github.com/users/White-Oak/orgs","repos_url":"https://api.github.com/users/White-Oak/repos","events_url":"https://api.github.com/users/White-Oak/events{/privacy}","received_events_url":"https://api.github.com/users/White-Oak/received_events","type":"User","site_admin":false},"body":"I seem to be the first one with the sample, so I am not entirely sure if I'm right with the code style etc, but the sample works perfectly!\r\n\r\npinging @cybergeek94 for review.","created_at":"2016-03-19T18:22:33Z","updated_at":"2016-03-22T23:24:24Z","closed_at":"2016-03-22T21:28:54Z","merged_at":"2016-03-22T21:28:54Z","merge_commit_sha":"3c29f29925613d78bd6d0b30e3a39ab1e1e4a468","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cybergeek94/multipart/pulls/31/commits","review_comments_url":"https://api.github.com/repos/cybergeek94/multipart/pulls/31/comments","review_comment_url":"https://api.github.com/repos/cybergeek94/multipart/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cybergeek94/multipart/issues/31/comments","statuses_url":"https://api.github.com/repos/cybergeek94/multipart/statuses/197109d6709d20dcff343d11549f6906ddafd5f5","head":{"label":"White-Oak:master","ref":"master","sha":"197109d6709d20dcff343d11549f6906ddafd5f5","user":{"login":"White-Oak","id":2813216,"avatar_url":"https://avatars.githubusercontent.com/u/2813216?v=3","gravatar_id":"","url":"https://api.github.com/users/White-Oak","html_url":"https://github.com/White-Oak","followers_url":"https://api.github.com/users/White-Oak/followers","following_url":"https://api.github.com/users/White-Oak/following{/other_user}","gists_url":"https://api.github.com/users/White-Oak/gists{/gist_id}","starred_url":"https://api.github.com/users/White-Oak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/White-Oak/subscriptions","organizations_url":"https://api.github.com/users/White-Oak/orgs","repos_url":"https://api.github.com/users/White-Oak/repos","events_url":"https://api.github.com/users/White-Oak/events{/privacy}","received_events_url":"https://api.github.com/users/White-Oak/received_events","type":"User","site_admin":false},"repo":{"id":54246268,"name":"multipart","full_name":"White-Oak/multipart","owner":{"login":"White-Oak","id":2813216,"avatar_url":"https://avatars.githubusercontent.com/u/2813216?v=3","gravatar_id":"","url":"https://api.github.com/users/White-Oak","html_url":"https://github.com/White-Oak","followers_url":"https://api.github.com/users/White-Oak/followers","following_url":"https://api.github.com/users/White-Oak/following{/other_user}","gists_url":"https://api.github.com/users/White-Oak/gists{/gist_id}","starred_url":"https://api.github.com/users/White-Oak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/White-Oak/subscriptions","organizations_url":"https://api.github.com/users/White-Oak/orgs","repos_url":"https://api.github.com/users/White-Oak/repos","events_url":"https://api.github.com/users/White-Oak/events{/privacy}","received_events_url":"https://api.github.com/users/White-Oak/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/White-Oak/multipart","description":"A backend-agnostic extension for file uploads in HTTP libraries for Rust","fork":true,"url":"https://api.github.com/repos/White-Oak/multipart","forks_url":"https://api.github.com/repos/White-Oak/multipart/forks","keys_url":"https://api.github.com/repos/White-Oak/multipart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/White-Oak/multipart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/White-Oak/multipart/teams","hooks_url":"https://api.github.com/repos/White-Oak/multipart/hooks","issue_events_url":"https://api.github.com/repos/White-Oak/multipart/issues/events{/number}","events_url":"https://api.github.com/repos/White-Oak/multipart/events","assignees_url":"https://api.github.com/repos/White-Oak/multipart/assignees{/user}","branches_url":"https://api.github.com/repos/White-Oak/multipart/branches{/branch}","tags_url":"https://api.github.com/repos/White-Oak/multipart/tags","blobs_url":"https://api.github.com/repos/White-Oak/multipart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/White-Oak/multipart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/White-Oak/multipart/git/refs{/sha}","trees_url":"https://api.github.com/repos/White-Oak/multipart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/White-Oak/multipart/statuses/{sha}","languages_url":"https://api.github.com/repos/White-Oak/multipart/languages","stargazers_url":"https://api.github.com/repos/White-Oak/multipart/stargazers","contributors_url":"https://api.github.com/repos/White-Oak/multipart/contributors","subscribers_url":"https://api.github.com/repos/White-Oak/multipart/subscribers","subscription_url":"https://api.github.com/repos/White-Oak/multipart/subscription","commits_url":"https://api.github.com/repos/White-Oak/multipart/commits{/sha}","git_commits_url":"https://api.github.com/repos/White-Oak/multipart/git/commits{/sha}","comments_url":"https://api.github.com/repos/White-Oak/multipart/comments{/number}","issue_comment_url":"https://api.github.com/repos/White-Oak/multipart/issues/comments{/number}","contents_url":"https://api.github.com/repos/White-Oak/multipart/contents/{+path}","compare_url":"https://api.github.com/repos/White-Oak/multipart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/White-Oak/multipart/merges","archive_url":"https://api.github.com/repos/White-Oak/multipart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/White-Oak/multipart/downloads","issues_url":"https://api.github.com/repos/White-Oak/multipart/issues{/number}","pulls_url":"https://api.github.com/repos/White-Oak/multipart/pulls{/number}","milestones_url":"https://api.github.com/repos/White-Oak/multipart/milestones{/number}","notifications_url":"https://api.github.com/repos/White-Oak/multipart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/White-Oak/multipart/labels{/name}","releases_url":"https://api.github.com/repos/White-Oak/multipart/releases{/id}","deployments_url":"https://api.github.com/repos/White-Oak/multipart/deployments","created_at":"2016-03-19T03:53:12Z","updated_at":"2016-03-19T03:53:13Z","pushed_at":"2016-03-22T12:10:11Z","git_url":"git://github.com/White-Oak/multipart.git","ssh_url":"git@github.com:White-Oak/multipart.git","clone_url":"https://github.com/White-Oak/multipart.git","svn_url":"https://github.com/White-Oak/multipart","homepage":"","size":903,"stargazers_count":0,"watchers_count":0,"language":"Rust","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":"cybergeek94:master","ref":"master","sha":"acd8cce6b016f5a31d55eb49bbbf85387d9c0aac","user":{"login":"cybergeek94","id":3198595,"avatar_url":"https://avatars.githubusercontent.com/u/3198595?v=3","gravatar_id":"","url":"https://api.github.com/users/cybergeek94","html_url":"https://github.com/cybergeek94","followers_url":"https://api.github.com/users/cybergeek94/followers","following_url":"https://api.github.com/users/cybergeek94/following{/other_user}","gists_url":"https://api.github.com/users/cybergeek94/gists{/gist_id}","starred_url":"https://api.github.com/users/cybergeek94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cybergeek94/subscriptions","organizations_url":"https://api.github.com/users/cybergeek94/orgs","repos_url":"https://api.github.com/users/cybergeek94/repos","events_url":"https://api.github.com/users/cybergeek94/events{/privacy}","received_events_url":"https://api.github.com/users/cybergeek94/received_events","type":"User","site_admin":false},"repo":{"id":25510903,"name":"multipart","full_name":"cybergeek94/multipart","owner":{"login":"cybergeek94","id":3198595,"avatar_url":"https://avatars.githubusercontent.com/u/3198595?v=3","gravatar_id":"","url":"https://api.github.com/users/cybergeek94","html_url":"https://github.com/cybergeek94","followers_url":"https://api.github.com/users/cybergeek94/followers","following_url":"https://api.github.com/users/cybergeek94/following{/other_user}","gists_url":"https://api.github.com/users/cybergeek94/gists{/gist_id}","starred_url":"https://api.github.com/users/cybergeek94/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cybergeek94/subscriptions","organizations_url":"https://api.github.com/users/cybergeek94/orgs","repos_url":"https://api.github.com/users/cybergeek94/repos","events_url":"https://api.github.com/users/cybergeek94/events{/privacy}","received_events_url":"https://api.github.com/users/cybergeek94/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cybergeek94/multipart","description":"A backend-agnostic extension for file uploads in HTTP libraries for Rust","fork":false,"url":"https://api.github.com/repos/cybergeek94/multipart","forks_url":"https://api.github.com/repos/cybergeek94/multipart/forks","keys_url":"https://api.github.com/repos/cybergeek94/multipart/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cybergeek94/multipart/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cybergeek94/multipart/teams","hooks_url":"https://api.github.com/repos/cybergeek94/multipart/hooks","issue_events_url":"https://api.github.com/repos/cybergeek94/multipart/issues/events{/number}","events_url":"https://api.github.com/repos/cybergeek94/multipart/events","assignees_url":"https://api.github.com/repos/cybergeek94/multipart/assignees{/user}","branches_url":"https://api.github.com/repos/cybergeek94/multipart/branches{/branch}","tags_url":"https://api.github.com/repos/cybergeek94/multipart/tags","blobs_url":"https://api.github.com/repos/cybergeek94/multipart/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cybergeek94/multipart/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cybergeek94/multipart/git/refs{/sha}","trees_url":"https://api.github.com/repos/cybergeek94/multipart/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cybergeek94/multipart/statuses/{sha}","languages_url":"https://api.github.com/repos/cybergeek94/multipart/languages","stargazers_url":"https://api.github.com/repos/cybergeek94/multipart/stargazers","contributors_url":"https://api.github.com/repos/cybergeek94/multipart/contributors","subscribers_url":"https://api.github.com/repos/cybergeek94/multipart/subscribers","subscription_url":"https://api.github.com/repos/cybergeek94/multipart/subscription","commits_url":"https://api.github.com/repos/cybergeek94/multipart/commits{/sha}","git_commits_url":"https://api.github.com/repos/cybergeek94/multipart/git/commits{/sha}","comments_url":"https://api.github.com/repos/cybergeek94/multipart/comments{/number}","issue_comment_url":"https://api.github.com/repos/cybergeek94/multipart/issues/comments{/number}","contents_url":"https://api.github.com/repos/cybergeek94/multipart/contents/{+path}","compare_url":"https://api.github.com/repos/cybergeek94/multipart/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cybergeek94/multipart/merges","archive_url":"https://api.github.com/repos/cybergeek94/multipart/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cybergeek94/multipart/downloads","issues_url":"https://api.github.com/repos/cybergeek94/multipart/issues{/number}","pulls_url":"https://api.github.com/repos/cybergeek94/multipart/pulls{/number}","milestones_url":"https://api.github.com/repos/cybergeek94/multipart/milestones{/number}","notifications_url":"https://api.github.com/repos/cybergeek94/multipart/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cybergeek94/multipart/labels{/name}","releases_url":"https://api.github.com/repos/cybergeek94/multipart/releases{/id}","deployments_url":"https://api.github.com/repos/cybergeek94/multipart/deployments","created_at":"2014-10-21T08:23:42Z","updated_at":"2016-03-22T15:08:04Z","pushed_at":"2016-03-22T21:32:11Z","git_url":"git://github.com/cybergeek94/multipart.git","ssh_url":"git@github.com:cybergeek94/multipart.git","clone_url":"https://github.com/cybergeek94/multipart.git","svn_url":"https://github.com/cybergeek94/multipart","homepage":"","size":906,"stargazers_count":25,"watchers_count":25,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7,"mirror_url":null,"open_issues_count":1,"forks":7,"open_issues":1,"watchers":25,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/31"},"html":{"href":"https://github.com/cybergeek94/multipart/pull/31"},"issue":{"href":"https://api.github.com/repos/cybergeek94/multipart/issues/31"},"comments":{"href":"https://api.github.com/repos/cybergeek94/multipart/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cybergeek94/multipart/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/cybergeek94/multipart/statuses/197109d6709d20dcff343d11549f6906ddafd5f5"}}}}