now the request check the url parsed
parent
b77d4959ea
commit
d02da8ff20
|
@ -31,7 +31,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn simple_request() {
|
fn simple_request() {
|
||||||
let req: Request = RequestBase::new("https://httpbin.org/");
|
let req: Request = RequestBase::new("https://httpbin.org/").unwrap();
|
||||||
let resp = req.launch();
|
let resp = req.launch();
|
||||||
assert_eq!(resp.status_code, StatusCode::OK);
|
assert_eq!(resp.status_code, StatusCode::OK);
|
||||||
assert!(resp.css::<Selector>("h2")[0].html().contains("httpbin.org"));
|
assert!(resp.css::<Selector>("h2")[0].html().contains("httpbin.org"));
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use crate::response;
|
use crate::response;
|
||||||
use http::status::StatusCode;
|
use http::status::StatusCode;
|
||||||
use url::Url;
|
use url::{ParseError, Url};
|
||||||
|
|
||||||
pub trait RequestBase {
|
pub trait RequestBase {
|
||||||
fn new(url: &'static str) -> Self;
|
fn new(url: &'static str) -> Result<Self, ParseError>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
fn launch(&self) -> response::Response;
|
fn launch(&self) -> response::Response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,9 +15,10 @@ pub struct Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RequestBase for Request {
|
impl RequestBase for Request {
|
||||||
fn new(url: &'static str) -> Request {
|
fn new(url: &'static str) -> Result<Request, ParseError> {
|
||||||
Request {
|
match Url::parse(url) {
|
||||||
url: Url::parse(url).unwrap(),
|
Ok(url_parsed) => Ok(Request { url: url_parsed }),
|
||||||
|
Err(error) => Err(error),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue