mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Auto merge of #14127 - servo:response-new-url, r=nox
Make Response::url private. <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14127) <!-- Reviewable:end -->
This commit is contained in:
commit
d8a0a00032
3 changed files with 14 additions and 18 deletions
|
@ -409,9 +409,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
match url.scheme() {
|
match url.scheme() {
|
||||||
"about" if url.path() == "blank" => {
|
"about" if url.path() == "blank" => {
|
||||||
let mut response = Response::new();
|
let mut response = Response::new(url);
|
||||||
// https://github.com/whatwg/fetch/issues/312
|
|
||||||
response.url = Some(url);
|
|
||||||
response.headers.set(ContentType(mime!(Text / Html; Charset = Utf8)));
|
response.headers.set(ContentType(mime!(Text / Html; Charset = Utf8)));
|
||||||
*response.body.lock().unwrap() = ResponseBody::Done(vec![]);
|
*response.body.lock().unwrap() = ResponseBody::Done(vec![]);
|
||||||
response
|
response
|
||||||
|
@ -425,9 +423,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
if *request.method.borrow() == Method::Get {
|
if *request.method.borrow() == Method::Get {
|
||||||
match decode(&url) {
|
match decode(&url) {
|
||||||
Ok((mime, bytes)) => {
|
Ok((mime, bytes)) => {
|
||||||
let mut response = Response::new();
|
let mut response = Response::new(url);
|
||||||
// https://github.com/whatwg/fetch/issues/312
|
|
||||||
response.url = Some(url.clone());
|
|
||||||
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
||||||
response.headers.set(ContentType(mime));
|
response.headers.set(ContentType(mime));
|
||||||
response
|
response
|
||||||
|
@ -449,9 +445,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
let _ = file.read_to_end(&mut bytes);
|
let _ = file.read_to_end(&mut bytes);
|
||||||
let mime = guess_mime_type(file_path);
|
let mime = guess_mime_type(file_path);
|
||||||
|
|
||||||
let mut response = Response::new();
|
let mut response = Response::new(url);
|
||||||
// https://github.com/whatwg/fetch/issues/312
|
|
||||||
response.url = Some(url.clone());
|
|
||||||
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
||||||
response.headers.set(ContentType(mime));
|
response.headers.set(ContentType(mime));
|
||||||
response
|
response
|
||||||
|
@ -475,8 +469,7 @@ fn basic_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
|
|
||||||
match load_blob_sync(url.clone(), context.filemanager.clone()) {
|
match load_blob_sync(url.clone(), context.filemanager.clone()) {
|
||||||
Ok((headers, bytes)) => {
|
Ok((headers, bytes)) => {
|
||||||
let mut response = Response::new();
|
let mut response = Response::new(url);
|
||||||
response.url = Some(url.clone());
|
|
||||||
response.headers = headers;
|
response.headers = headers;
|
||||||
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
|
||||||
response
|
response
|
||||||
|
@ -694,7 +687,7 @@ fn http_redirect_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
Some(&Location(ref location)) => location.clone(),
|
Some(&Location(ref location)) => location.clone(),
|
||||||
_ => return Response::network_error(NetworkError::Internal("Location header parsing failure".into()))
|
_ => return Response::network_error(NetworkError::Internal("Location header parsing failure".into()))
|
||||||
};
|
};
|
||||||
let response_url = response.actual_response().url.as_ref().unwrap();
|
let response_url = response.actual_response().url().unwrap();
|
||||||
let location_url = response_url.join(&*location);
|
let location_url = response_url.join(&*location);
|
||||||
let location_url = match location_url {
|
let location_url = match location_url {
|
||||||
Ok(url) => url,
|
Ok(url) => url,
|
||||||
|
@ -1028,8 +1021,7 @@ fn http_network_fetch<UI: 'static + UIProvider>(request: Rc<Request>,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut response = Response::new();
|
let mut response = Response::new(url.clone());
|
||||||
response.url = Some(url.clone());
|
|
||||||
response.status = Some(res.response.status);
|
response.status = Some(res.response.status);
|
||||||
response.raw_status = Some((res.response.status_raw().0,
|
response.raw_status = Some((res.response.status_raw().0,
|
||||||
res.response.status_raw().1.as_bytes().to_vec()));
|
res.response.status_raw().1.as_bytes().to_vec()));
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub enum ResponseMsg {
|
||||||
pub struct Response {
|
pub struct Response {
|
||||||
pub response_type: ResponseType,
|
pub response_type: ResponseType,
|
||||||
pub termination_reason: Option<TerminationReason>,
|
pub termination_reason: Option<TerminationReason>,
|
||||||
pub url: Option<Url>,
|
url: Option<Url>,
|
||||||
pub url_list: RefCell<Vec<Url>>,
|
pub url_list: RefCell<Vec<Url>>,
|
||||||
/// `None` can be considered a StatusCode of `0`.
|
/// `None` can be considered a StatusCode of `0`.
|
||||||
#[ignore_heap_size_of = "Defined in hyper"]
|
#[ignore_heap_size_of = "Defined in hyper"]
|
||||||
|
@ -100,11 +100,11 @@ pub struct Response {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Response {
|
impl Response {
|
||||||
pub fn new() -> Response {
|
pub fn new(url: Url) -> Response {
|
||||||
Response {
|
Response {
|
||||||
response_type: ResponseType::Default,
|
response_type: ResponseType::Default,
|
||||||
termination_reason: None,
|
termination_reason: None,
|
||||||
url: None,
|
url: Some(url),
|
||||||
url_list: RefCell::new(Vec::new()),
|
url_list: RefCell::new(Vec::new()),
|
||||||
status: Some(StatusCode::Ok),
|
status: Some(StatusCode::Ok),
|
||||||
raw_status: Some((200, b"OK".to_vec())),
|
raw_status: Some((200, b"OK".to_vec())),
|
||||||
|
@ -136,6 +136,10 @@ impl Response {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn url(&self) -> Option<&Url> {
|
||||||
|
self.url.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_network_error(&self) -> bool {
|
pub fn is_network_error(&self) -> bool {
|
||||||
match self.response_type {
|
match self.response_type {
|
||||||
ResponseType::Error(..) => true,
|
ResponseType::Error(..) => true,
|
||||||
|
|
|
@ -383,8 +383,8 @@ fn test_fetch_response_is_opaque_filtered() {
|
||||||
assert!(!fetch_response.is_network_error());
|
assert!(!fetch_response.is_network_error());
|
||||||
assert_eq!(fetch_response.response_type, ResponseType::Opaque);
|
assert_eq!(fetch_response.response_type, ResponseType::Opaque);
|
||||||
|
|
||||||
|
assert!(fetch_response.url().is_none());
|
||||||
assert!(fetch_response.url_list.into_inner().len() == 0);
|
assert!(fetch_response.url_list.into_inner().len() == 0);
|
||||||
assert!(fetch_response.url.is_none());
|
|
||||||
// this also asserts that status message is "the empty byte sequence"
|
// this also asserts that status message is "the empty byte sequence"
|
||||||
assert!(fetch_response.status.is_none());
|
assert!(fetch_response.status.is_none());
|
||||||
assert_eq!(fetch_response.headers, Headers::new());
|
assert_eq!(fetch_response.headers, Headers::new());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue