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 analysis_server.src.server.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/socket_server.dart'; | 11 import 'package:analysis_server/src/socket_server.dart'; |
12 import 'package:analysis_server/src/status/get_handler.dart'; | 12 import 'package:analysis_server/src/status/get_handler.dart'; |
| 13 import 'package:analysis_server/src/status/get_handler2.dart'; |
13 | 14 |
14 /** | 15 /** |
15 * Instances of the class [HttpServer] implement a simple HTTP server. The | 16 * 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 | 17 * primary responsibility of this server is to listen for an UPGRADE request and |
17 * to start an analysis server. | 18 * to start an analysis server. |
18 */ | 19 */ |
19 class HttpAnalysisServer { | 20 class HttpAnalysisServer { |
20 /** | 21 /** |
21 * Number of lines of print output to capture. | 22 * Number of lines of print output to capture. |
22 */ | 23 */ |
23 static const int MAX_PRINT_BUFFER_LENGTH = 1000; | 24 static const int MAX_PRINT_BUFFER_LENGTH = 1000; |
24 | 25 |
25 /** | 26 /** |
26 * An object that can handle either a WebSocket connection or a connection | 27 * An object that can handle either a WebSocket connection or a connection |
27 * to the client over stdio. | 28 * to the client over stdio. |
28 */ | 29 */ |
29 SocketServer socketServer; | 30 SocketServer socketServer; |
30 | 31 |
31 /** | 32 /** |
32 * An object that can handle GET requests. | 33 * An object that can handle GET requests. |
33 */ | 34 */ |
34 GetHandler getHandler; | 35 AbstractGetHandler getHandler; |
35 | 36 |
36 /** | 37 /** |
37 * Future that is completed with the HTTP server once it is running. | 38 * Future that is completed with the HTTP server once it is running. |
38 */ | 39 */ |
39 Future<HttpServer> _server; | 40 Future<HttpServer> _server; |
40 | 41 |
41 /** | 42 /** |
42 * Last PRINT_BUFFER_LENGTH lines printed. | 43 * Last PRINT_BUFFER_LENGTH lines printed. |
43 */ | 44 */ |
44 List<String> _printBuffer = <String>[]; | 45 List<String> _printBuffer = <String>[]; |
(...skipping 26 matching lines...) Expand all Loading... |
71 void serveHttp(int port) { | 72 void serveHttp(int port) { |
72 _server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); | 73 _server = HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port); |
73 _server.then(_handleServer).catchError((_) {/* Ignore errors. */}); | 74 _server.then(_handleServer).catchError((_) {/* Ignore errors. */}); |
74 } | 75 } |
75 | 76 |
76 /** | 77 /** |
77 * Handle a GET request received by the HTTP server. | 78 * Handle a GET request received by the HTTP server. |
78 */ | 79 */ |
79 void _handleGetRequest(HttpRequest request) { | 80 void _handleGetRequest(HttpRequest request) { |
80 if (getHandler == null) { | 81 if (getHandler == null) { |
81 getHandler = new GetHandler(socketServer, _printBuffer); | 82 if (socketServer.analysisServer.options.enableNewAnalysisDriver) { |
| 83 getHandler = new GetHandler2(socketServer, _printBuffer); |
| 84 } else { |
| 85 getHandler = new GetHandler(socketServer, _printBuffer); |
| 86 } |
82 } | 87 } |
83 getHandler.handleGetRequest(request); | 88 getHandler.handleGetRequest(request); |
84 } | 89 } |
85 | 90 |
86 /** | 91 /** |
87 * Attach a listener to a newly created HTTP server. | 92 * Attach a listener to a newly created HTTP server. |
88 */ | 93 */ |
89 void _handleServer(HttpServer httpServer) { | 94 void _handleServer(HttpServer httpServer) { |
90 httpServer.listen((HttpRequest request) { | 95 httpServer.listen((HttpRequest request) { |
91 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; | 96 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; |
(...skipping 24 matching lines...) Expand all Loading... |
116 */ | 121 */ |
117 void _returnUnknownRequest(HttpRequest request) { | 122 void _returnUnknownRequest(HttpRequest request) { |
118 HttpResponse response = request.response; | 123 HttpResponse response = request.response; |
119 response.statusCode = HttpStatus.NOT_FOUND; | 124 response.statusCode = HttpStatus.NOT_FOUND; |
120 response.headers.contentType = | 125 response.headers.contentType = |
121 new ContentType("text", "plain", charset: "utf-8"); | 126 new ContentType("text", "plain", charset: "utf-8"); |
122 response.write('Not found'); | 127 response.write('Not found'); |
123 response.close(); | 128 response.close(); |
124 } | 129 } |
125 } | 130 } |
OLD | NEW |