| 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 part of vmservice; | 5 part of vmservice; |
| 6 | 6 |
| 7 class ServiceRequest { | 7 class ServiceRequest { |
| 8 final List<String> pathSegments = new List<String>(); | 8 final List<String> pathSegments = new List<String>(); |
| 9 final Map<String, String> parameters = new Map<String, String>(); | 9 final Map<String, String> parameters = new Map<String, String>(); |
| 10 String _response; | 10 String _response; |
| 11 String get response => _response; | 11 String get response => _response; |
| 12 | 12 |
| 13 ServiceRequest(); | 13 ServiceRequest(); |
| 14 | 14 |
| 15 bool parse(Uri uri) { | 15 bool parse(Uri uri) { |
| 16 var path = uri.path; | 16 var path = uri.path; |
| 17 var split = path.split('/'); | 17 var split = path.split('/'); |
| 18 if (split.length == 0) { | 18 if (split.length == 0) { |
| 19 setErrorResponse('Invalid request uri: ${request.uri}'); |
| 19 return false; | 20 return false; |
| 20 } | 21 } |
| 21 for (int i = 0; i < split.length; i++) { | 22 for (int i = 0; i < split.length; i++) { |
| 22 var pathSegment = split[i]; | 23 var pathSegment = split[i]; |
| 23 if (pathSegment == '') { | 24 if (pathSegment == '') { |
| 24 continue; | 25 continue; |
| 25 } | 26 } |
| 26 pathSegments.add(pathSegment); | 27 pathSegments.add(pathSegment); |
| 27 } | 28 } |
| 28 uri.queryParameters.forEach((k, v) { | 29 uri.queryParameters.forEach((k, v) { |
| 29 parameters[k] = v; | 30 parameters[k] = v; |
| 30 }); | 31 }); |
| 31 return true; | 32 return true; |
| 32 } | 33 } |
| 33 | 34 |
| 34 List toServiceCallMessage() { | 35 List toServiceCallMessage() { |
| 35 return [pathSegments, parameters.keys.toList(), parameters.values.toList()]; | 36 return [pathSegments, parameters.keys.toList(), parameters.values.toList()]; |
| 36 } | 37 } |
| 37 | 38 |
| 38 void setErrorResponse(String error) { | 39 void setErrorResponse(String error) { |
| 39 _response = JSON.encode({ | 40 _response = JSON.encode({ |
| 40 'type': 'error', | 41 'type': 'Error', |
| 41 'msg': error, | 42 'msg': error, |
| 42 'pathSegments': pathSegments, | 43 'pathSegments': pathSegments, |
| 43 'parameters': parameters | 44 'parameters': parameters |
| 44 }); | 45 }); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void setResponse(String response) { | 48 void setResponse(String response) { |
| 48 _response = response; | 49 _response = response; |
| 49 } | 50 } |
| 50 | 51 |
| 51 } | 52 } |
| OLD | NEW |