aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-10-09 06:28:32 -0400
committerGitHub <noreply@github.com>2019-10-09 06:28:32 -0400
commitbb174275264e48ea91ce85f28829d465e61084bd (patch)
treed50a93f1b8830e27fdb9599ccf213066d6dcc7bd
parentec408e9a571f7be9d8630c06add7f528a3199e47 (diff)
parentf771e5f371b6f7babd91300e16c614e410cd60a3 (diff)
downloadservo-bb174275264e48ea91ce85f28829d465e61084bd.tar.gz
servo-bb174275264e48ea91ce85f28829d465e61084bd.zip
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 -->
-rw-r--r--components/net/http_loader.rs27
1 files changed, 15 insertions, 12 deletions
diff --git a/components/net/http_loader.rs b/components/net/http_loader.rs
index f2158bb4aee..a451fde1fbc 100644
--- a/components/net/http_loader.rs
+++ b/components/net/http_loader.rs
@@ -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