OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library protocol; | 5 library protocol; |
6 | 6 |
7 import 'dart:convert' show JsonDecoder; | 7 import 'dart:convert' show JsonDecoder; |
8 | 8 |
9 /** | 9 /** |
10 * Instances of the class [Request] represent a request that was received. | 10 * Instances of the class [Request] represent a request that was received. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 * | 66 * |
67 * where the parameters are optional and can contain any number of name/value | 67 * where the parameters are optional and can contain any number of name/value |
68 * pairs. | 68 * pairs. |
69 */ | 69 */ |
70 factory Request.fromString(String data) { | 70 factory Request.fromString(String data) { |
71 try { | 71 try { |
72 var result = DECODER.convert(data); | 72 var result = DECODER.convert(data); |
73 if (result is! Map) { | 73 if (result is! Map) { |
74 return null; | 74 return null; |
75 } | 75 } |
76 String id = result[Request.ID]; | 76 var id = result[Request.ID]; |
77 String method = result[Request.METHOD]; | 77 var method = result[Request.METHOD]; |
| 78 if (id is! String || method is! String) { |
| 79 return null; |
| 80 } |
78 var params = result[Request.PARAMS]; | 81 var params = result[Request.PARAMS]; |
79 Request request = new Request(id, method); | 82 Request request = new Request(id, method); |
80 if (params is Map) { | 83 if (params is Map) { |
81 params.forEach((String key, Object value) { | 84 params.forEach((String key, Object value) { |
82 request.setParameter(key, value); | 85 request.setParameter(key, value); |
83 }); | 86 }); |
| 87 } else if (params != null) { |
| 88 return null; |
84 } | 89 } |
85 return request; | 90 return request; |
86 } catch (exception) { | 91 } catch (exception) { |
87 return null; | 92 return null; |
88 } | 93 } |
89 } | 94 } |
90 | 95 |
91 /** | 96 /** |
92 * Return the value of the parameter with the given [name], or `null` if there | 97 * Return the value of the parameter with the given [name], or `null` if there |
93 * is no such parameter associated with this request. | 98 * is no such parameter associated with this request. |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 /** | 579 /** |
575 * The response to be returned as a result of the failure. | 580 * The response to be returned as a result of the failure. |
576 */ | 581 */ |
577 final Response response; | 582 final Response response; |
578 | 583 |
579 /** | 584 /** |
580 * Initialize a newly created exception to return the given reponse. | 585 * Initialize a newly created exception to return the given reponse. |
581 */ | 586 */ |
582 RequestFailure(this.response); | 587 RequestFailure(this.response); |
583 } | 588 } |
OLD | NEW |