mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Auto merge of #23860 - CYBAI:request-builder, r=KiChjang
Use RequestBuilder for CORS preflight fetch Just found this can be improved with the request builder! --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes do not require tests because just move to builder pattern <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/23860) <!-- Reviewable:end -->
This commit is contained in:
commit
bb17427526
1 changed files with 15 additions and 12 deletions
|
@ -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};
|
||||
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue