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