Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/Response.h" | 6 #include "modules/fetch/Response.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 const long long length = blobData->length(); | 146 const long long length = blobData->length(); |
| 147 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth)); | 147 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth)); |
| 148 return create(context, blob, ResponseInit(responseInit, exceptionState), exceptionState); | 148 return create(context, blob, ResponseInit(responseInit, exceptionState), exceptionState); |
| 149 } | 149 } |
| 150 ASSERT_NOT_REACHED(); | 150 ASSERT_NOT_REACHED(); |
| 151 return nullptr; | 151 return nullptr; |
| 152 } | 152 } |
| 153 | 153 |
| 154 Response* Response::create(ExecutionContext* context, Blob* body, const Response Init& responseInit, ExceptionState& exceptionState) | 154 Response* Response::create(ExecutionContext* context, Blob* body, const Response Init& responseInit, ExceptionState& exceptionState) |
| 155 { | 155 { |
| 156 unsigned short status = responseInit.status; | |
| 157 | |
| 156 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 158 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
| 157 // RangeError." | 159 // RangeError." |
| 158 if (responseInit.status < 200 || 599 < responseInit.status) { | 160 if (status < 200 || 599 < status) { |
| 159 exceptionState.throwRangeError("Invalid status"); | 161 exceptionState.throwRangeError(ExceptionMessages::indexOutsideRange<unsi gned>("status", status, 200, ExceptionMessages::InclusiveBound, 599, ExceptionMe ssages::InclusiveBound)); |
| 160 return 0; | 162 return 0; |
| 161 } | 163 } |
| 162 | 164 |
| 163 // "2. If |init|'s statusText member does not match the Reason-Phrase | 165 // "2. If init's status member is a null body status and body is non-null, |
| 166 // throw a TypeError. A null body status is 101, 204, 205, or 304, | |
| 167 // 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.
| |
| 168 if ((status == 101 || status == 204 || status == 205 || status == 304) && bo dy) { | |
| 169 exceptionState.throwTypeError("Response with null body status cannot hav e body"); | |
| 170 return 0; | |
| 171 } | |
| 172 | |
| 173 // "3. If |init|'s statusText member does not match the Reason-Phrase | |
| 164 // token production, throw a TypeError." | 174 // token production, throw a TypeError." |
| 165 if (!isValidReasonPhrase(responseInit.statusText)) { | 175 if (!isValidReasonPhrase(responseInit.statusText)) { |
| 166 exceptionState.throwTypeError("Invalid statusText"); | 176 exceptionState.throwTypeError("Invalid statusText"); |
| 167 return 0; | 177 return 0; |
| 168 } | 178 } |
| 169 | 179 |
| 170 // "3. Let |r| be a new Response object, associated with a new response, | 180 // "4. Let |r| be a new Response object, associated with a new response, |
| 171 // Headers object, and Body object." | 181 // Headers object, and Body object." |
| 172 Response* r = new Response(context); | 182 Response* r = new Response(context); |
| 173 r->suspendIfNeeded(); | 183 r->suspendIfNeeded(); |
| 174 | 184 |
| 175 // "4. Set |r|'s response's status to |init|'s status member." | 185 // "5. Set |r|'s response's status to |init|'s status member." |
| 176 r->m_response->setStatus(responseInit.status); | 186 r->m_response->setStatus(responseInit.status); |
| 177 | 187 |
| 178 // "5. Set |r|'s response's status message to |init|'s statusText member." | 188 // "6. Set |r|'s response's status message to |init|'s statusText member." |
| 179 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); | 189 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); |
| 180 | 190 |
| 181 // "6. If |init|'s headers member is present, run these substeps:" | 191 // "7. If |init|'s headers member is present, run these substeps:" |
| 182 if (responseInit.headers) { | 192 if (responseInit.headers) { |
| 183 // "1. Empty |r|'s response's header list." | 193 // "1. Empty |r|'s response's header list." |
| 184 r->m_response->headerList()->clearList(); | 194 r->m_response->headerList()->clearList(); |
| 185 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow | 195 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow |
| 186 // any exceptions." | 196 // any exceptions." |
| 187 r->m_headers->fillWith(responseInit.headers.get(), exceptionState); | 197 r->m_headers->fillWith(responseInit.headers.get(), exceptionState); |
| 188 if (exceptionState.hadException()) | 198 if (exceptionState.hadException()) |
| 189 return 0; | 199 return 0; |
| 190 } else if (!responseInit.headersDictionary.isUndefinedOrNull()) { | 200 } else if (!responseInit.headersDictionary.isUndefinedOrNull()) { |
| 191 // "1. Empty |r|'s response's header list." | 201 // "1. Empty |r|'s response's header list." |
| 192 r->m_response->headerList()->clearList(); | 202 r->m_response->headerList()->clearList(); |
| 193 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow | 203 // "2. Fill |r|'s Headers object with |init|'s headers member. Rethrow |
| 194 // any exceptions." | 204 // any exceptions." |
| 195 r->m_headers->fillWith(responseInit.headersDictionary, exceptionState); | 205 r->m_headers->fillWith(responseInit.headersDictionary, exceptionState); |
| 196 if (exceptionState.hadException()) | 206 if (exceptionState.hadException()) |
| 197 return 0; | 207 return 0; |
| 198 } | 208 } |
| 199 // "7. If body is given, run these substeps:" | 209 // "8. If body is given, run these substeps:" |
| 200 if (body) { | 210 if (body) { |
| 201 // "1. Let |stream| and |Content-Type| be the result of extracting body. " | 211 // "1. Let |stream| and |Content-Type| be the result of extracting body. " |
| 202 // "2. Set |r|'s response's body to |stream|." | 212 // "2. Set |r|'s response's body to |stream|." |
| 203 // "3. If |Content-Type| is non-null and |r|'s response's header list | 213 // "3. If |Content-Type| is non-null and |r|'s response's header list |
| 204 // contains no header named `Content-Type`, append `Content-Type`/ | 214 // contains no header named `Content-Type`, append `Content-Type`/ |
| 205 // |Content-Type| to |r|'s response's header list." | 215 // |Content-Type| to |r|'s response's header list." |
| 206 // https://fetch.spec.whatwg.org/#concept-bodyinit-extract | 216 // https://fetch.spec.whatwg.org/#concept-bodyinit-extract |
| 207 // Step 3, Blob: | 217 // Step 3, Blob: |
| 208 // "If object's type attribute is not the empty byte sequence, set | 218 // "If object's type attribute is not the empty byte sequence, set |
| 209 // Content-Type to its value." | 219 // Content-Type to its value." |
| 210 r->m_response->replaceBodyStreamBuffer(BodyStreamBuffer::create(FetchBlo bDataConsumerHandle::create(context, body->blobDataHandle()))); | 220 r->m_response->replaceBodyStreamBuffer(BodyStreamBuffer::create(FetchBlo bDataConsumerHandle::create(context, body->blobDataHandle()))); |
| 211 r->refreshBody(); | 221 r->refreshBody(); |
| 212 if (!body->type().isEmpty() && !r->m_response->headerList()->has("Conten t-Type")) | 222 if (!body->type().isEmpty() && !r->m_response->headerList()->has("Conten t-Type")) |
| 213 r->m_response->headerList()->append("Content-Type", body->type()); | 223 r->m_response->headerList()->append("Content-Type", body->type()); |
| 214 } | 224 } |
| 215 | 225 |
| 216 // "8. Set |r|'s MIME type to the result of extracting a MIME type | 226 // "9. Set |r|'s MIME type to the result of extracting a MIME type |
| 217 // from |r|'s response's header list." | 227 // from |r|'s response's header list." |
| 218 r->m_response->setMIMEType(r->m_response->headerList()->extractMIMEType()); | 228 r->m_response->setMIMEType(r->m_response->headerList()->extractMIMEType()); |
| 219 | 229 |
| 220 // "9. Return |r|." | 230 // "10. Return |r|." |
| 221 return r; | 231 return r; |
| 222 } | 232 } |
| 223 | 233 |
| 224 Response* Response::create(ExecutionContext* context, FetchResponseData* respons e) | 234 Response* Response::create(ExecutionContext* context, FetchResponseData* respons e) |
| 225 { | 235 { |
| 226 Response* r = new Response(context, response); | 236 Response* r = new Response(context, response); |
| 227 r->suspendIfNeeded(); | 237 r->suspendIfNeeded(); |
| 228 return r; | 238 return r; |
| 229 } | 239 } |
| 230 | 240 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 } | 444 } |
| 435 | 445 |
| 436 DEFINE_TRACE(Response) | 446 DEFINE_TRACE(Response) |
| 437 { | 447 { |
| 438 Body::trace(visitor); | 448 Body::trace(visitor); |
| 439 visitor->trace(m_response); | 449 visitor->trace(m_response); |
| 440 visitor->trace(m_headers); | 450 visitor->trace(m_headers); |
| 441 } | 451 } |
| 442 | 452 |
| 443 } // namespace blink | 453 } // namespace blink |
| OLD | NEW |