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

Unified Diff: Source/modules/serviceworkers/Request.cpp

Issue 516603004: [ServiceWorker] Support setting body to Request object in ServiceWorker. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: incorporated yhirano's comment Created 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/modules/serviceworkers/Request.cpp
diff --git a/Source/modules/serviceworkers/Request.cpp b/Source/modules/serviceworkers/Request.cpp
index 835617bc59f83e6a0c5619fdd0ba50d7b1c7f626..e16d2e4e6e29bcf323ff760214597cad00b7c1bd 100644
--- a/Source/modules/serviceworkers/Request.cpp
+++ b/Source/modules/serviceworkers/Request.cpp
@@ -112,8 +112,27 @@ PassRefPtrWillBeRawPtr<Request> createRequestWithRequestData(PassRefPtrWillBeRaw
}
if (exceptionState.hadException())
return nullptr;
- // FIXME: Support body.
- // "20. Return |r|."
+ // "17. If |init|'s body member is present, run these substeps:"
+ if (init.bodyBlobHandle) {
+ // "1. Let |stream| and |Content-Type| be the result of extracting
+ // |init|'s body member."
+ // "2. Set |r|'s request's body to |stream|."
+ // "3.If |Content-Type| is non-null and |r|'s request's header list
+ // contains no header named `Content-Type`, append
+ // `Content-Type`/|Content-Type| to |r|'s Headers object. Rethrow any
+ // exception."
+ r->setBodyBlobHandle(init.bodyBlobHandle);
+ if (!init.bodyBlobHandle->type().isEmpty() && !r->headers()->has("Content-Type", exceptionState)) {
+ r->headers()->append("Content-Type", init.bodyBlobHandle->type(), exceptionState);
+ }
+ if (exceptionState.hadException())
+ return nullptr;
+ }
+ // "18. Set |r|'s FetchBodyStream object's MIME type to the result of
+ // extracting a MIME type from |r|'s request's header list."
+ // FIXME: We don't have MIME type in FetchBodyStream object yet.
+
+ // "19. Return |r|."
return r.release();
}
@@ -147,7 +166,7 @@ PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, const
request->setURL(parsedURL);
// "4. Set |fallbackMode| to CORS."
// "5. Set |fallbackCredentials| to omit."
- return createRequestWithRequestData(request.release(), RequestInit(init), FetchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState);
+ return createRequestWithRequestData(request.release(), RequestInit(context, init, exceptionState), FetchRequestData::CORSMode, FetchRequestData::OmitCredentials, exceptionState);
}
PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Request* input, ExceptionState& exceptionState)
@@ -167,7 +186,7 @@ PassRefPtrWillBeRawPtr<Request> Request::create(ExecutionContext* context, Reque
// mode and credentials; it has the same effect.
const FetchRequestData::Mode currentMode = request->mode();
const FetchRequestData::Credentials currentCredentials = request->credentials();
- return createRequestWithRequestData(request.release(), RequestInit(init), currentMode, currentCredentials, exceptionState);
+ return createRequestWithRequestData(request.release(), RequestInit(context, init, exceptionState), currentMode, currentCredentials, exceptionState);
}
PassRefPtrWillBeRawPtr<Request> Request::create(PassRefPtrWillBeRawPtr<FetchRequestData> request)
@@ -264,6 +283,11 @@ String Request::credentials() const
return "";
}
+void Request::setBodyBlobHandle(PassRefPtr<BlobDataHandle>blobHandle)
+{
+ m_request->setBlobDataHandle(blobHandle);
+}
+
void Request::trace(Visitor* visitor)
{
visitor->trace(m_request);

Powered by Google App Engine
This is Rietveld 408576698