Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: third_party/WebKit/Source/modules/fetch/Request.cpp

Issue 2840193002: fetch: Align RequestInit's |headers| with the spec. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/fetch/Request.h" 5 #include "modules/fetch/Request.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/V8PrivateProperty.h" 8 #include "bindings/core/v8/V8PrivateProperty.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/ExecutionContext.h" 10 #include "core/dom/ExecutionContext.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // Headers object whose guard is "request"." 313 // Headers object whose guard is "request"."
314 Request* r = Request::Create(script_state, request); 314 Request* r = Request::Create(script_state, request);
315 // Perform the following steps: 315 // Perform the following steps:
316 // - "Let |headers| be a copy of |r|'s Headers object." 316 // - "Let |headers| be a copy of |r|'s Headers object."
317 // - "If |init|'s headers member is present, set |headers| to |init|'s 317 // - "If |init|'s headers member is present, set |headers| to |init|'s
318 // headers member." 318 // headers member."
319 // 319 //
320 // We don't create a copy of r's Headers object when init's headers member 320 // We don't create a copy of r's Headers object when init's headers member
321 // is present. 321 // is present.
322 Headers* headers = nullptr; 322 Headers* headers = nullptr;
323 if (!init.headers) { 323 if (init.headers.isNull()) {
324 headers = r->getHeaders()->Clone(); 324 headers = r->getHeaders()->Clone();
325 } 325 }
326 // "Empty |r|'s request's header list." 326 // "Empty |r|'s request's header list."
327 r->request_->HeaderList()->ClearList(); 327 r->request_->HeaderList()->ClearList();
328 // "If |r|'s request's mode is "no-cors", run these substeps: 328 // "If |r|'s request's mode is "no-cors", run these substeps:
329 if (r->GetRequest()->Mode() == WebURLRequest::kFetchRequestModeNoCORS) { 329 if (r->GetRequest()->Mode() == WebURLRequest::kFetchRequestModeNoCORS) {
330 // "If |r|'s request's method is not a simple method, throw a 330 // "If |r|'s request's method is not a simple method, throw a
331 // TypeError." 331 // TypeError."
332 if (!FetchUtils::IsSimpleMethod(r->GetRequest()->Method())) { 332 if (!FetchUtils::IsSimpleMethod(r->GetRequest()->Method())) {
333 exception_state.ThrowTypeError("'" + r->GetRequest()->Method() + 333 exception_state.ThrowTypeError("'" + r->GetRequest()->Method() +
334 "' is unsupported in no-cors mode."); 334 "' is unsupported in no-cors mode.");
335 return nullptr; 335 return nullptr;
336 } 336 }
337 // "If |request|'s integrity metadata is not the empty string, throw a 337 // "If |request|'s integrity metadata is not the empty string, throw a
338 // TypeError." 338 // TypeError."
339 if (!request->Integrity().IsEmpty()) { 339 if (!request->Integrity().IsEmpty()) {
340 exception_state.ThrowTypeError( 340 exception_state.ThrowTypeError(
341 "The integrity attribute is unsupported in no-cors mode."); 341 "The integrity attribute is unsupported in no-cors mode.");
342 return nullptr; 342 return nullptr;
343 } 343 }
344 // "Set |r|'s Headers object's guard to "request-no-cors"." 344 // "Set |r|'s Headers object's guard to "request-no-cors"."
345 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard); 345 r->getHeaders()->SetGuard(Headers::kRequestNoCORSGuard);
346 } 346 }
347 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions." 347 // "Fill |r|'s Headers object with |headers|. Rethrow any exceptions."
348 if (init.headers) { 348 if (!init.headers.isNull()) {
349 r->getHeaders()->FillWith(init.headers.Get(), exception_state); 349 r->getHeaders()->FillWith(init.headers, exception_state);
350 } else { 350 } else {
351 DCHECK(headers); 351 DCHECK(headers);
352 r->getHeaders()->FillWith(headers, exception_state); 352 r->getHeaders()->FillWith(headers, exception_state);
353 } 353 }
354 if (exception_state.HadException()) 354 if (exception_state.HadException())
355 return nullptr; 355 return nullptr;
356 356
357 // "If either |init|'s body member is present or |temporaryBody| is 357 // "If either |init|'s body member is present or |temporaryBody| is
358 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. 358 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError.
359 if (init.body || temporary_body || 359 if (init.body || temporary_body ||
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 .Set(request.As<v8::Object>(), body_buffer); 763 .Set(request.As<v8::Object>(), body_buffer);
764 } 764 }
765 765
766 DEFINE_TRACE(Request) { 766 DEFINE_TRACE(Request) {
767 Body::Trace(visitor); 767 Body::Trace(visitor);
768 visitor->Trace(request_); 768 visitor->Trace(request_);
769 visitor->Trace(headers_); 769 visitor->Trace(headers_);
770 } 770 }
771 771
772 } // namespace blink 772 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698