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

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

Issue 1301523002: [Fetch API] Send request body as a FormData. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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 | Annotate | Revision Log
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 "config.h" 5 #include "config.h"
6 #include "modules/fetch/Request.h" 6 #include "modules/fetch/Request.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.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 29 matching lines...) Expand all
40 request->setSameOriginDataURLFlag(true); 40 request->setSameOriginDataURLFlag(true);
41 request->mutableReferrer()->setClient(); 41 request->mutableReferrer()->setClient();
42 request->setMode(original->mode()); 42 request->setMode(original->mode());
43 request->setCredentials(original->credentials()); 43 request->setCredentials(original->credentials());
44 request->setRedirect(original->redirect()); 44 request->setRedirect(original->redirect());
45 // FIXME: Set cache mode. 45 // FIXME: Set cache mode.
46 // TODO(yhirano): Set redirect mode. 46 // TODO(yhirano): Set redirect mode.
47 return request; 47 return request;
48 } 48 }
49 49
50 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, const RequestInit& init, Exceptio nState& exceptionState) 50 Request* Request::createRequestWithRequestOrString(ScriptState* scriptState, Req uest* inputRequest, const String& inputString, RequestInit& init, ExceptionState & exceptionState)
51 { 51 {
52 // "1. Let |temporaryBody| be null." 52 // "1. Let |temporaryBody| be null."
53 BodyStreamBuffer* temporaryBody = nullptr; 53 BodyStreamBuffer* temporaryBody = nullptr;
54 54
55 if (inputRequest) { 55 if (inputRequest) {
56 // We check bodyUsed even when the body is null in spite of the 56 // We check bodyUsed even when the body is null in spite of the
57 // spec. See https://github.com/whatwg/fetch/issues/61 for details. 57 // spec. See https://github.com/whatwg/fetch/issues/61 for details.
58 if (inputRequest->bodyUsed()) { 58 if (inputRequest->bodyUsed()) {
59 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used."); 59 exceptionState.throwTypeError("Cannot construct a Request with a Req uest object that has already been used.");
60 return nullptr; 60 return nullptr;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 r->headers()->fillWith(init.headersDictionary, exceptionState); 212 r->headers()->fillWith(init.headersDictionary, exceptionState);
213 } else { 213 } else {
214 ASSERT(headers); 214 ASSERT(headers);
215 r->headers()->fillWith(headers, exceptionState); 215 r->headers()->fillWith(headers, exceptionState);
216 } 216 }
217 if (exceptionState.hadException()) 217 if (exceptionState.hadException())
218 return nullptr; 218 return nullptr;
219 219
220 // "31. If either |init|'s body member is present or |temporaryBody| is 220 // "31. If either |init|'s body member is present or |temporaryBody| is
221 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError. 221 // non-null, and |request|'s method is `GET` or `HEAD`, throw a TypeError.
222 if (init.bodyBlobHandle || temporaryBody) { 222 if (init.body || temporaryBody) {
223 if (request->method() == "GET" || request->method() == "HEAD") { 223 if (request->method() == "GET" || request->method() == "HEAD") {
224 exceptionState.throwTypeError("Request with GET/HEAD method cannot h ave body."); 224 exceptionState.throwTypeError("Request with GET/HEAD method cannot h ave body.");
225 return nullptr; 225 return nullptr;
226 } 226 }
227 } 227 }
228 228
229 // "32. If |init|'s body member is present, run these substeps:" 229 // "32. If |init|'s body member is present, run these substeps:"
230 if (init.bodyBlobHandle) { 230 if (init.body) {
231 // "1. Let |stream| and |Content-Type| be the result of extracting 231 // "1. Let |stream| and |Content-Type| be the result of extracting
232 // |init|'s body member." 232 // |init|'s body member."
233 // "2. Set |temporaryBody| to |stream|. 233 // "2. Set |temporaryBody| to |stream|.
234 // "3. If |Content-Type| is non-null and |r|'s request's header list 234 // "3. If |Content-Type| is non-null and |r|'s request's header list
235 // contains no header named `Content-Type`, append 235 // contains no header named `Content-Type`, append
236 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any 236 // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any
237 // exception." 237 // exception."
238 temporaryBody = new BodyStreamBuffer(FetchBlobDataConsumerHandle::create (scriptState->executionContext(), init.bodyBlobHandle)); 238 temporaryBody = new BodyStreamBuffer(init.body.release());
239 if (!init.bodyBlobHandle->type().isEmpty() && !r->headers()->has("Conten t-Type", exceptionState)) { 239 if (!init.contentType.isEmpty() && !r->headers()->has("Content-Type", ex ceptionState)) {
240 r->headers()->append("Content-Type", init.bodyBlobHandle->type(), ex ceptionState); 240 r->headers()->append("Content-Type", init.contentType, exceptionStat e);
241 } 241 }
242 if (exceptionState.hadException()) 242 if (exceptionState.hadException())
243 return nullptr; 243 return nullptr;
244 } 244 }
245 245
246 // "33. Set |r|'s body to |temporaryBody|. 246 // "33. Set |r|'s body to |temporaryBody|.
247 if (temporaryBody) 247 if (temporaryBody)
248 r->m_request->setBuffer(temporaryBody); 248 r->m_request->setBuffer(temporaryBody);
249 249
250 // "34. Set |r|'s MIME type to the result of extracting a MIME type from 250 // "34. Set |r|'s MIME type to the result of extracting a MIME type from
(...skipping 23 matching lines...) Expand all
274 return create(scriptState, input.getAsRequest(), init, exceptionState); 274 return create(scriptState, input.getAsRequest(), init, exceptionState);
275 } 275 }
276 276
277 Request* Request::create(ScriptState* scriptState, const String& input, Exceptio nState& exceptionState) 277 Request* Request::create(ScriptState* scriptState, const String& input, Exceptio nState& exceptionState)
278 { 278 {
279 return create(scriptState, input, Dictionary(), exceptionState); 279 return create(scriptState, input, Dictionary(), exceptionState);
280 } 280 }
281 281
282 Request* Request::create(ScriptState* scriptState, const String& input, const Di ctionary& init, ExceptionState& exceptionState) 282 Request* Request::create(ScriptState* scriptState, const String& input, const Di ctionary& init, ExceptionState& exceptionState)
283 { 283 {
284 return createRequestWithRequestOrString(scriptState, nullptr, input, Request Init(scriptState->executionContext(), init, exceptionState), exceptionState); 284 RequestInit requestInit(scriptState->executionContext(), init, exceptionStat e);
285 return createRequestWithRequestOrString(scriptState, nullptr, input, request Init, exceptionState);
285 } 286 }
286 287
287 Request* Request::create(ScriptState* scriptState, Request* input, ExceptionStat e& exceptionState) 288 Request* Request::create(ScriptState* scriptState, Request* input, ExceptionStat e& exceptionState)
288 { 289 {
289 return create(scriptState, input, Dictionary(), exceptionState); 290 return create(scriptState, input, Dictionary(), exceptionState);
290 } 291 }
291 292
292 Request* Request::create(ScriptState* scriptState, Request* input, const Diction ary& init, ExceptionState& exceptionState) 293 Request* Request::create(ScriptState* scriptState, Request* input, const Diction ary& init, ExceptionState& exceptionState)
293 { 294 {
294 return createRequestWithRequestOrString(scriptState, input, String(), Reques tInit(scriptState->executionContext(), init, exceptionState), exceptionState); 295 RequestInit requestInit(scriptState->executionContext(), init, exceptionStat e);
296 return createRequestWithRequestOrString(scriptState, input, String(), reques tInit, exceptionState);
295 } 297 }
296 298
297 Request* Request::create(ExecutionContext* context, FetchRequestData* request) 299 Request* Request::create(ExecutionContext* context, FetchRequestData* request)
298 { 300 {
299 return new Request(context, request); 301 return new Request(context, request);
300 } 302 }
301 303
302 Request::Request(ExecutionContext* context, FetchRequestData* request) 304 Request::Request(ExecutionContext* context, FetchRequestData* request)
303 : Body(context) 305 : Body(context)
304 , m_request(request) 306 , m_request(request)
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 } 529 }
528 530
529 DEFINE_TRACE(Request) 531 DEFINE_TRACE(Request)
530 { 532 {
531 Body::trace(visitor); 533 Body::trace(visitor);
532 visitor->trace(m_request); 534 visitor->trace(m_request);
533 visitor->trace(m_headers); 535 visitor->trace(m_headers);
534 } 536 }
535 537
536 } // namespace blink 538 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698