Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of vmservice; | |
| 6 | |
| 7 class ServiceRequest { | |
| 8 final List<String> pathSegments = new List<String>(); | |
| 9 final Map<String, String> parameters = new Map<String, String>(); | |
| 10 String _response; | |
| 11 String get response => _response; | |
|
siva
2013/07/19 17:41:16
The style guide prefers to avoid wrapping fields i
Cutch
2013/07/19 18:15:02
I'm protecting _response from being set without go
| |
| 12 | |
| 13 | |
| 14 ServiceRequest(); | |
| 15 | |
| 16 bool parse(Uri uri) { | |
| 17 String path = uri.path; | |
| 18 List<String> split = path.split('/'); | |
| 19 if (split.length == 0) { | |
| 20 return false; | |
| 21 } | |
| 22 for (int i = 0; i < split.length; i++) { | |
| 23 var pathSegment = split[i]; | |
| 24 if (pathSegment == '') { | |
| 25 continue; | |
| 26 } | |
| 27 pathSegments.add(pathSegment); | |
| 28 } | |
| 29 uri.queryParameters.forEach((k, v) { | |
| 30 parameters[k] = v; | |
| 31 }); | |
| 32 return true; | |
| 33 } | |
| 34 | |
| 35 | |
| 36 String toServiceCallMessage() { | |
| 37 return JSON.stringify({ | |
| 38 'p': pathSegments, | |
| 39 'k': parameters.keys.toList(), | |
| 40 'v': parameters.values.toList() | |
| 41 }); | |
| 42 } | |
| 43 | |
| 44 | |
| 45 void setErrorResponse(String error) { | |
| 46 _response = JSON.stringify({ | |
| 47 'error': error, | |
| 48 'pathSegments': pathSegments, | |
| 49 'parameters': parameters | |
| 50 }); | |
| 51 } | |
| 52 | |
| 53 | |
| 54 void setResponse(String response) { | |
| 55 _response = response; | |
| 56 } | |
| 57 | |
| 58 } | |
| OLD | NEW |