| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:analysis_server/src/channel/web_socket_channel.dart'; | 8 import 'package:analysis_server/src/channel/web_socket_channel.dart'; |
| 9 import 'package:analysis_server/src/socket_server.dart'; | 9 import 'package:analysis_server/src/socket_server.dart'; |
| 10 import 'package:analysis_server/src/status/diagnostics.dart'; | 10 import 'package:analysis_server/src/status/diagnostics.dart'; |
| 11 import 'package:analysis_server/src/status/get_handler.dart'; | |
| 12 | 11 |
| 13 /** | 12 /** |
| 14 * Instances of the class [HttpServer] implement a simple HTTP server. The | 13 * Instances of the class [HttpServer] implement a simple HTTP server. The |
| 15 * server: | 14 * server: |
| 16 * | 15 * |
| 17 * - listens for an UPGRADE request in order to start an analysis server | 16 * - listens for an UPGRADE request in order to start an analysis server |
| 18 * - serves diagnostic information as html pages | 17 * - serves diagnostic information as html pages |
| 19 */ | 18 */ |
| 20 class HttpAnalysisServer { | 19 class HttpAnalysisServer { |
| 21 /** | 20 /** |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 return null; | 88 return null; |
| 90 } | 89 } |
| 91 } | 90 } |
| 92 | 91 |
| 93 /** | 92 /** |
| 94 * Handle a GET request received by the HTTP server. | 93 * Handle a GET request received by the HTTP server. |
| 95 */ | 94 */ |
| 96 void _handleGetRequest(HttpRequest request) { | 95 void _handleGetRequest(HttpRequest request) { |
| 97 if (getHandler == null) { | 96 if (getHandler == null) { |
| 98 if (socketServer.analysisServer.options.enableNewAnalysisDriver) { | 97 if (socketServer.analysisServer.options.enableNewAnalysisDriver) { |
| 99 // TODO(devoncarew): Remove GetHandler2. | |
| 100 getHandler = new DiagnosticsSite(socketServer, _printBuffer); | 98 getHandler = new DiagnosticsSite(socketServer, _printBuffer); |
| 101 } else { | 99 } else { |
| 102 // TODO(devoncarew): GetHandler is essentially dead code. | 100 getHandler = new ErrorGetHandler( |
| 103 getHandler = new GetHandler(socketServer, _printBuffer); | 101 'Diagnostics only supported for the new analysis driver.'); |
| 104 } | 102 } |
| 105 } | 103 } |
| 106 getHandler.handleGetRequest(request); | 104 getHandler.handleGetRequest(request); |
| 107 } | 105 } |
| 108 | 106 |
| 109 /** | 107 /** |
| 110 * Attach a listener to a newly created HTTP server. | 108 * Attach a listener to a newly created HTTP server. |
| 111 */ | 109 */ |
| 112 void _handleServer(HttpServer httpServer) { | 110 void _handleServer(HttpServer httpServer) { |
| 113 httpServer.listen((HttpRequest request) { | 111 httpServer.listen((HttpRequest request) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 149 |
| 152 /** | 150 /** |
| 153 * Instances of the class [AbstractGetHandler] handle GET requests. | 151 * Instances of the class [AbstractGetHandler] handle GET requests. |
| 154 */ | 152 */ |
| 155 abstract class AbstractGetHandler { | 153 abstract class AbstractGetHandler { |
| 156 /** | 154 /** |
| 157 * Handle a GET request received by the HTTP server. | 155 * Handle a GET request received by the HTTP server. |
| 158 */ | 156 */ |
| 159 void handleGetRequest(HttpRequest request); | 157 void handleGetRequest(HttpRequest request); |
| 160 } | 158 } |
| 159 |
| 160 /** |
| 161 * An [AbstractGetHandler] that always returns the given error message. |
| 162 */ |
| 163 class ErrorGetHandler extends AbstractGetHandler { |
| 164 final String message; |
| 165 |
| 166 ErrorGetHandler(this.message); |
| 167 |
| 168 @override |
| 169 void handleGetRequest(HttpRequest request) { |
| 170 HttpResponse response = request.response; |
| 171 response.statusCode = HttpStatus.NOT_FOUND; |
| 172 response.headers.contentType = ContentType.TEXT; |
| 173 response.write(message); |
| 174 response.close(); |
| 175 } |
| 176 } |
| OLD | NEW |