Index: Source/modules/fetch/Response.cpp |
diff --git a/Source/modules/fetch/Response.cpp b/Source/modules/fetch/Response.cpp |
index 29c7c0de34933f6a711117f2692aea6a6a8abcba..c1d1eb9202512ab1884186caded8d9c057041bd1 100644 |
--- a/Source/modules/fetch/Response.cpp |
+++ b/Source/modules/fetch/Response.cpp |
@@ -19,6 +19,16 @@ |
#include "public/platform/WebServiceWorkerResponse.h" |
#include "wtf/RefPtr.h" |
+// Check whether |status| is a null body status |
hiroshige
2015/07/30 11:20:40
nit: s/Check/Checks/, and append a period at the l
|
+// Spec: https://fetch.spec.whatwg.org/#statuses |
hiroshige
2015/07/30 11:20:40
nit: https://fetch.spec.whatwg.org/#null-body-stat
shiva.jm
2015/07/30 11:47:16
Done.
|
+bool isNullBodyStatus(unsigned short status) |
+{ |
+ if (status == 101 || status == 204 || status == 205 || status == 304) |
+ return true; |
+ |
+ return false; |
+} |
+ |
namespace blink { |
namespace { |
@@ -153,9 +163,11 @@ Response* Response::create(ExecutionContext* context, const BodyInit& body, cons |
Response* Response::create(ExecutionContext* context, Blob* body, const ResponseInit& responseInit, ExceptionState& exceptionState) |
{ |
- // "1. If |init|'s status member is not in the range 200 to 599, throw a |
+ unsigned short status = responseInit.status; |
+ |
+ // "1. If |init|'s status member is not in the range 200 to 599, inclusive, throw a |
// RangeError." |
- if (responseInit.status < 200 || 599 < responseInit.status) { |
+ if (status < 200 || 599 < status) { |
exceptionState.throwRangeError("Invalid status"); |
hiroshige
2015/07/30 11:20:40
How about applying this?
https://codereview.chromi
shiva.jm
2015/07/30 11:47:16
Done.
|
return 0; |
} |
@@ -198,15 +210,20 @@ Response* Response::create(ExecutionContext* context, Blob* body, const Response |
} |
// "7. If body is given, run these substeps:" |
if (body) { |
- // "1. Let |stream| and |Content-Type| be the result of extracting body." |
- // "2. Set |r|'s response's body to |stream|." |
- // "3. If |Content-Type| is non-null and |r|'s response's header list |
+ // "1. If |init|'s status member is a null body status, throw a TypeError." |
+ // "2. Let |stream| and |Content-Type| be the result of extracting body." |
+ // "3. Set |r|'s response's body to |stream|." |
+ // "4. If |Content-Type| is non-null and |r|'s response's header list |
// contains no header named `Content-Type`, append `Content-Type`/ |
// |Content-Type| to |r|'s response's header list." |
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract |
// Step 3, Blob: |
// "If object's type attribute is not the empty byte sequence, set |
// Content-Type to its value." |
+ if (isNullBodyStatus(status)) { |
+ exceptionState.throwTypeError("Response with null body status cannot have body"); |
+ return 0; |
+ } |
r->m_response->replaceBodyStreamBuffer(BodyStreamBuffer::create(FetchBlobDataConsumerHandle::create(context, body->blobDataHandle()))); |
r->refreshBody(); |
if (!body->type().isEmpty() && !r->m_response->headerList()->has("Content-Type")) |