| 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 get.handler; | 5 library get.handler; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 * state. | 38 * state. |
| 39 */ | 39 */ |
| 40 static const String CACHE_STATE_PATH = '/cache_state'; | 40 static const String CACHE_STATE_PATH = '/cache_state'; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * The path used to request code completion information. | 43 * The path used to request code completion information. |
| 44 */ | 44 */ |
| 45 static const String COMPLETION_PATH = '/completion'; | 45 static const String COMPLETION_PATH = '/completion'; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * The path used to request an overlay contents. |
| 49 */ |
| 50 static const String OVERLAY_PATH = '/overlay'; |
| 51 |
| 52 /** |
| 48 * The path used to request overlays information. | 53 * The path used to request overlays information. |
| 49 */ | 54 */ |
| 50 static const String OVERLAYS_PATH = '/overlays'; | 55 static const String OVERLAYS_PATH = '/overlays'; |
| 51 | 56 |
| 52 /** | 57 /** |
| 53 * Query parameter used to represent the cache state to search for, when | 58 * Query parameter used to represent the cache state to search for, when |
| 54 * accessing [CACHE_STATE_PATH]. | 59 * accessing [CACHE_STATE_PATH]. |
| 55 */ | 60 */ |
| 56 static const String STATE_QUERY_PARAM = 'state'; | 61 static const String STATE_QUERY_PARAM = 'state'; |
| 57 | 62 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 * The socket server whose status is to be reported on. | 82 * The socket server whose status is to be reported on. |
| 78 */ | 83 */ |
| 79 SocketServer _server; | 84 SocketServer _server; |
| 80 | 85 |
| 81 /** | 86 /** |
| 82 * Buffer containing strings printed by the analysis server. | 87 * Buffer containing strings printed by the analysis server. |
| 83 */ | 88 */ |
| 84 List<String> _printBuffer; | 89 List<String> _printBuffer; |
| 85 | 90 |
| 86 /** | 91 /** |
| 92 * Contents of overlay files. |
| 93 */ |
| 94 final Map<int, String> _overlayContents = <int, String>{}; |
| 95 |
| 96 /** |
| 87 * Initialize a newly created handler for GET requests. | 97 * Initialize a newly created handler for GET requests. |
| 88 */ | 98 */ |
| 89 GetHandler(this._server, this._printBuffer); | 99 GetHandler(this._server, this._printBuffer); |
| 90 | 100 |
| 91 /** | 101 /** |
| 92 * Handle a GET request received by the HTTP server. | 102 * Handle a GET request received by the HTTP server. |
| 93 */ | 103 */ |
| 94 void handleGetRequest(HttpRequest request) { | 104 void handleGetRequest(HttpRequest request) { |
| 95 String path = request.uri.path; | 105 String path = request.uri.path; |
| 96 if (path == STATUS_PATH) { | 106 if (path == STATUS_PATH) { |
| 97 _returnServerStatus(request); | 107 _returnServerStatus(request); |
| 98 } else if (path == CACHE_STATE_PATH) { | 108 } else if (path == CACHE_STATE_PATH) { |
| 99 _returnCacheState(request); | 109 _returnCacheState(request); |
| 100 } else if (path == CACHE_ENTRY_PATH) { | 110 } else if (path == CACHE_ENTRY_PATH) { |
| 101 _returnCacheEntry(request); | 111 _returnCacheEntry(request); |
| 102 } else if (path == COMPLETION_PATH) { | 112 } else if (path == COMPLETION_PATH) { |
| 103 _returnCompletionInfo(request); | 113 _returnCompletionInfo(request); |
| 114 } else if (path == OVERLAY_PATH) { |
| 115 _returnOverlayContents(request); |
| 104 } else if (path == OVERLAYS_PATH) { | 116 } else if (path == OVERLAYS_PATH) { |
| 105 _returnOverlaysInfo(request); | 117 _returnOverlaysInfo(request); |
| 106 } else { | 118 } else { |
| 107 _returnUnknownRequest(request); | 119 _returnUnknownRequest(request); |
| 108 } | 120 } |
| 109 } | 121 } |
| 110 | 122 |
| 111 /** | 123 /** |
| 112 * Create a link to [path] with query parameters [params], with inner HTML | 124 * Create a link to [path] with query parameters [params], with inner HTML |
| 113 * [innerHtml]. | 125 * [innerHtml]. |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 response.write('<head>'); | 383 response.write('<head>'); |
| 372 response.write('<title>Dart Analysis Server - Failure</title>'); | 384 response.write('<title>Dart Analysis Server - Failure</title>'); |
| 373 response.write('</head>'); | 385 response.write('</head>'); |
| 374 response.write('<body>'); | 386 response.write('<body>'); |
| 375 response.write(HTML_ESCAPE.convert(message)); | 387 response.write(HTML_ESCAPE.convert(message)); |
| 376 response.write('</body>'); | 388 response.write('</body>'); |
| 377 response.write('</html>'); | 389 response.write('</html>'); |
| 378 response.close(); | 390 response.close(); |
| 379 } | 391 } |
| 380 | 392 |
| 393 void _returnOverlayContents(HttpRequest request) { |
| 394 String idString = request.requestedUri.queryParameters['id']; |
| 395 int id = int.parse(idString); |
| 396 String contents = _overlayContents[id]; |
| 397 HttpResponse response = request.response; |
| 398 response.statusCode = HttpStatus.OK; |
| 399 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 400 response.write('<html>'); |
| 401 response.write('<head>'); |
| 402 response.write('<title>Dart Analysis Server - Overlay</title>'); |
| 403 response.write('</head>'); |
| 404 response.write('<body>'); |
| 405 response.write('<pre>${HTML_ESCAPE.convert(contents)}</pre>'); |
| 406 response.write('</body>'); |
| 407 response.write('</html>'); |
| 408 response.close(); |
| 409 } |
| 410 |
| 381 /** | 411 /** |
| 382 * Return a response displaying overlays information. | 412 * Return a response displaying overlays information. |
| 383 */ | 413 */ |
| 384 void _returnOverlaysInfo(HttpRequest request) { | 414 void _returnOverlaysInfo(HttpRequest request) { |
| 385 AnalysisServer analysisServer = _server.analysisServer; | 415 AnalysisServer analysisServer = _server.analysisServer; |
| 386 if (analysisServer == null) { | 416 if (analysisServer == null) { |
| 387 return _returnFailure(request, 'Analysis server is not running'); | 417 return _returnFailure(request, 'Analysis server is not running'); |
| 388 } | 418 } |
| 389 HttpResponse response = request.response; | 419 HttpResponse response = request.response; |
| 390 response.statusCode = HttpStatus.OK; | 420 response.statusCode = HttpStatus.OK; |
| 391 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); | 421 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 392 response.write('<html>'); | 422 response.write('<html>'); |
| 393 response.write('<head>'); | 423 response.write('<head>'); |
| 394 response.write('<title>Dart Analysis Server - Overlays</title>'); | 424 response.write('<title>Dart Analysis Server - Overlays</title>'); |
| 395 response.write('</head>'); | 425 response.write('</head>'); |
| 396 response.write('<body>'); | 426 response.write('<body>'); |
| 397 response.write('<h1>Dart Analysis Server - Overlays</h1>'); | 427 response.write('<h1>Dart Analysis Server - Overlays</h1>'); |
| 398 response.write('<table border="1">'); | 428 response.write('<table border="1">'); |
| 399 int count = 0; | 429 int count = 0; |
| 430 _overlayContents.clear(); |
| 400 analysisServer.folderMap.forEach((_, AnalysisContextImpl context) { | 431 analysisServer.folderMap.forEach((_, AnalysisContextImpl context) { |
| 401 context.visitContentCache((Source source, int stamp, String contents) { | 432 context.visitContentCache((Source source, int stamp, String contents) { |
| 402 count++; | 433 count++; |
| 403 response.write('<tr>'); | 434 response.write('<tr>'); |
| 404 response.write('<td><pre>${HTML_ESCAPE.convert('$source')}</pre></td>'); | 435 String linkRef = '$OVERLAY_PATH?id=$count'; |
| 436 String linkText = HTML_ESCAPE.convert(source.toString()); |
| 437 response.write('<td><a href="$linkRef">$linkText</a></td>'); |
| 405 response.write( | 438 response.write( |
| 406 '<td>${new DateTime.fromMillisecondsSinceEpoch(stamp)}</td>'); | 439 '<td>${new DateTime.fromMillisecondsSinceEpoch(stamp)}</td>'); |
| 407 response.write('</tr>'); | 440 response.write('</tr>'); |
| 441 _overlayContents[count] = contents; |
| 408 }); | 442 }); |
| 409 }); | 443 }); |
| 410 response.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); | 444 response.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); |
| 411 response.write('</table>'); | 445 response.write('</table>'); |
| 412 response.write('</body>'); | 446 response.write('</body>'); |
| 413 response.write('</html>'); | 447 response.write('</html>'); |
| 414 response.close(); | 448 response.close(); |
| 415 } | 449 } |
| 416 | 450 |
| 417 /** | 451 /** |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 if (header) { | 670 if (header) { |
| 637 response.write('</th>'); | 671 response.write('</th>'); |
| 638 } else { | 672 } else { |
| 639 response.write('</td>'); | 673 response.write('</td>'); |
| 640 } | 674 } |
| 641 } | 675 } |
| 642 | 676 |
| 643 response.write('</tr>'); | 677 response.write('</tr>'); |
| 644 } | 678 } |
| 645 } | 679 } |
| OLD | NEW |