Chromium Code Reviews| 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 Server { | 7 class Server { |
| 8 int port; | 8 int port; |
| 9 static ContentType jsonContentType = ContentType.parse('application/json'); | 9 static ContentType jsonContentType = ContentType.parse('application/json'); |
| 10 final VmService service; | 10 final VmService service; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 if (resource != null) { | 23 if (resource != null) { |
| 24 // Serving up a static resource (e.g. .css, .html, .png). | 24 // Serving up a static resource (e.g. .css, .html, .png). |
| 25 request.response.headers.contentType = ContentType.parse(mimeType); | 25 request.response.headers.contentType = ContentType.parse(mimeType); |
| 26 request.response.add(resource.data); | 26 request.response.add(resource.data); |
| 27 request.response.close(); | 27 request.response.close(); |
| 28 return; | 28 return; |
| 29 } | 29 } |
| 30 | 30 |
| 31 var serviceRequest = new ServiceRequest(); | 31 var serviceRequest = new ServiceRequest(); |
| 32 var r = serviceRequest.parse(request.uri); | 32 var r = serviceRequest.parse(request.uri); |
| 33 var f; | |
| 33 if (!r) { | 34 if (!r) { |
| 34 // Did not understand the request uri. | 35 // Did not understand the request uri. |
| 35 serviceRequest.setErrorResponse('Invalid request uri: ${request.uri}'); | 36 serviceRequest.setErrorResponse('Invalid request uri: ${request.uri}'); |
| 36 } else { | 37 } else { |
| 37 r = service.runningIsolates.route(serviceRequest); | 38 f = service.runningIsolates.route(serviceRequest); |
| 38 if (!r) { | |
| 39 // Nothing responds to this type of request. | |
| 40 serviceRequest.setErrorResponse('No route for: $path'); | |
| 41 } | |
| 42 } | 39 } |
| 43 | 40 |
| 44 // Send response back over HTTP. | 41 if (f == null) { |
| 45 request.response.headers.contentType = jsonContentType; | 42 // Nothing responds to this type of request. |
| 46 request.response.write(serviceRequest.response); | 43 serviceRequest.setErrorResponse('No route for: $path'); |
|
siva
2013/08/01 18:16:18
This seems to override the error response set in t
Cutch
2013/08/01 22:22:04
Done.
| |
| 47 request.response.close(); | 44 // Send response back over HTTP. |
| 45 request.response.headers.contentType = jsonContentType; | |
| 46 request.response.write(serviceRequest.response); | |
| 47 request.response.close(); | |
| 48 return; | |
| 49 } | |
| 50 | |
| 51 // Route was successful. | |
| 52 f.then((_) { | |
| 53 // Send response back over HTTP. | |
| 54 request.response.headers.contentType = jsonContentType; | |
| 55 request.response.write(serviceRequest.response); | |
| 56 request.response.close(); | |
| 57 }); | |
| 48 } | 58 } |
| 49 | 59 |
| 50 Future startServer() { | 60 Future startServer() { |
| 51 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((s) { | 61 return HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then((s) { |
| 52 // Only display message when port is automatically selected. | 62 // Only display message when port is automatically selected. |
| 53 var display_message = (port == 0); | 63 var display_message = (port == 0); |
| 54 // Retrieve port. | 64 // Retrieve port. |
| 55 port = s.port; | 65 port = s.port; |
| 56 _server = s; | 66 _server = s; |
| 57 _server.listen(_requestHandler); | 67 _server.listen(_requestHandler); |
| 58 if (display_message) { | 68 if (display_message) { |
| 59 print('VmService listening on port $port'); | 69 print('VmService listening on port $port'); |
| 60 } | 70 } |
| 61 return s; | 71 return s; |
| 62 }); | 72 }); |
| 63 } | 73 } |
| 64 } | 74 } |
| 65 | |
| OLD | NEW |