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