Index: Source/modules/fetch/Response.cpp |
diff --git a/Source/modules/fetch/Response.cpp b/Source/modules/fetch/Response.cpp |
index 29c7c0de34933f6a711117f2692aea6a6a8abcba..cc17997eea69b2a60d9b88d8ea6ea5edb24e117c 100644 |
--- a/Source/modules/fetch/Response.cpp |
+++ b/Source/modules/fetch/Response.cpp |
@@ -153,32 +153,42 @@ Response* Response::create(ExecutionContext* context, const BodyInit& body, cons |
Response* Response::create(ExecutionContext* context, Blob* body, const ResponseInit& responseInit, ExceptionState& exceptionState) |
{ |
+ unsigned short status = responseInit.status; |
+ |
// "1. If |init|'s status member is not in the range 200 to 599, throw a |
// RangeError." |
- if (responseInit.status < 200 || 599 < responseInit.status) { |
- exceptionState.throwRangeError("Invalid status"); |
+ if (status < 200 || 599 < status) { |
+ exceptionState.throwRangeError(ExceptionMessages::indexOutsideRange<unsigned>("status", status, 200, ExceptionMessages::InclusiveBound, 599, ExceptionMessages::InclusiveBound)); |
+ return 0; |
+ } |
+ |
+ // "2. If init's status member is a null body status and body is non-null, |
+ // throw a TypeError. A null body status is 101, 204, 205, or 304, |
+ // spec link, See https://github.com/whatwg/fetch/issues/86 for details |
philipj_slow
2015/07/28 09:52:51
The issue link is already in the description. I me
shiva.jm
2015/07/29 04:13:00
Done.
shiva.jm
2015/07/29 04:13:00
Done.
|
+ if ((status == 101 || status == 204 || status == 205 || status == 304) && body) { |
+ exceptionState.throwTypeError("Response with null body status cannot have body"); |
return 0; |
} |
- // "2. If |init|'s statusText member does not match the Reason-Phrase |
+ // "3. If |init|'s statusText member does not match the Reason-Phrase |
// token production, throw a TypeError." |
if (!isValidReasonPhrase(responseInit.statusText)) { |
exceptionState.throwTypeError("Invalid statusText"); |
return 0; |
} |
- // "3. Let |r| be a new Response object, associated with a new response, |
+ // "4. Let |r| be a new Response object, associated with a new response, |
// Headers object, and Body object." |
Response* r = new Response(context); |
r->suspendIfNeeded(); |
- // "4. Set |r|'s response's status to |init|'s status member." |
+ // "5. Set |r|'s response's status to |init|'s status member." |
r->m_response->setStatus(responseInit.status); |
- // "5. Set |r|'s response's status message to |init|'s statusText member." |
+ // "6. Set |r|'s response's status message to |init|'s statusText member." |
r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); |
- // "6. If |init|'s headers member is present, run these substeps:" |
+ // "7. If |init|'s headers member is present, run these substeps:" |
if (responseInit.headers) { |
// "1. Empty |r|'s response's header list." |
r->m_response->headerList()->clearList(); |
@@ -196,7 +206,7 @@ Response* Response::create(ExecutionContext* context, Blob* body, const Response |
if (exceptionState.hadException()) |
return 0; |
} |
- // "7. If body is given, run these substeps:" |
+ // "8. 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|." |
@@ -213,11 +223,11 @@ Response* Response::create(ExecutionContext* context, Blob* body, const Response |
r->m_response->headerList()->append("Content-Type", body->type()); |
} |
- // "8. Set |r|'s MIME type to the result of extracting a MIME type |
+ // "9. Set |r|'s MIME type to the result of extracting a MIME type |
// from |r|'s response's header list." |
r->m_response->setMIMEType(r->m_response->headerList()->extractMIMEType()); |
- // "9. Return |r|." |
+ // "10. Return |r|." |
return r; |
} |