mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
Create HttpStatus to safely deal with HTTP responses status. (#33581)
Signed-off-by: webbeef <me@webbeef.org>
This commit is contained in:
parent
013473f1d5
commit
58f34ad7a3
30 changed files with 344 additions and 403 deletions
|
@ -19,6 +19,7 @@ use ipc_channel::ipc::{self, IpcReceiver};
|
|||
use log::warn;
|
||||
use mime::{self, Mime};
|
||||
use net_traits::filemanager_thread::{FileTokenCheck, RelativePos};
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::{
|
||||
is_cors_safelisted_method, is_cors_safelisted_request_header, BodyChunkRequest,
|
||||
BodyChunkResponse, CredentialsMode, Destination, Origin, RedirectMode, Referrer, Request,
|
||||
|
@ -599,8 +600,7 @@ fn create_blank_reply(url: ServoUrl, timing_type: ResourceTimingType) -> Respons
|
|||
.headers
|
||||
.typed_insert(ContentType::from(mime::TEXT_HTML_UTF_8));
|
||||
*response.body.lock().unwrap() = ResponseBody::Done(vec![]);
|
||||
response.status = Some((StatusCode::OK, "OK".to_string()));
|
||||
response.raw_status = Some((StatusCode::OK.as_u16(), b"OK".to_vec()));
|
||||
response.status = HttpStatus::default();
|
||||
response
|
||||
}
|
||||
|
||||
|
@ -681,13 +681,13 @@ async fn scheme_fetch(
|
|||
}
|
||||
}
|
||||
|
||||
fn is_null_body_status(status: &Option<(StatusCode, String)>) -> bool {
|
||||
fn is_null_body_status(status: &HttpStatus) -> bool {
|
||||
matches!(
|
||||
status,
|
||||
Some((StatusCode::SWITCHING_PROTOCOLS, ..)) |
|
||||
Some((StatusCode::NO_CONTENT, ..)) |
|
||||
Some((StatusCode::RESET_CONTENT, ..)) |
|
||||
Some((StatusCode::NOT_MODIFIED, ..))
|
||||
status.try_code(),
|
||||
Some(StatusCode::SWITCHING_PROTOCOLS) |
|
||||
Some(StatusCode::NO_CONTENT) |
|
||||
Some(StatusCode::RESET_CONTENT) |
|
||||
Some(StatusCode::NOT_MODIFIED)
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ use malloc_size_of::{
|
|||
Measurable,
|
||||
};
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::Request;
|
||||
use net_traits::response::{HttpsState, Response, ResponseBody};
|
||||
use net_traits::{FetchMetadata, Metadata, ResourceFetchTiming};
|
||||
|
@ -70,8 +71,7 @@ struct MeasurableCachedResource {
|
|||
metadata: CachedMetadata,
|
||||
location_url: Option<Result<ServoUrl, String>>,
|
||||
https_state: HttpsState,
|
||||
status: Option<(StatusCode, String)>,
|
||||
raw_status: Option<(u16, Vec<u8>)>,
|
||||
status: HttpStatus,
|
||||
url_list: Vec<ServoUrl>,
|
||||
expires: Duration,
|
||||
last_validated: Instant,
|
||||
|
@ -105,7 +105,7 @@ struct MeasurableCachedMetadata {
|
|||
/// Character set.
|
||||
pub charset: Option<String>,
|
||||
/// HTTP Status
|
||||
pub status: Option<(u16, Vec<u8>)>,
|
||||
pub status: HttpStatus,
|
||||
}
|
||||
|
||||
impl MallocSizeOf for CachedMetadata {
|
||||
|
@ -132,9 +132,9 @@ pub struct HttpCache {
|
|||
}
|
||||
|
||||
/// Determine if a response is cacheable by default <https://tools.ietf.org/html/rfc7231#section-6.1>
|
||||
fn is_cacheable_by_default(status_code: u16) -> bool {
|
||||
fn is_cacheable_by_default(status_code: StatusCode) -> bool {
|
||||
matches!(
|
||||
status_code,
|
||||
status_code.as_u16(),
|
||||
200 | 203 | 204 | 206 | 300 | 301 | 404 | 405 | 410 | 414 | 501
|
||||
)
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ fn get_response_expiry(response: &Response) -> Duration {
|
|||
}
|
||||
// Calculating Heuristic Freshness
|
||||
// <https://tools.ietf.org/html/rfc7234#section-4.2.2>
|
||||
if let Some((ref code, _)) = response.raw_status {
|
||||
if let Some(ref code) = response.status.try_code() {
|
||||
// <https://tools.ietf.org/html/rfc7234#section-5.5.4>
|
||||
// Since presently we do not generate a Warning header field with a 113 warn-code,
|
||||
// 24 hours minus response age is the max for heuristic calculation.
|
||||
|
@ -318,9 +318,6 @@ fn create_cached_response(
|
|||
.location_url
|
||||
.clone_from(&cached_resource.data.location_url);
|
||||
response.status.clone_from(&cached_resource.data.status);
|
||||
response
|
||||
.raw_status
|
||||
.clone_from(&cached_resource.data.raw_status);
|
||||
response.url_list.clone_from(&cached_resource.data.url_list);
|
||||
response.https_state = cached_resource.data.https_state;
|
||||
response.referrer = request.referrer.to_url().cloned();
|
||||
|
@ -357,8 +354,7 @@ fn create_resource_with_bytes_from_resource(
|
|||
metadata: resource.data.metadata.clone(),
|
||||
location_url: resource.data.location_url.clone(),
|
||||
https_state: resource.data.https_state,
|
||||
status: Some((StatusCode::PARTIAL_CONTENT, "Partial Content".into())),
|
||||
raw_status: Some((206, b"Partial Content".to_vec())),
|
||||
status: StatusCode::PARTIAL_CONTENT.into(),
|
||||
url_list: resource.data.url_list.clone(),
|
||||
expires: resource.data.expires,
|
||||
last_validated: resource.data.last_validated,
|
||||
|
@ -373,20 +369,12 @@ fn handle_range_request(
|
|||
range_spec: Vec<(Bound<u64>, Bound<u64>)>,
|
||||
done_chan: &mut DoneChannel,
|
||||
) -> Option<CachedResponse> {
|
||||
let mut complete_cached_resources =
|
||||
candidates
|
||||
.iter()
|
||||
.filter(|resource| match resource.data.raw_status {
|
||||
Some((ref code, _)) => *code == 200,
|
||||
None => false,
|
||||
});
|
||||
let partial_cached_resources =
|
||||
candidates
|
||||
.iter()
|
||||
.filter(|resource| match resource.data.raw_status {
|
||||
Some((ref code, _)) => *code == 206,
|
||||
None => false,
|
||||
});
|
||||
let mut complete_cached_resources = candidates
|
||||
.iter()
|
||||
.filter(|resource| resource.data.status == StatusCode::OK);
|
||||
let partial_cached_resources = candidates
|
||||
.iter()
|
||||
.filter(|resource| resource.data.status == StatusCode::PARTIAL_CONTENT);
|
||||
match (
|
||||
range_spec.first().unwrap(),
|
||||
complete_cached_resources.next(),
|
||||
|
@ -659,9 +647,9 @@ impl HttpCache {
|
|||
//
|
||||
// TODO: Combining partial content to fulfill a non-Range request
|
||||
// see https://tools.ietf.org/html/rfc7234#section-3.3
|
||||
match cached_resource.data.raw_status {
|
||||
Some((ref code, _)) => {
|
||||
if *code == 206 {
|
||||
match cached_resource.data.status.try_code() {
|
||||
Some(ref code) => {
|
||||
if *code == StatusCode::PARTIAL_CONTENT {
|
||||
continue;
|
||||
}
|
||||
},
|
||||
|
@ -699,7 +687,7 @@ impl HttpCache {
|
|||
if response.actual_response().is_network_error() {
|
||||
return *resource.body.lock().unwrap() == ResponseBody::Empty;
|
||||
}
|
||||
resource.data.raw_status == response.raw_status
|
||||
resource.data.status == response.status
|
||||
});
|
||||
|
||||
for cached_resource in relevant_cached_resources {
|
||||
|
@ -735,7 +723,7 @@ impl HttpCache {
|
|||
response: Response,
|
||||
done_chan: &mut DoneChannel,
|
||||
) -> Option<Response> {
|
||||
assert_eq!(response.status.map(|s| s.0), Some(StatusCode::NOT_MODIFIED));
|
||||
assert_eq!(response.status, StatusCode::NOT_MODIFIED);
|
||||
let entry_key = CacheKey::new(request);
|
||||
if let Some(cached_resources) = self.entries.get_mut(&entry_key) {
|
||||
if let Some(cached_resource) = cached_resources.iter_mut().next() {
|
||||
|
@ -774,8 +762,8 @@ impl HttpCache {
|
|||
constructed_response.referrer = request.referrer.to_url().cloned();
|
||||
constructed_response.referrer_policy = request.referrer_policy;
|
||||
constructed_response
|
||||
.raw_status
|
||||
.clone_from(&cached_resource.data.raw_status);
|
||||
.status
|
||||
.clone_from(&cached_resource.data.status);
|
||||
constructed_response
|
||||
.url_list
|
||||
.clone_from(&cached_resource.data.url_list);
|
||||
|
@ -874,7 +862,6 @@ impl HttpCache {
|
|||
location_url: response.location_url.clone(),
|
||||
https_state: response.https_state,
|
||||
status: response.status.clone(),
|
||||
raw_status: response.raw_status.clone(),
|
||||
url_list: response.url_list.clone(),
|
||||
expires: expiry,
|
||||
last_validated: Instant::now(),
|
||||
|
|
|
@ -35,6 +35,7 @@ use hyper_serde::Serde;
|
|||
use ipc_channel::ipc::{self, IpcSender};
|
||||
use ipc_channel::router::ROUTER;
|
||||
use log::{debug, error, info, log_enabled, warn};
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::pub_domains::reg_suffix;
|
||||
use net_traits::request::Origin::Origin as SpecificOrigin;
|
||||
use net_traits::request::{
|
||||
|
@ -381,7 +382,7 @@ fn send_response_to_devtools(
|
|||
devtools_chan: &Sender<DevtoolsControlMsg>,
|
||||
request_id: String,
|
||||
headers: Option<HeaderMap>,
|
||||
status: Option<(u16, Vec<u8>)>,
|
||||
status: HttpStatus,
|
||||
pipeline_id: PipelineId,
|
||||
) {
|
||||
let response = DevtoolsHttpResponse {
|
||||
|
@ -803,16 +804,11 @@ pub async fn http_fetch(
|
|||
if response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.try_code()
|
||||
.is_some_and(is_redirect_status)
|
||||
{
|
||||
// Substep 1.
|
||||
if response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.map_or(true, |s| s.0 != StatusCode::SEE_OTHER)
|
||||
{
|
||||
if response.actual_response().status != StatusCode::SEE_OTHER {
|
||||
// TODO: send RST_STREAM frame
|
||||
}
|
||||
|
||||
|
@ -989,11 +985,7 @@ pub async fn http_redirect_fetch(
|
|||
}
|
||||
|
||||
// Step 9
|
||||
if response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.map_or(true, |s| s.0 != StatusCode::SEE_OTHER) &&
|
||||
if response.actual_response().status != StatusCode::SEE_OTHER &&
|
||||
request.body.as_ref().is_some_and(|b| b.source_is_null())
|
||||
{
|
||||
return Response::network_error(NetworkError::Internal("Request body is not done".into()));
|
||||
|
@ -1008,11 +1000,11 @@ pub async fn http_redirect_fetch(
|
|||
if response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.is_some_and(|(code, _)| {
|
||||
((*code == StatusCode::MOVED_PERMANENTLY || *code == StatusCode::FOUND) &&
|
||||
.try_code()
|
||||
.is_some_and(|code| {
|
||||
((code == StatusCode::MOVED_PERMANENTLY || code == StatusCode::FOUND) &&
|
||||
request.method == Method::POST) ||
|
||||
(*code == StatusCode::SEE_OTHER &&
|
||||
(code == StatusCode::SEE_OTHER &&
|
||||
request.method != Method::HEAD &&
|
||||
request.method != Method::GET)
|
||||
})
|
||||
|
@ -1500,20 +1492,14 @@ async fn http_network_or_cache_fetch(
|
|||
let forward_response =
|
||||
http_network_fetch(http_request, include_credentials, done_chan, context).await;
|
||||
// Substep 3
|
||||
if let Some((200..=399, _)) = forward_response.raw_status {
|
||||
if !http_request.method.is_safe() {
|
||||
if let Ok(mut http_cache) = context.state.http_cache.write() {
|
||||
http_cache.invalidate(http_request, &forward_response);
|
||||
}
|
||||
if forward_response.status.in_range(200..=399) && !http_request.method.is_safe() {
|
||||
if let Ok(mut http_cache) = context.state.http_cache.write() {
|
||||
http_cache.invalidate(http_request, &forward_response);
|
||||
}
|
||||
}
|
||||
|
||||
// Substep 4
|
||||
if revalidating_flag &&
|
||||
forward_response
|
||||
.status
|
||||
.as_ref()
|
||||
.is_some_and(|s| s.0 == StatusCode::NOT_MODIFIED)
|
||||
{
|
||||
if revalidating_flag && forward_response.status == StatusCode::NOT_MODIFIED {
|
||||
if let Ok(mut http_cache) = context.state.http_cache.write() {
|
||||
// Ensure done_chan is None,
|
||||
// since the network response will be replaced by the revalidated stored one.
|
||||
|
@ -1616,8 +1602,8 @@ async fn http_network_or_cache_fetch(
|
|||
|
||||
// Step 10
|
||||
// FIXME: Figure out what to do with request window objects
|
||||
if let (Some((StatusCode::UNAUTHORIZED, _)), false, true) =
|
||||
(response.status.as_ref(), cors_flag, include_credentials)
|
||||
if let (Some(StatusCode::UNAUTHORIZED), false, true) =
|
||||
(response.status.try_code(), cors_flag, include_credentials)
|
||||
{
|
||||
// Substep 1
|
||||
// TODO: Spec says requires testing on multiple WWW-Authenticate headers
|
||||
|
@ -1653,7 +1639,7 @@ async fn http_network_or_cache_fetch(
|
|||
}
|
||||
|
||||
// Step 11
|
||||
if let Some((StatusCode::PROXY_AUTHENTICATION_REQUIRED, _)) = response.status.as_ref() {
|
||||
if response.status == StatusCode::PROXY_AUTHENTICATION_REQUIRED {
|
||||
// Step 1
|
||||
if request_has_no_window {
|
||||
return Response::network_error(NetworkError::Internal(
|
||||
|
@ -1836,15 +1822,15 @@ async fn http_network_fetch(
|
|||
let timing = context.timing.lock().unwrap().clone();
|
||||
let mut response = Response::new(url.clone(), timing);
|
||||
|
||||
response.status = Some((
|
||||
response.status = HttpStatus::new(
|
||||
res.status(),
|
||||
res.status().canonical_reason().unwrap_or("").into(),
|
||||
));
|
||||
res.status()
|
||||
.canonical_reason()
|
||||
.unwrap_or("")
|
||||
.as_bytes()
|
||||
.to_vec(),
|
||||
);
|
||||
info!("got {:?} response for {:?}", res.status(), request.url());
|
||||
response.raw_status = Some((
|
||||
res.status().as_u16(),
|
||||
res.status().canonical_reason().unwrap_or("").into(),
|
||||
));
|
||||
response.headers = res.headers().clone();
|
||||
response.referrer = request.referrer.to_url().cloned();
|
||||
response.referrer_policy = request.referrer_policy;
|
||||
|
@ -2047,12 +2033,7 @@ async fn cors_preflight_fetch(
|
|||
let response =
|
||||
http_network_or_cache_fetch(&mut preflight, false, false, &mut None, context).await;
|
||||
// Step 7
|
||||
if cors_check(request, &response).is_ok() &&
|
||||
response
|
||||
.status
|
||||
.as_ref()
|
||||
.is_some_and(|(status, _)| status.is_success())
|
||||
{
|
||||
if cors_check(request, &response).is_ok() && response.status.code().is_success() {
|
||||
// Substep 1
|
||||
let mut methods = if response
|
||||
.headers
|
||||
|
@ -2231,9 +2212,9 @@ fn is_no_store_cache(headers: &HeaderMap) -> bool {
|
|||
}
|
||||
|
||||
/// <https://fetch.spec.whatwg.org/#redirect-status>
|
||||
pub fn is_redirect_status(status: &(StatusCode, String)) -> bool {
|
||||
pub fn is_redirect_status(status: StatusCode) -> bool {
|
||||
matches!(
|
||||
status.0,
|
||||
status,
|
||||
StatusCode::MOVED_PERMANENTLY |
|
||||
StatusCode::FOUND |
|
||||
StatusCode::SEE_OTHER |
|
||||
|
|
|
@ -6,9 +6,10 @@ use std::future::{ready, Future};
|
|||
use std::pin::Pin;
|
||||
|
||||
use headers::{HeaderMapExt, Range};
|
||||
use http::{Method, StatusCode};
|
||||
use http::Method;
|
||||
use log::debug;
|
||||
use net_traits::blob_url_store::{parse_blob_url, BlobURLStoreError};
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::Request;
|
||||
use net_traits::response::{Response, ResponseBody};
|
||||
use net_traits::{NetworkError, ResourceFetchTiming};
|
||||
|
@ -55,8 +56,7 @@ impl ProtocolHandler for BlobProtocolHander {
|
|||
};
|
||||
|
||||
let mut response = Response::new(url, ResourceFetchTiming::new(request.timing_type()));
|
||||
response.status = Some((StatusCode::OK, "OK".to_string()));
|
||||
response.raw_status = Some((StatusCode::OK.as_u16(), b"OK".to_vec()));
|
||||
response.status = HttpStatus::default();
|
||||
|
||||
if is_range_request {
|
||||
partial_content(&mut response);
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::pin::Pin;
|
|||
|
||||
use data_url::DataUrl;
|
||||
use headers::HeaderValue;
|
||||
use http::StatusCode;
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::Request;
|
||||
use net_traits::response::{Response, ResponseBody};
|
||||
use net_traits::{NetworkError, ResourceFetchTiming};
|
||||
|
@ -40,8 +40,7 @@ impl ProtocolHandler for DataProtocolHander {
|
|||
http::header::CONTENT_TYPE,
|
||||
HeaderValue::from_str(&mime.to_string()).unwrap(),
|
||||
);
|
||||
response.status = Some((StatusCode::OK, "OK".to_string()));
|
||||
response.raw_status = Some((StatusCode::OK.as_u16(), b"OK".to_vec()));
|
||||
response.status = HttpStatus::default();
|
||||
Some(response)
|
||||
},
|
||||
Err(_) => None,
|
||||
|
|
|
@ -102,9 +102,7 @@ impl ProtocolRegistry {
|
|||
}
|
||||
|
||||
pub fn range_not_satisfiable_error(response: &mut Response) {
|
||||
let reason = "Range Not Satisfiable".to_owned();
|
||||
response.status = Some((StatusCode::RANGE_NOT_SATISFIABLE, reason.clone()));
|
||||
response.raw_status = Some((StatusCode::RANGE_NOT_SATISFIABLE.as_u16(), reason.into()));
|
||||
response.status = StatusCode::RANGE_NOT_SATISFIABLE.into();
|
||||
}
|
||||
|
||||
/// Get the range bounds if the `Range` header is present.
|
||||
|
@ -132,7 +130,5 @@ pub fn get_range_request_bounds(range: Option<Range>) -> RangeRequestBounds {
|
|||
}
|
||||
|
||||
pub fn partial_content(response: &mut Response) {
|
||||
let reason = "Partial Content".to_owned();
|
||||
response.status = Some((StatusCode::PARTIAL_CONTENT, reason.clone()));
|
||||
response.raw_status = Some((StatusCode::PARTIAL_CONTENT.as_u16(), reason.into()));
|
||||
response.status = StatusCode::PARTIAL_CONTENT.into();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ use net::protocols::ProtocolRegistry;
|
|||
use net::resource_thread::CoreResourceThreadPool;
|
||||
use net::test::HttpState;
|
||||
use net_traits::filemanager_thread::FileTokenCheck;
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::{
|
||||
Destination, Origin, RedirectMode, Referrer, Request, RequestBuilder, RequestMode,
|
||||
};
|
||||
|
@ -642,7 +643,7 @@ fn test_fetch_response_is_opaque_filtered() {
|
|||
assert!(fetch_response.url().is_none());
|
||||
assert!(fetch_response.url_list.is_empty());
|
||||
// this also asserts that status message is "the empty byte sequence"
|
||||
assert!(fetch_response.status.is_none());
|
||||
assert!(fetch_response.status.is_error());
|
||||
assert_eq!(fetch_response.headers, HeaderMap::new());
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Empty => {},
|
||||
|
@ -694,7 +695,7 @@ fn test_fetch_response_is_opaque_redirect_filtered() {
|
|||
assert_eq!(fetch_response.response_type, ResponseType::OpaqueRedirect);
|
||||
|
||||
// this also asserts that status message is "the empty byte sequence"
|
||||
assert!(fetch_response.status.is_none());
|
||||
assert!(fetch_response.status.is_error());
|
||||
assert_eq!(fetch_response.headers, HeaderMap::new());
|
||||
match *fetch_response.body.lock().unwrap() {
|
||||
ResponseBody::Empty => {},
|
||||
|
@ -855,8 +856,7 @@ fn test_load_adds_host_to_hsts_list_when_url_is_https() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
assert!(context
|
||||
.state
|
||||
|
@ -922,7 +922,7 @@ fn test_fetch_self_signed() {
|
|||
|
||||
let response = fetch_with_context(&mut request, &mut context);
|
||||
|
||||
assert!(response.status.unwrap().0.is_success());
|
||||
assert!(response.status.code().is_success());
|
||||
|
||||
let _ = server.close();
|
||||
}
|
||||
|
@ -1392,7 +1392,7 @@ fn test_fetch_with_devtools() {
|
|||
|
||||
let httpresponse = DevtoolsHttpResponse {
|
||||
headers: Some(response_headers),
|
||||
status: Some((200, b"OK".to_vec())),
|
||||
status: HttpStatus::default(),
|
||||
body: None,
|
||||
pipeline_id: TEST_PIPELINE_ID,
|
||||
};
|
||||
|
|
|
@ -39,7 +39,7 @@ fn test_refreshing_resource_sets_done_chan_the_appropriate_value() {
|
|||
// First, store the 'normal' response.
|
||||
cache.store(&request, &response);
|
||||
// Second, mutate the response into a 304 response, and refresh the stored one.
|
||||
response.status = Some((StatusCode::NOT_MODIFIED, String::from("304")));
|
||||
response.status = StatusCode::NOT_MODIFIED.into();
|
||||
let (send, recv) = unbounded();
|
||||
let mut done_chan = Some((send, recv));
|
||||
let refreshed_response = cache.refresh(&request, response.clone(), &mut done_chan);
|
||||
|
|
|
@ -35,6 +35,7 @@ use net::cookie_storage::CookieStorage;
|
|||
use net::http_loader::determine_requests_referrer;
|
||||
use net::resource_thread::AuthCacheEntry;
|
||||
use net::test::replace_host_table;
|
||||
use net_traits::http_status::HttpStatus;
|
||||
use net_traits::request::{
|
||||
BodyChunkRequest, BodyChunkResponse, BodySource, CredentialsMode, Destination, Referrer,
|
||||
RequestBody, RequestBuilder,
|
||||
|
@ -161,8 +162,7 @@ fn test_check_default_headers_loaded_in_every_request() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
// Testing for method.POST
|
||||
|
@ -188,8 +188,7 @@ fn test_check_default_headers_loaded_in_every_request() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
let _ = server.close();
|
||||
|
@ -219,8 +218,7 @@ fn test_load_when_request_is_not_get_or_head_and_there_is_no_body_content_length
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
let _ = server.close();
|
||||
|
@ -253,8 +251,7 @@ fn test_request_and_response_data_with_network_messages() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
let _ = server.close();
|
||||
|
@ -312,7 +309,7 @@ fn test_request_and_response_data_with_network_messages() {
|
|||
|
||||
let httpresponse = DevtoolsHttpResponse {
|
||||
headers: Some(response_headers),
|
||||
status: Some((200, b"OK".to_vec())),
|
||||
status: HttpStatus::default(),
|
||||
body: None,
|
||||
pipeline_id: TEST_PIPELINE_ID,
|
||||
};
|
||||
|
@ -341,13 +338,7 @@ fn test_request_and_response_message_from_devtool_without_pipeline_id() {
|
|||
|
||||
let (devtools_chan, devtools_port) = unbounded();
|
||||
let response = fetch(&mut request, Some(devtools_chan));
|
||||
assert!(response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.0
|
||||
.is_success());
|
||||
assert!(response.actual_response().status.code().is_success());
|
||||
|
||||
let _ = server.close();
|
||||
|
||||
|
@ -393,7 +384,7 @@ fn test_redirected_request_to_devtools() {
|
|||
assert_eq!(devhttprequest.url, pre_url);
|
||||
assert_eq!(
|
||||
devhttpresponse.status,
|
||||
Some((301, b"Moved Permanently".to_vec()))
|
||||
HttpStatus::from(StatusCode::MOVED_PERMANENTLY)
|
||||
);
|
||||
|
||||
let devhttprequest = expect_devtools_http_request(&devtools_port);
|
||||
|
@ -401,7 +392,7 @@ fn test_redirected_request_to_devtools() {
|
|||
|
||||
assert_eq!(devhttprequest.method, Method::GET);
|
||||
assert_eq!(devhttprequest.url, post_url);
|
||||
assert_eq!(devhttpresponse.status, Some((200, b"OK".to_vec())));
|
||||
assert_eq!(devhttpresponse.status, HttpStatus::default());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -435,7 +426,7 @@ fn test_load_when_redirecting_from_a_post_should_rewrite_next_request_as_get() {
|
|||
let _ = pre_server.close();
|
||||
let _ = post_server.close();
|
||||
|
||||
assert!(response.to_actual().status.unwrap().0.is_success());
|
||||
assert!(response.to_actual().status.code().is_success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -466,7 +457,7 @@ fn test_load_should_decode_the_response_as_deflate_when_response_headers_have_co
|
|||
let _ = server.close();
|
||||
|
||||
let internal_response = response.internal_response.unwrap();
|
||||
assert!(internal_response.status.clone().unwrap().0.is_success());
|
||||
assert!(internal_response.status.clone().code().is_success());
|
||||
assert_eq!(
|
||||
*internal_response.body.lock().unwrap(),
|
||||
ResponseBody::Done(b"Yay!".to_vec())
|
||||
|
@ -499,7 +490,7 @@ fn test_load_should_decode_the_response_as_gzip_when_response_headers_have_conte
|
|||
let _ = server.close();
|
||||
|
||||
let internal_response = response.internal_response.unwrap();
|
||||
assert!(internal_response.status.clone().unwrap().0.is_success());
|
||||
assert!(internal_response.status.clone().code().is_success());
|
||||
assert_eq!(
|
||||
*internal_response.body.lock().unwrap(),
|
||||
ResponseBody::Done(b"Yay!".to_vec())
|
||||
|
@ -544,7 +535,7 @@ fn test_load_doesnt_send_request_body_on_any_redirect() {
|
|||
let _ = pre_server.close();
|
||||
let _ = post_server.close();
|
||||
|
||||
assert!(response.to_actual().status.unwrap().0.is_success());
|
||||
assert!(response.to_actual().status.code().is_success());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -576,8 +567,7 @@ fn test_load_doesnt_add_host_to_hsts_list_when_url_is_http_even_if_hsts_headers_
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
assert_eq!(
|
||||
context
|
||||
|
@ -622,8 +612,7 @@ fn test_load_sets_cookies_in_the_resource_manager_when_it_get_set_cookie_header_
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
assert_cookie_for_domain(
|
||||
|
@ -674,8 +663,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -720,8 +708,7 @@ fn test_load_sends_cookie_if_nonhttp() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -758,8 +745,7 @@ fn test_cookie_set_with_httponly_should_not_be_available_using_getcookiesforurl(
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
|
||||
assert_cookie_for_domain(
|
||||
|
@ -802,13 +788,7 @@ fn test_when_cookie_received_marked_secure_is_ignored_for_http() {
|
|||
|
||||
let _ = server.close();
|
||||
|
||||
assert!(response
|
||||
.actual_response()
|
||||
.status
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.0
|
||||
.is_success());
|
||||
assert!(response.actual_response().status.code().is_success());
|
||||
|
||||
assert_cookie_for_domain(&context.state.cookie_jar, url.as_str(), None);
|
||||
}
|
||||
|
@ -844,8 +824,7 @@ fn test_load_sets_content_length_to_length_of_request_body() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -883,8 +862,7 @@ fn test_load_uses_explicit_accept_from_headers_in_load_data() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -919,8 +897,7 @@ fn test_load_sets_default_accept_to_html_xhtml_xml_and_then_anything_else() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -958,8 +935,7 @@ fn test_load_uses_explicit_accept_encoding_from_load_data_headers() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -994,8 +970,7 @@ fn test_load_sets_default_accept_encoding_to_gzip_and_deflate() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -1140,7 +1115,7 @@ fn test_load_follows_a_redirect() {
|
|||
let _ = post_server.close();
|
||||
|
||||
let internal_response = response.internal_response.unwrap();
|
||||
assert!(internal_response.status.clone().unwrap().0.is_success());
|
||||
assert!(internal_response.status.clone().code().is_success());
|
||||
assert_eq!(
|
||||
*internal_response.body.lock().unwrap(),
|
||||
ResponseBody::Done(b"Yay!".to_vec())
|
||||
|
@ -1223,7 +1198,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
|
|||
let _ = server.close();
|
||||
|
||||
let internal_response = response.internal_response.unwrap();
|
||||
assert!(internal_response.status.clone().unwrap().0.is_success());
|
||||
assert!(internal_response.status.clone().code().is_success());
|
||||
assert_eq!(
|
||||
*internal_response.body.lock().unwrap(),
|
||||
ResponseBody::Done(b"Yay!".to_vec())
|
||||
|
@ -1272,7 +1247,7 @@ fn test_redirect_from_x_to_x_provides_x_with_cookie_from_first_response() {
|
|||
let _ = server.close();
|
||||
|
||||
let internal_response = response.internal_response.unwrap();
|
||||
assert!(internal_response.status.clone().unwrap().0.is_success());
|
||||
assert!(internal_response.status.clone().code().is_success());
|
||||
assert_eq!(
|
||||
*internal_response.body.lock().unwrap(),
|
||||
ResponseBody::Done(b"Yay!".to_vec())
|
||||
|
@ -1322,8 +1297,7 @@ fn test_if_auth_creds_not_in_url_but_in_cache_it_sets_it() {
|
|||
.internal_response
|
||||
.unwrap()
|
||||
.status
|
||||
.unwrap()
|
||||
.0
|
||||
.code()
|
||||
.is_success());
|
||||
}
|
||||
|
||||
|
@ -1348,7 +1322,7 @@ fn test_auth_ui_needs_www_auth() {
|
|||
let _ = server.close();
|
||||
|
||||
assert_eq!(
|
||||
response.internal_response.unwrap().status.unwrap().0,
|
||||
response.internal_response.unwrap().status,
|
||||
StatusCode::UNAUTHORIZED
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue