1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use Response;
use Error;
use Read;
/// A function to help unwrap a Hyper Client's Response, and make sure
/// it actually responds with a body, and a successful status code.
/// The general idea of this is to get the actual result of the request,
/// instead of the request object as that's all we'll end up using.
///
/// * `resp` - A Hyper Client `Result<Response, Error>`.
///
/// Returns a `Result<String, u16>` Where the result is the response body as a string,
/// and the error is either the HTTP Status code or one a few unique errors:
///
/// Error Code `1`: The actual response object had an error.
/// Error Code `2`: We failed to read the result to a string, but the request was successful.
///
/// # Examples
///
/// You can run the get_response_body method like so with a normal request:
///
/// ```rust,no_run
/// extern crate hyper;
/// extern crate statusio;
/// let client = hyper::client::Client::new();
/// let resp = statusio::helpers::get_response_body(client.get("https://google.com").send());
/// ```
///
/// If the underlying hyper request has error'd out it will return an error code of "1":
///
/// ```rust,no_run
/// extern crate hyper;
/// extern crate statusio;
/// let client = hyper::client::Client::new();
/// let resp = statusio::helpers::get_response_body(client.get("hftp://google.com").send());
/// assert!(resp.is_err());
/// assert!(resp.err().unwrap() == 1);
/// ```