| 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 import 'dart:typed_data'; | 8 import 'dart:typed_data'; |
| 9 | 9 |
| 10 import 'package:async/async.dart' hide StreamQueue; | 10 import 'package:async/async.dart' hide StreamQueue; |
| 11 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
| 12 import 'package:shelf/shelf.dart' as shelf; | 12 import 'package:shelf/shelf.dart' as shelf; |
| 13 import 'package:stack_trace/stack_trace.dart'; | 13 import 'package:stack_trace/stack_trace.dart'; |
| 14 | 14 |
| 15 import 'backend/operating_system.dart'; | 15 import 'backend/operating_system.dart'; |
| 16 import 'util/path_handler.dart'; | 16 import 'util/path_handler.dart'; |
| 17 import 'util/stream_queue.dart'; | 17 import 'util/stream_queue.dart'; |
| 18 | 18 |
| 19 /// The maximum console line length. | 19 /// The maximum console line length. |
| 20 const _lineLength = 100; | 20 const _lineLength = 100; |
| 21 | 21 |
| 22 /// A typedef for a possibly-asynchronous function. | 22 /// A typedef for a possibly-asynchronous function. |
| 23 /// | 23 /// |
| 24 /// The return type should only ever by [Future] or void. | 24 /// The return type should only ever by [Future] or void. |
| 25 typedef AsyncFunction(); | 25 typedef AsyncFunction(); |
| 26 | 26 |
| 27 /// A typedef for a zero-argument callback function. | 27 /// A typedef for a zero-argument callback function. |
| 28 typedef void Callback(); | 28 typedef void Callback(); |
| 29 | 29 |
| 30 /// A converter that decodes bytes using UTF-8 and splits them on newlines. | 30 /// A transformer that decodes bytes using UTF-8 and splits them on newlines. |
| 31 final lineSplitter = UTF8.decoder.fuse(const LineSplitter()); | 31 final lineSplitter = new StreamTransformer<List<int>, String>( |
| 32 (stream, cancelOnError) => stream |
| 33 .transform(UTF8.decoder) |
| 34 .transform(const LineSplitter()) |
| 35 .listen(null, cancelOnError: cancelOnError)); |
| 32 | 36 |
| 33 /// A regular expression to match the exception prefix that some exceptions' | 37 /// A regular expression to match the exception prefix that some exceptions' |
| 34 /// [Object.toString] values contain. | 38 /// [Object.toString] values contain. |
| 35 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); | 39 final _exceptionPrefix = new RegExp(r'^([A-Z][a-zA-Z]*)?(Exception|Error): '); |
| 36 | 40 |
| 37 /// A regular expression matching a single vowel. | 41 /// A regular expression matching a single vowel. |
| 38 final _vowel = new RegExp('[aeiou]'); | 42 final _vowel = new RegExp('[aeiou]'); |
| 39 | 43 |
| 40 /// Directories that are specific to OS X. | 44 /// Directories that are specific to OS X. |
| 41 /// | 45 /// |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 return BASE64.encode(data); | 361 return BASE64.encode(data); |
| 358 } | 362 } |
| 359 | 363 |
| 360 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. | 364 /// Returns middleware that nests all requests beneath the URL prefix [beneath]. |
| 361 shelf.Middleware nestingMiddleware(String beneath) { | 365 shelf.Middleware nestingMiddleware(String beneath) { |
| 362 return (handler) { | 366 return (handler) { |
| 363 var pathHandler = new PathHandler()..add(beneath, handler); | 367 var pathHandler = new PathHandler()..add(beneath, handler); |
| 364 return pathHandler.handler; | 368 return pathHandler.handler; |
| 365 }; | 369 }; |
| 366 } | 370 } |
| OLD | NEW |