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 pub.barback.web_socket_api; | 5 library pub.barback.web_socket_api; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 | 9 |
10 import 'package:path/path.dart' as path; | 10 import 'package:path/path.dart' as path; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 /// http://localhost:1234/index.html -> NOT_SERVED error | 83 /// http://localhost:1234/index.html -> NOT_SERVED error |
84 /// | 84 /// |
85 /// This does *not* currently support the implicit index.html behavior that | 85 /// This does *not* currently support the implicit index.html behavior that |
86 /// pub serve provides for user-friendliness: | 86 /// pub serve provides for user-friendliness: |
87 /// | 87 /// |
88 /// http://localhost:1234 -> NOT_SERVED error | 88 /// http://localhost:1234 -> NOT_SERVED error |
89 /// | 89 /// |
90 /// This does *not* currently check to ensure the asset actually exists. It | 90 /// This does *not* currently check to ensure the asset actually exists. It |
91 /// only maps what the corresponding asset *should* be for that URL. | 91 /// only maps what the corresponding asset *should* be for that URL. |
92 Map _urlToAssetId(json_rpc.Parameters params) { | 92 Map _urlToAssetId(json_rpc.Parameters params) { |
93 // TODO(nweiz): Use [params.asUrl] when issue 17700 is fixed. | 93 var url = params["url"].asUrl; |
94 var urlString = params["url"].asString; | |
95 var url; | |
96 try { | |
97 url = Uri.parse(urlString); | |
98 } on FormatException catch (ex) { | |
99 throw new json_rpc.RpcException.invalidParams( | |
100 '"$urlString" is not a valid URL.'); | |
101 } | |
102 | 94 |
103 // If a line number was given, map it to the output line. | 95 // If a line number was given, map it to the output line. |
104 var line = params["line"].asIntOr(null); | 96 var line = params["line"].asIntOr(null); |
105 | 97 |
106 var id = _environment.getAssetIdForUrl(url); | 98 var id = _environment.getAssetIdForUrl(url); |
107 if (id == null) { | 99 if (id == null) { |
108 throw new json_rpc.RpcException(_NOT_SERVED, | 100 throw new json_rpc.RpcException(_NOT_SERVED, |
109 '"${url.host}:${url.port}" is not being served by pub.'); | 101 '"${url.host}:${url.port}" is not being served by pub.'); |
110 } | 102 } |
111 | 103 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 | 264 |
273 if (!path.isWithin(".", pathString)) { | 265 if (!path.isWithin(".", pathString)) { |
274 throw new json_rpc.RpcException.invalidParams( | 266 throw new json_rpc.RpcException.invalidParams( |
275 '"$key" cannot reach out of its containing directory. ' | 267 '"$key" cannot reach out of its containing directory. ' |
276 'Got "$pathString".'); | 268 'Got "$pathString".'); |
277 } | 269 } |
278 | 270 |
279 return pathString; | 271 return pathString; |
280 } | 272 } |
281 } | 273 } |
OLD | NEW |