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

Side by Side Diff: runtime/bin/dartutils.cc

Issue 16305011: Fix HTTP response handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 6 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
« no previous file with comments | « runtime/bin/builtin.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/dartutils.h" 5 #include "bin/dartutils.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 8
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 Dart_GetField(builtin_lib, 280 Dart_GetField(builtin_lib,
281 DartUtils::NewString("_httpRequestStatusString")); 281 DartUtils::NewString("_httpRequestStatusString"));
282 if (Dart_IsError(responseStatus)) { 282 if (Dart_IsError(responseStatus)) {
283 return responseStatus; 283 return responseStatus;
284 } 284 }
285 if (Dart_IsNull(responseStatus)) { 285 if (Dart_IsNull(responseStatus)) {
286 return Dart_Error("HTTP error."); 286 return Dart_Error("HTTP error.");
287 } 287 }
288 return Dart_Error(DartUtils::GetStringValue(responseStatus)); 288 return Dart_Error(DartUtils::GetStringValue(responseStatus));
289 } 289 }
290 Dart_Handle responseList = 290 Dart_Handle response =
291 Dart_GetField(builtin_lib, DartUtils::NewString("_httpRequestResponse")); 291 Dart_GetField(builtin_lib, DartUtils::NewString("_httpRequestResponse"));
292 if (Dart_IsError(responseList)) { 292 if (Dart_IsError(response)) {
293 return responseList; 293 return response;
294 } 294 }
295 // Query list length. 295 if (Dart_IsString(response)) {
296 result = Dart_ListLength(responseList, buffer_len); 296 // Received response as string.
297 if (Dart_IsError(result)) { 297 uint8_t* responseString = NULL;
298 *buffer_len = 0; 298 intptr_t responseStringLength;
299 *buffer = NULL; 299 Dart_Handle r = Dart_StringToUTF8(response, &responseString,
300 return result; 300 &responseStringLength);
301 } 301 if (Dart_IsError(r)) {
302 // Get payload as bytes. 302 *buffer = NULL;
303 *buffer = reinterpret_cast<uint8_t*>(malloc(*buffer_len)); 303 *buffer_len = 0;
304 result = Dart_ListGetAsBytes(responseList, 0, *buffer, *buffer_len); 304 return r;
305 if (Dart_IsError(result)) { 305 }
306 free(*buffer); 306 // Get payload as bytes.
307 *buffer_len = 0; 307 *buffer_len = responseStringLength;
308 *buffer = NULL; 308 *buffer = reinterpret_cast<uint8_t*>(malloc(responseStringLength));
309 return result; 309 memmove(*buffer, responseString, responseStringLength);
310 } else {
311 // Received response as list of bytes.
312 ASSERT(Dart_IsList(response));
313 // Query list length.
314 result = Dart_ListLength(response, buffer_len);
315 if (Dart_IsError(result)) {
316 *buffer_len = 0;
317 *buffer = NULL;
318 return result;
319 }
320 // Get payload as bytes.
321 *buffer = reinterpret_cast<uint8_t*>(malloc(*buffer_len));
322 result = Dart_ListGetAsBytes(response, 0, *buffer, *buffer_len);
323 if (Dart_IsError(result)) {
324 free(*buffer);
325 *buffer_len = 0;
326 *buffer = NULL;
327 return result;
328 }
310 } 329 }
311 return result; 330 return result;
312 } 331 }
313 332
314 333
315 Dart_Handle DartUtils::ReadStringFromHttp(const char* script_uri) { 334 Dart_Handle DartUtils::ReadStringFromHttp(const char* script_uri) {
316 Dart_Handle uri = NewString(script_uri); 335 Dart_Handle uri = NewString(script_uri);
317 if (Dart_IsError(uri)) { 336 if (Dart_IsError(uri)) {
318 return uri; 337 return uri;
319 } 338 }
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 if (Dart_IsError(result)) { 545 if (Dart_IsError(result)) {
527 return result; 546 return result;
528 } 547 }
529 const uint8_t* payload = buffer; 548 const uint8_t* payload = buffer;
530 bool is_snapshot = false; 549 bool is_snapshot = false;
531 payload = SniffForMagicNumber(payload, &len, &is_snapshot); 550 payload = SniffForMagicNumber(payload, &len, &is_snapshot);
532 if (is_snapshot) { 551 if (is_snapshot) {
533 return Dart_LoadScriptFromSnapshot(payload, len); 552 return Dart_LoadScriptFromSnapshot(payload, len);
534 } else { 553 } else {
535 Dart_Handle source = Dart_NewStringFromUTF8(payload, len); 554 Dart_Handle source = Dart_NewStringFromUTF8(payload, len);
555 free(buffer);
536 if (Dart_IsError(source)) { 556 if (Dart_IsError(source)) {
537 return source; 557 return source;
538 } 558 }
539 return Dart_LoadScript(uri, source, 0, 0); 559 return Dart_LoadScript(uri, source, 0, 0);
540 } 560 }
541 } 561 }
542 562
543 563
544 Dart_Handle DartUtils::LoadScript(const char* script_uri, 564 Dart_Handle DartUtils::LoadScript(const char* script_uri,
545 Dart_Handle builtin_lib) { 565 Dart_Handle builtin_lib) {
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 new CObjectString(CObject::NewString(os_error->message())); 953 new CObjectString(CObject::NewString(os_error->message()));
934 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 954 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
935 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 955 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
936 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 956 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
937 result->SetAt(2, error_message); 957 result->SetAt(2, error_message);
938 return result; 958 return result;
939 } 959 }
940 960
941 } // namespace bin 961 } // namespace bin
942 } // namespace dart 962 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/builtin.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698