Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(498)

Side by Side Diff: pkg/analysis_server/lib/src/server/http_server.dart

Issue 1573343003: HttpServer start async fix (#25394). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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';
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 if (_printBuffer.length > MAX_PRINT_BUFFER_LENGTH) { 62 if (_printBuffer.length > MAX_PRINT_BUFFER_LENGTH) {
63 _printBuffer.removeRange( 63 _printBuffer.removeRange(
64 0, _printBuffer.length - MAX_PRINT_BUFFER_LENGTH); 64 0, _printBuffer.length - MAX_PRINT_BUFFER_LENGTH);
65 } 65 }
66 } 66 }
67 67
68 /** 68 /**
69 * Begin serving HTTP requests over the given port. 69 * Begin serving HTTP requests over the given port.
70 */ 70 */
71 void serveHttp(int port) { 71 void serveHttp(int port) {
72 try { 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);
75 } catch (exception) {
76 // We were unable to start the server, and there's nothing we can do about
77 // it.
78 }
79 } 74 }
80 75
81 /** 76 /**
82 * Handle a GET request received by the HTTP server. 77 * Handle a GET request received by the HTTP server.
83 */ 78 */
84 void _handleGetRequest(HttpRequest request) { 79 void _handleGetRequest(HttpRequest request) {
85 if (getHandler == null) { 80 if (getHandler == null) {
86 getHandler = new GetHandler(socketServer, _printBuffer); 81 getHandler = new GetHandler(socketServer, _printBuffer);
87 } 82 }
88 getHandler.handleGetRequest(request); 83 getHandler.handleGetRequest(request);
89 } 84 }
90 85
91 /** 86 /**
92 * Attach a listener to a newly created HTTP server. 87 * Attach a listener to a newly created HTTP server.
93 */ 88 */
94 void _handleServer(HttpServer httServer) { 89 void _handleServer(HttpServer httpServer) {
95 httServer.listen((HttpRequest request) { 90 httpServer.listen((HttpRequest request) {
96 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; 91 List<String> updateValues = request.headers[HttpHeaders.UPGRADE];
97 if (updateValues != null && updateValues.indexOf('websocket') >= 0) { 92 if (updateValues != null && updateValues.indexOf('websocket') >= 0) {
98 WebSocketTransformer.upgrade(request).then((WebSocket websocket) { 93 WebSocketTransformer.upgrade(request).then((WebSocket websocket) {
99 _handleWebSocket(websocket); 94 _handleWebSocket(websocket);
100 }); 95 });
101 } else if (request.method == 'GET') { 96 } else if (request.method == 'GET') {
102 _handleGetRequest(request); 97 _handleGetRequest(request);
103 } else { 98 } else {
104 _returnUnknownRequest(request); 99 _returnUnknownRequest(request);
105 } 100 }
(...skipping 15 matching lines...) Expand all
121 */ 116 */
122 void _returnUnknownRequest(HttpRequest request) { 117 void _returnUnknownRequest(HttpRequest request) {
123 HttpResponse response = request.response; 118 HttpResponse response = request.response;
124 response.statusCode = HttpStatus.NOT_FOUND; 119 response.statusCode = HttpStatus.NOT_FOUND;
125 response.headers.contentType = 120 response.headers.contentType =
126 new ContentType("text", "plain", charset: "utf-8"); 121 new ContentType("text", "plain", charset: "utf-8");
127 response.write('Not found'); 122 response.write('Not found');
128 response.close(); 123 response.close();
129 } 124 }
130 } 125 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698