Chromium Code Reviews| Index: runtime/bin/vmservice/service_request.dart |
| diff --git a/runtime/bin/vmservice/service_request.dart b/runtime/bin/vmservice/service_request.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b00a1cd78c80b769de94c91b2a1c5e4e05b8199c |
| --- /dev/null |
| +++ b/runtime/bin/vmservice/service_request.dart |
| @@ -0,0 +1,58 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +part of vmservice; |
| + |
| +class ServiceRequest { |
| + final List<String> pathSegments = new List<String>(); |
| + final Map<String, String> parameters = new Map<String, String>(); |
| + String _response; |
| + 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
|
| + |
| + |
| + ServiceRequest(); |
| + |
| + bool parse(Uri uri) { |
| + String path = uri.path; |
| + List<String> split = path.split('/'); |
| + if (split.length == 0) { |
| + return false; |
| + } |
| + for (int i = 0; i < split.length; i++) { |
| + var pathSegment = split[i]; |
| + if (pathSegment == '') { |
| + continue; |
| + } |
| + pathSegments.add(pathSegment); |
| + } |
| + uri.queryParameters.forEach((k, v) { |
| + parameters[k] = v; |
| + }); |
| + return true; |
| + } |
| + |
| + |
| + String toServiceCallMessage() { |
| + return JSON.stringify({ |
| + 'p': pathSegments, |
| + 'k': parameters.keys.toList(), |
| + 'v': parameters.values.toList() |
| + }); |
| + } |
| + |
| + |
| + void setErrorResponse(String error) { |
| + _response = JSON.stringify({ |
| + 'error': error, |
| + 'pathSegments': pathSegments, |
| + 'parameters': parameters |
| + }); |
| + } |
| + |
| + |
| + void setResponse(String response) { |
| + _response = response; |
| + } |
| + |
| +} |