Skip to content

Commit

Permalink
Use RequestBuilder for CORS preflight fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
CYBAI committed Oct 9, 2019
1 parent 9c3e4a7 commit f771e5f
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions components/net/http_loader.rs
Expand Up @@ -39,7 +39,7 @@ use msg::constellation_msg::{HistoryStateId, PipelineId};
use net_traits::quality::{quality_to_value, Quality, QualityItem};
use net_traits::request::Origin::Origin as SpecificOrigin;
use net_traits::request::{CacheMode, CredentialsMode, Destination, Origin};
use net_traits::request::{RedirectMode, Referrer, Request, RequestMode};
use net_traits::request::{RedirectMode, Referrer, Request, RequestBuilder, RequestMode};
use net_traits::request::{ResponseTainting, ServiceWorkersMode};
use net_traits::response::{HttpsState, Response, ResponseBody, ResponseType};
use net_traits::{CookieSource, FetchMetadata, NetworkError, ReferrerPolicy};
Expand Down Expand Up @@ -1606,17 +1606,20 @@ fn cors_preflight_fetch(
context: &FetchContext,
) -> Response {
// Step 1
let mut preflight = Request::new(
request.current_url(),
Some(request.origin.clone()),
request.pipeline_id,
);
preflight.method = Method::OPTIONS;
preflight.initiator = request.initiator.clone();
preflight.destination = request.destination.clone();
preflight.origin = request.origin.clone();
preflight.referrer = request.referrer.clone();
preflight.referrer_policy = request.referrer_policy;
let mut preflight = RequestBuilder::new(request.current_url())
.method(Method::OPTIONS)
.origin(match &request.origin {
Origin::Client => {
unreachable!("We shouldn't get Client origin in cors_preflight_fetch.")
},
Origin::Origin(origin) => origin.clone(),
})
.pipeline_id(request.pipeline_id)
.initiator(request.initiator.clone())
.destination(request.destination.clone())
.referrer(Some(request.referrer.clone()))
.referrer_policy(request.referrer_policy)
.build();

// Step 2
preflight
Expand Down

0 comments on commit f771e5f

Please sign in to comment.