| 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 analysis_server.src.server.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'; |
| 11 import 'package:analysis_server/src/get_handler.dart'; | |
| 12 import 'package:analysis_server/src/socket_server.dart'; | 11 import 'package:analysis_server/src/socket_server.dart'; |
| 13 import 'package:analysis_server/src/status/get_handler.dart' as newHandler; | 12 import 'package:analysis_server/src/status/get_handler.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | |
| 15 | 13 |
| 16 /** | 14 /** |
| 17 * Instances of the class [HttpServer] implement a simple HTTP server. The | 15 * Instances of the class [HttpServer] implement a simple HTTP server. The |
| 18 * primary responsibility of this server is to listen for an UPGRADE request and | 16 * primary responsibility of this server is to listen for an UPGRADE request and |
| 19 * to start an analysis server. | 17 * to start an analysis server. |
| 20 */ | 18 */ |
| 21 class HttpAnalysisServer { | 19 class HttpAnalysisServer { |
| 22 /** | 20 /** |
| 23 * Number of lines of print output to capture. | 21 * Number of lines of print output to capture. |
| 24 */ | 22 */ |
| 25 static const int MAX_PRINT_BUFFER_LENGTH = 1000; | 23 static const int MAX_PRINT_BUFFER_LENGTH = 1000; |
| 26 | 24 |
| 27 /** | 25 /** |
| 28 * An object that can handle either a WebSocket connection or a connection | 26 * An object that can handle either a WebSocket connection or a connection |
| 29 * to the client over stdio. | 27 * to the client over stdio. |
| 30 */ | 28 */ |
| 31 SocketServer socketServer; | 29 SocketServer socketServer; |
| 32 | 30 |
| 33 /** | 31 /** |
| 34 * An object that can handle GET requests. | 32 * An object that can handle GET requests. |
| 35 */ | 33 */ |
| 36 GetHandler getHandler; | 34 GetHandler getHandler; |
| 37 | 35 |
| 38 /** | 36 /** |
| 39 * An object that can handle GET requests when the new task model is in use. | |
| 40 */ | |
| 41 newHandler.GetHandler newGetHandler; | |
| 42 | |
| 43 /** | |
| 44 * Future that is completed with the HTTP server once it is running. | 37 * Future that is completed with the HTTP server once it is running. |
| 45 */ | 38 */ |
| 46 Future<HttpServer> _server; | 39 Future<HttpServer> _server; |
| 47 | 40 |
| 48 /** | 41 /** |
| 49 * Last PRINT_BUFFER_LENGTH lines printed. | 42 * Last PRINT_BUFFER_LENGTH lines printed. |
| 50 */ | 43 */ |
| 51 List<String> _printBuffer = <String>[]; | 44 List<String> _printBuffer = <String>[]; |
| 52 | 45 |
| 53 /** | 46 /** |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 } catch (exception) { | 75 } catch (exception) { |
| 83 // We were unable to start the server, and there's nothing we can do about | 76 // We were unable to start the server, and there's nothing we can do about |
| 84 // it. | 77 // it. |
| 85 } | 78 } |
| 86 } | 79 } |
| 87 | 80 |
| 88 /** | 81 /** |
| 89 * Handle a GET request received by the HTTP server. | 82 * Handle a GET request received by the HTTP server. |
| 90 */ | 83 */ |
| 91 void _handleGetRequest(HttpRequest request) { | 84 void _handleGetRequest(HttpRequest request) { |
| 92 if (AnalysisEngine.instance.useTaskModel) { | 85 if (getHandler == null) { |
| 93 if (newGetHandler == null) { | 86 getHandler = new GetHandler(socketServer, _printBuffer); |
| 94 newGetHandler = new newHandler.GetHandler(socketServer, _printBuffer); | |
| 95 } | |
| 96 newGetHandler.handleGetRequest(request); | |
| 97 } else { | |
| 98 if (getHandler == null) { | |
| 99 getHandler = new GetHandler(socketServer, _printBuffer); | |
| 100 } | |
| 101 getHandler.handleGetRequest(request); | |
| 102 } | 87 } |
| 88 getHandler.handleGetRequest(request); |
| 103 } | 89 } |
| 104 | 90 |
| 105 /** | 91 /** |
| 106 * Attach a listener to a newly created HTTP server. | 92 * Attach a listener to a newly created HTTP server. |
| 107 */ | 93 */ |
| 108 void _handleServer(HttpServer httServer) { | 94 void _handleServer(HttpServer httServer) { |
| 109 httServer.listen((HttpRequest request) { | 95 httServer.listen((HttpRequest request) { |
| 110 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; | 96 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; |
| 111 if (updateValues != null && updateValues.indexOf('websocket') >= 0) { | 97 if (updateValues != null && updateValues.indexOf('websocket') >= 0) { |
| 112 WebSocketTransformer.upgrade(request).then((WebSocket websocket) { | 98 WebSocketTransformer.upgrade(request).then((WebSocket websocket) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 135 */ | 121 */ |
| 136 void _returnUnknownRequest(HttpRequest request) { | 122 void _returnUnknownRequest(HttpRequest request) { |
| 137 HttpResponse response = request.response; | 123 HttpResponse response = request.response; |
| 138 response.statusCode = HttpStatus.NOT_FOUND; | 124 response.statusCode = HttpStatus.NOT_FOUND; |
| 139 response.headers.contentType = | 125 response.headers.contentType = |
| 140 new ContentType("text", "plain", charset: "utf-8"); | 126 new ContentType("text", "plain", charset: "utf-8"); |
| 141 response.write('Not found'); | 127 response.write('Not found'); |
| 142 response.close(); | 128 response.close(); |
| 143 } | 129 } |
| 144 } | 130 } |
| OLD | NEW |