{"action":"created","issue":{"url":"https://api.github.com/repos/iron/iron/issues/410","labels_url":"https://api.github.com/repos/iron/iron/issues/410/labels{/name}","comments_url":"https://api.github.com/repos/iron/iron/issues/410/comments","events_url":"https://api.github.com/repos/iron/iron/issues/410/events","html_url":"https://github.com/iron/iron/issues/410","id":119649639,"number":410,"title":"ResponseBody not writing out","user":{"login":"mcasper","id":6878025,"avatar_url":"https://avatars.githubusercontent.com/u/6878025?v=3","gravatar_id":"","url":"https://api.github.com/users/mcasper","html_url":"https://github.com/mcasper","followers_url":"https://api.github.com/users/mcasper/followers","following_url":"https://api.github.com/users/mcasper/following{/other_user}","gists_url":"https://api.github.com/users/mcasper/gists{/gist_id}","starred_url":"https://api.github.com/users/mcasper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcasper/subscriptions","organizations_url":"https://api.github.com/users/mcasper/orgs","repos_url":"https://api.github.com/users/mcasper/repos","events_url":"https://api.github.com/users/mcasper/events{/privacy}","received_events_url":"https://api.github.com/users/mcasper/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-01T06:09:49Z","updated_at":"2015-12-01T06:21:30Z","closed_at":null,"body":"@mikeastock and I are trying to use `ResponseBody` to read the body of an `iron::response::Response` in order to test our Handlers (in conjunction with reem/iron-test). However, it seems that `ResponseBody` is not able to write its buffer back out to something that can be read (like an `&[u8]`), making it impossible make assertions about the response body. The following code models the problem:\r\n\r\n```Rust\r\nfn hello_world_handler(_: &mut Request) -> IronResult<Response> {\r\n    Ok(Response::with((iron::status::Ok, \"Hello, world!\")))\r\n}\r\n\r\nfn main() {\r\n    let data = Cursor::new(Vec::new());\r\n    let mut stream = MockStream::new(data);\r\n    let mut reader = BufReader::new(&mut stream as &mut NetworkStream);\r\n    let mut req = request::new(method::Get,\r\n                               Url::parse(\"http://localhost:3000/users\").unwrap(),\r\n                               &mut reader);\r\n\r\n    let response = hello_world_handler(&mut req).unwrap();\r\n    let f = ::std::fs::File::create(\"/tmp/test\").unwrap();\r\n    let mut response_body = ResponseBody::new(f);\r\n    response.body.unwrap().write_body(&mut response_body).ok();\r\n\r\n    let mut result = Vec::new();\r\n    response_body.write(&mut result).ok();\r\n\r\n    assert_eq!(result, b\"Hello, world!\");\r\n}\r\n```\r\nRunning the code shows that nothing was ever written to `result`:\r\n```\r\nthread '<main>' panicked at 'assertion failed: `(left == right)` (left: `[]`, right: `[72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]`)', src/main.rs:33\r\n```\r\nAnd if we were to inspect the `usize` returned by the `response_body.write()` call, we would see that it is indeed 0.\r\n\r\nHowever, if you look at the file we used as the initial buffer:\r\n```\r\ncat /tmp/test\r\nHello, world!%\r\n```\r\nYou'll see that we did extract the body successfully from the `Response`.\r\n\r\nSo the problem seems to be with `ResponseBody`, was wondering if we could get any guidance on this.\r\n\r\nThanks guys!"},"comment":{"url":"https://api.github.com/repos/iron/iron/issues/comments/160867785","html_url":"https://github.com/iron/iron/issues/410#issuecomment-160867785","issue_url":"https://api.github.com/repos/iron/iron/issues/410","id":160867785,"user":{"login":"mcasper","id":6878025,"avatar_url":"https://avatars.githubusercontent.com/u/6878025?v=3","gravatar_id":"","url":"https://api.github.com/users/mcasper","html_url":"https://github.com/mcasper","followers_url":"https://api.github.com/users/mcasper/followers","following_url":"https://api.github.com/users/mcasper/following{/other_user}","gists_url":"https://api.github.com/users/mcasper/gists{/gist_id}","starred_url":"https://api.github.com/users/mcasper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mcasper/subscriptions","organizations_url":"https://api.github.com/users/mcasper/orgs","repos_url":"https://api.github.com/users/mcasper/repos","events_url":"https://api.github.com/users/mcasper/events{/privacy}","received_events_url":"https://api.github.com/users/mcasper/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T06:21:30Z","updated_at":"2015-12-01T06:21:30Z","body":"We got bytes!\r\n\r\n```\r\nthread '<main>' panicked at 'assertion failed: `(left == right)` (left: `[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]`, right: `[72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33]`)', src/main.rs:33\r\n```"}}