| 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:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:analysis_server/src/analysis_server.dart'; | 9 import 'package:analysis_server/src/analysis_server.dart'; |
| 10 import 'package:analysis_server/src/channel.dart'; | 10 import 'package:analysis_server/src/channel.dart'; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 ArgResults results = parser.parse(args); | 68 ArgResults results = parser.parse(args); |
| 69 if (results[HELP_OPTION]) { | 69 if (results[HELP_OPTION]) { |
| 70 _printUsage(parser); | 70 _printUsage(parser); |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 if (results[PORT_OPTION] == null) { | 73 if (results[PORT_OPTION] == null) { |
| 74 print('Missing required port number'); | 74 print('Missing required port number'); |
| 75 print(''); | 75 print(''); |
| 76 _printUsage(parser); | 76 _printUsage(parser); |
| 77 exitCode = 1; |
| 77 return; | 78 return; |
| 78 } | 79 } |
| 79 | 80 |
| 80 try { | 81 try { |
| 81 int port = int.parse(results[PORT_OPTION]); | 82 int port = int.parse(results[PORT_OPTION]); |
| 82 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then(_handleServer); | 83 HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, port).then(_handleServer); |
| 83 print('Listening on port $port'); | 84 print('Listening on port $port'); |
| 84 } on FormatException { | 85 } on FormatException { |
| 85 print('Invalid port number: ${results[PORT_OPTION]}'); | 86 print('Invalid port number: ${results[PORT_OPTION]}'); |
| 86 print(''); | 87 print(''); |
| 87 _printUsage(parser); | 88 _printUsage(parser); |
| 89 exitCode = 1; |
| 88 return; | 90 return; |
| 89 } | 91 } |
| 90 } | 92 } |
| 91 | 93 |
| 92 /** | 94 /** |
| 93 * Attach a listener to a newly created HTTP server. | 95 * Attach a listener to a newly created HTTP server. |
| 94 */ | 96 */ |
| 95 void _handleServer(HttpServer server) { | 97 void _handleServer(HttpServer server) { |
| 96 server.listen((HttpRequest request) { | 98 server.listen((HttpRequest request) { |
| 97 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; | 99 List<String> updateValues = request.headers[HttpHeaders.UPGRADE]; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 * server. | 174 * server. |
| 173 */ | 175 */ |
| 174 void _returnUnknownRequest(HttpRequest request) { | 176 void _returnUnknownRequest(HttpRequest request) { |
| 175 HttpResponse response = request.response; | 177 HttpResponse response = request.response; |
| 176 response.statusCode = HttpStatus.NOT_FOUND; | 178 response.statusCode = HttpStatus.NOT_FOUND; |
| 177 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); | 179 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/plain"); |
| 178 response.write('Not found'); | 180 response.write('Not found'); |
| 179 response.close(); | 181 response.close(); |
| 180 } | 182 } |
| 181 } | 183 } |
| OLD | NEW |