| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:math' as math; | 7 import 'dart:math' as math; |
| 8 | 8 |
| 9 import 'package:async/async.dart' hide StreamQueue; | 9 import 'package:async/async.dart' hide StreamQueue; |
| 10 import 'package:crypto/crypto.dart'; | |
| 11 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| 12 import 'package:shelf/shelf.dart' as shelf; | 11 import 'package:shelf/shelf.dart' as shelf; |
| 13 import 'package:stack_trace/stack_trace.dart'; | 12 import 'package:stack_trace/stack_trace.dart'; |
| 14 | 13 |
| 15 import 'backend/operating_system.dart'; | 14 import 'backend/operating_system.dart'; |
| 16 import 'util/path_handler.dart'; | 15 import 'util/path_handler.dart'; |
| 17 import 'util/stream_queue.dart'; | 16 import 'util/stream_queue.dart'; |
| 18 | 17 |
| 19 /// The maximum console line length. | 18 /// The maximum console line length. |
| 20 const _lineLength = 100; | 19 const _lineLength = 100; |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 /// This is useful for making a block of code async without forcing the | 420 /// This is useful for making a block of code async without forcing the |
| 422 /// containing method to return a future. | 421 /// containing method to return a future. |
| 423 void invoke(fn()) { | 422 void invoke(fn()) { |
| 424 fn(); | 423 fn(); |
| 425 } | 424 } |
| 426 | 425 |
| 427 /// Returns a random base64 string containing [bytes] bytes of data. | 426 /// Returns a random base64 string containing [bytes] bytes of data. |
| 428 /// | 427 /// |
| 429 /// [seed] is passed to [math.Random]; [urlSafe] and [addLineSeparator] are | 428 /// [seed] is passed to [math.Random]; [urlSafe] and [addLineSeparator] are |
| 430 /// passed to [CryptoUtils.bytesToBase64]. | 429 /// passed to [CryptoUtils.bytesToBase64]. |
| 431 String randomBase64(int bytes, {int seed, bool urlSafe: false, | 430 String randomBase64(int bytes, {int seed}) { |
| 432 bool addLineSeparator: false}) { | |
| 433 var random = new math.Random(seed); | 431 var random = new math.Random(seed); |
| 434 var data = []; | 432 var data = []; |
| 435 for (var i = 0; i < bytes; i++) { | 433 for (var i = 0; i < bytes; i++) { |
| 436 data.add(random.nextInt(256)); | 434 data.add(random.nextInt(256)); |
| 437 } | 435 } |
| 438 return CryptoUtils.bytesToBase64(data, | 436 return BASE64.encode(data); |
| 439 urlSafe: urlSafe, addLineSeparator: addLineSeparator); | |
| 440 } | 437 } |
| 441 | 438 |
| 442 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 439 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
| 443 shelf.Middleware nestingMiddleware(String beneath) { | 440 shelf.Middleware nestingMiddleware(String beneath) { |
| 444 return (handler) { | 441 return (handler) { |
| 445 var pathHandler = new PathHandler()..add(beneath, handler); | 442 var pathHandler = new PathHandler()..add(beneath, handler); |
| 446 return pathHandler.handler; | 443 return pathHandler.handler; |
| 447 }; | 444 }; |
| 448 } | 445 } |
| OLD | NEW |