| 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 http.server; | 5 library http.server; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/channel/web_socket_channel.dart'; | 10 import 'package:analysis_server/src/channel/web_socket_channel.dart'; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 if (_printBuffer.length > MAX_PRINT_BUFFER_LENGTH) { | 69 if (_printBuffer.length > MAX_PRINT_BUFFER_LENGTH) { |
| 70 _printBuffer.removeRange( | 70 _printBuffer.removeRange( |
| 71 0, _printBuffer.length - MAX_PRINT_BUFFER_LENGTH); | 71 0, _printBuffer.length - MAX_PRINT_BUFFER_LENGTH); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Begin serving HTTP requests over the given port. | 76 * Begin serving HTTP requests over the given port. |
| 77 */ | 77 */ |
| 78 void serveHttp(int port) { | 78 void serveHttp(int port) { |
| 79 _server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); | 79 try { |
| 80 _server.then(_handleServer); | 80 _server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); |
| 81 _server.then(_handleServer); |
| 82 } catch (exception) { |
| 83 // We were unable to start the server, and there's nothing we can do about |
| 84 // it. |
| 85 } |
| 81 } | 86 } |
| 82 | 87 |
| 83 /** | 88 /** |
| 84 * Handle a GET request received by the HTTP server. | 89 * Handle a GET request received by the HTTP server. |
| 85 */ | 90 */ |
| 86 void _handleGetRequest(HttpRequest request) { | 91 void _handleGetRequest(HttpRequest request) { |
| 87 if (AnalysisEngine.instance.useTaskModel) { | 92 if (AnalysisEngine.instance.useTaskModel) { |
| 88 if (newGetHandler == null) { | 93 if (newGetHandler == null) { |
| 89 newGetHandler = new newHandler.GetHandler(socketServer, _printBuffer); | 94 newGetHandler = new newHandler.GetHandler(socketServer, _printBuffer); |
| 90 } | 95 } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 */ | 135 */ |
| 131 void _returnUnknownRequest(HttpRequest request) { | 136 void _returnUnknownRequest(HttpRequest request) { |
| 132 HttpResponse response = request.response; | 137 HttpResponse response = request.response; |
| 133 response.statusCode = HttpStatus.NOT_FOUND; | 138 response.statusCode = HttpStatus.NOT_FOUND; |
| 134 response.headers.contentType = | 139 response.headers.contentType = |
| 135 new ContentType("text", "plain", charset: "utf-8"); | 140 new ContentType("text", "plain", charset: "utf-8"); |
| 136 response.write('Not found'); | 141 response.write('Not found'); |
| 137 response.close(); | 142 response.close(); |
| 138 } | 143 } |
| 139 } | 144 } |
| OLD | NEW |