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

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

Issue 1862293003: Fetch: Fix 'body' processing in RequestInit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/RequestInit.h" 5 #include "modules/fetch/RequestInit.h"
6 6
7 #include "bindings/core/v8/Dictionary.h" 7 #include "bindings/core/v8/Dictionary.h"
8 #include "bindings/core/v8/V8ArrayBuffer.h" 8 #include "bindings/core/v8/V8ArrayBuffer.h"
9 #include "bindings/core/v8/V8ArrayBufferView.h" 9 #include "bindings/core/v8/V8ArrayBufferView.h"
10 #include "bindings/core/v8/V8Binding.h" 10 #include "bindings/core/v8/V8Binding.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 // painful. There should be no developer-visible difference in behav ior with this option, 75 // painful. There should be no developer-visible difference in behav ior with this option,
76 // except that the `Content-Type` header will be set early. That see ms reasonable. 76 // except that the `Content-Type` header will be set early. That see ms reasonable.
77 PasswordCredential* credential = V8PasswordCredential::toImpl(v8::Lo cal<v8::Object>::Cast(v8Credential)); 77 PasswordCredential* credential = V8PasswordCredential::toImpl(v8::Lo cal<v8::Object>::Cast(v8Credential));
78 attachedCredential = credential->encodeFormData(contentType); 78 attachedCredential = credential->encodeFormData(contentType);
79 credentials = "password"; 79 credentials = "password";
80 } else if (v8Credential->IsString()) { 80 } else if (v8Credential->IsString()) {
81 credentials = toUSVString(isolate, v8Credential, exceptionState); 81 credentials = toUSVString(isolate, v8Credential, exceptionState);
82 } 82 }
83 } 83 }
84 84
85 if (isCredentialSet || !isBodySet || v8Body->IsUndefined() || v8Body->IsNull ()) 85 if (attachedCredential.get() || !isBodySet || v8Body->IsUndefined() || v8Bod y->IsNull())
86 return; 86 return;
87 87
88 if (v8Body->IsArrayBuffer()) { 88 if (v8Body->IsArrayBuffer()) {
89 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc al<v8::Object>::Cast(v8Body))); 89 body = FetchFormDataConsumerHandle::create(V8ArrayBuffer::toImpl(v8::Loc al<v8::Object>::Cast(v8Body)));
90 } else if (v8Body->IsArrayBufferView()) { 90 } else if (v8Body->IsArrayBufferView()) {
91 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8: :Local<v8::Object>::Cast(v8Body))); 91 body = FetchFormDataConsumerHandle::create(V8ArrayBufferView::toImpl(v8: :Local<v8::Object>::Cast(v8Body)));
92 } else if (V8Blob::hasInstance(v8Body, isolate)) { 92 } else if (V8Blob::hasInstance(v8Body, isolate)) {
93 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj ect>::Cast(v8Body))->blobDataHandle(); 93 RefPtr<BlobDataHandle> blobDataHandle = V8Blob::toImpl(v8::Local<v8::Obj ect>::Cast(v8Body))->blobDataHandle();
94 contentType = blobDataHandle->type(); 94 contentType = blobDataHandle->type();
95 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea se()); 95 body = FetchBlobDataConsumerHandle::create(context, blobDataHandle.relea se());
96 } else if (V8FormData::hasInstance(v8Body, isolate)) { 96 } else if (V8FormData::hasInstance(v8Body, isolate)) {
97 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje ct>::Cast(v8Body))->encodeMultiPartFormData(); 97 RefPtr<EncodedFormData> formData = V8FormData::toImpl(v8::Local<v8::Obje ct>::Cast(v8Body))->encodeMultiPartFormData();
98 // Here we handle formData->boundary() as a C-style string. See 98 // Here we handle formData->boundary() as a C-style string. See
99 // FormDataEncoder::generateUniqueBoundaryString. 99 // FormDataEncoder::generateUniqueBoundaryString.
100 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data(); 100 contentType = AtomicString("multipart/form-data; boundary=") + formData- >boundary().data();
101 body = FetchFormDataConsumerHandle::create(context, formData.release()); 101 body = FetchFormDataConsumerHandle::create(context, formData.release());
102 } else if (V8URLSearchParams::hasInstance(v8Body, isolate)) { 102 } else if (V8URLSearchParams::hasInstance(v8Body, isolate)) {
103 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData(); 103 RefPtr<EncodedFormData> formData = V8URLSearchParams::toImpl(v8::Local<v 8::Object>::Cast(v8Body))->encodeFormData();
104 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8"); 104 contentType = AtomicString("application/x-www-form-urlencoded;charset=UT F-8");
105 body = FetchFormDataConsumerHandle::create(context, formData.release()); 105 body = FetchFormDataConsumerHandle::create(context, formData.release());
106 } else if (v8Body->IsString()) { 106 } else if (v8Body->IsString()) {
107 contentType = "text/plain;charset=UTF-8"; 107 contentType = "text/plain;charset=UTF-8";
108 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState)); 108 body = FetchFormDataConsumerHandle::create(toUSVString(isolate, v8Body, exceptionState));
109 } 109 }
110 } 110 }
111 111
112 } // namespace blink 112 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/http/tests/fetch/script-tests/request.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698