@@ -44,6 +44,7 @@ use url::Url;
44
44
use hyper:: Client ;
45
45
use hyper:: header:: UserAgent ;
46
46
use hyper:: status:: StatusCode ;
47
+ use hyper:: client:: Response ;
47
48
48
49
const USER_AGENT : & ' static str = "robotparser-rs (https://crates.io/crates/robotparser)" ;
49
50
@@ -247,7 +248,7 @@ impl<'a> RobotFileParser<'a> {
247
248
let client = Client :: new ( ) ;
248
249
let request = client. get ( self . url . clone ( ) )
249
250
. header ( UserAgent ( USER_AGENT . to_owned ( ) ) ) ;
250
- let mut res = match request. send ( ) {
251
+ let res = match request. send ( ) {
251
252
Ok ( res) => res,
252
253
Err ( _) => {
253
254
return ;
@@ -260,16 +261,19 @@ impl<'a> RobotFileParser<'a> {
260
261
status if status >= StatusCode :: BadRequest && status < StatusCode :: InternalServerError => {
261
262
self . allow_all . set ( true ) ;
262
263
}
263
- StatusCode :: Ok => {
264
- let mut buf = String :: new ( ) ;
265
- res. read_to_string ( & mut buf) . unwrap ( ) ;
266
- let lines: Vec < & str > = buf. split ( '\n' ) . collect ( ) ;
267
- self . parse ( & lines) ;
268
- }
264
+ StatusCode :: Ok => self . from_response ( res) ,
269
265
_ => { }
270
266
}
271
267
}
272
268
269
+ /// Reads the HTTP response and feeds it to the parser.
270
+ pub fn from_response ( & self , mut response : Response ) {
271
+ let mut buf = String :: new ( ) ;
272
+ response. read_to_string ( & mut buf) . unwrap ( ) ;
273
+ let lines: Vec < & str > = buf. split ( '\n' ) . collect ( ) ;
274
+ self . parse ( & lines) ;
275
+ }
276
+
273
277
fn _add_entry ( & self , entry : Entry < ' a > ) {
274
278
if entry. has_useragent ( "*" ) {
275
279
// the default entry is considered last
0 commit comments