Merge pull request #8 from messense/feature/from-response-mutability

Change from_response method signature
This commit is contained in:
messense 2016-08-25 18:22:03 +08:00 committed by GitHub
commit c32933db75

View file

@ -248,7 +248,7 @@ impl<'a> RobotFileParser<'a> {
let client = Client::new(); let client = Client::new();
let request = client.get(self.url.clone()) let request = client.get(self.url.clone())
.header(UserAgent(USER_AGENT.to_owned())); .header(UserAgent(USER_AGENT.to_owned()));
let res = match request.send() { let mut res = match request.send() {
Ok(res) => res, Ok(res) => res,
Err(_) => { Err(_) => {
return; return;
@ -261,13 +261,13 @@ impl<'a> RobotFileParser<'a> {
status if status >= StatusCode::BadRequest && status < StatusCode::InternalServerError => { status if status >= StatusCode::BadRequest && status < StatusCode::InternalServerError => {
self.allow_all.set(true); self.allow_all.set(true);
} }
StatusCode::Ok => self.from_response(res), StatusCode::Ok => self.from_response(&mut res),
_ => {} _ => {}
} }
} }
/// Reads the HTTP response and feeds it to the parser. /// Reads the HTTP response and feeds it to the parser.
pub fn from_response(&self, mut response: Response) { pub fn from_response(&self, response: &mut Response) {
let mut buf = String::new(); let mut buf = String::new();
response.read_to_string(&mut buf).unwrap(); response.read_to_string(&mut buf).unwrap();
let lines: Vec<&str> = buf.split('\n').collect(); let lines: Vec<&str> = buf.split('\n').collect();