mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Implement a basic test for Fetch and fix errors it finds
This commit is contained in:
parent
099beee85c
commit
5a8c533755
5 changed files with 89 additions and 30 deletions
|
@ -13,7 +13,7 @@ use url::Url;
|
|||
|
||||
pub trait ResponseMethods {
|
||||
fn new() -> Response;
|
||||
fn to_filtered(self, ResponseType) -> Response;
|
||||
fn to_filtered(Rc<Response>, ResponseType) -> Response;
|
||||
}
|
||||
|
||||
impl ResponseMethods for Response {
|
||||
|
@ -34,17 +34,23 @@ impl ResponseMethods for Response {
|
|||
|
||||
/// Convert to a filtered response, of type `filter_type`.
|
||||
/// Do not use with type Error or Default
|
||||
fn to_filtered(self, filter_type: ResponseType) -> Response {
|
||||
fn to_filtered(old_response: Rc<Response>, filter_type: ResponseType) -> Response {
|
||||
|
||||
assert!(filter_type != ResponseType::Error);
|
||||
assert!(filter_type != ResponseType::Default);
|
||||
if self.is_network_error() {
|
||||
return self;
|
||||
|
||||
if Response::is_network_error(&old_response) {
|
||||
return Response::network_error();
|
||||
}
|
||||
let old_headers = self.headers.clone();
|
||||
let mut response = self.clone();
|
||||
response.internal_response = Some(Rc::new(self));
|
||||
|
||||
let old_headers = old_response.headers.clone();
|
||||
let mut response = (*old_response).clone();
|
||||
response.internal_response = Some(old_response);
|
||||
|
||||
match filter_type {
|
||||
|
||||
ResponseType::Default | ResponseType::Error => unreachable!(),
|
||||
|
||||
ResponseType::Basic => {
|
||||
let headers = old_headers.iter().filter(|header| {
|
||||
match &*header.name().to_ascii_lowercase() {
|
||||
|
@ -55,6 +61,7 @@ impl ResponseMethods for Response {
|
|||
response.headers = headers;
|
||||
response.response_type = filter_type;
|
||||
},
|
||||
|
||||
ResponseType::CORS => {
|
||||
let headers = old_headers.iter().filter(|header| {
|
||||
match &*header.name().to_ascii_lowercase() {
|
||||
|
@ -67,6 +74,7 @@ impl ResponseMethods for Response {
|
|||
response.headers = headers;
|
||||
response.response_type = filter_type;
|
||||
},
|
||||
|
||||
ResponseType::Opaque |
|
||||
ResponseType::OpaqueRedirect => {
|
||||
response.headers = Headers::new();
|
||||
|
@ -74,6 +82,7 @@ impl ResponseMethods for Response {
|
|||
response.body = ResponseBody::Empty;
|
||||
}
|
||||
}
|
||||
|
||||
response
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue