OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 chat_server; | 5 library chat_server; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:math'; | 10 import 'dart:math'; |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 void _sendJSONResponse(HttpResponse response, Map responseData) { | 310 void _sendJSONResponse(HttpResponse response, Map responseData) { |
311 response.headers.set("Content-Type", "application/json; charset=UTF-8"); | 311 response.headers.set("Content-Type", "application/json; charset=UTF-8"); |
312 response.outputStream.writeString(json.stringify(responseData)); | 312 response.outputStream.writeString(json.stringify(responseData)); |
313 response.outputStream.close(); | 313 response.outputStream.close(); |
314 } | 314 } |
315 | 315 |
316 void redirectPageHandler(HttpRequest request, | 316 void redirectPageHandler(HttpRequest request, |
317 HttpResponse response, | 317 HttpResponse response, |
318 String redirectPath) { | 318 String redirectPath) { |
319 if (_redirectPage == null) { | 319 if (_redirectPage == null) { |
320 _redirectPage = redirectPageHtml.charCodes; | 320 _redirectPage = redirectPageHtml.codeUnits; |
321 } | 321 } |
322 response.statusCode = HttpStatus.FOUND; | 322 response.statusCode = HttpStatus.FOUND; |
323 response.headers.set( | 323 response.headers.set( |
324 "Location", "http://$_host:$_port/${redirectPath}"); | 324 "Location", "http://$_host:$_port/${redirectPath}"); |
325 response.contentLength = _redirectPage.length; | 325 response.contentLength = _redirectPage.length; |
326 response.outputStream.write(_redirectPage); | 326 response.outputStream.write(_redirectPage); |
327 response.outputStream.close(); | 327 response.outputStream.close(); |
328 } | 328 } |
329 | 329 |
330 // Serve the content of a file. | 330 // Serve the content of a file. |
(...skipping 23 matching lines...) Expand all Loading... |
354 file.openInputStream().pipe(response.outputStream); | 354 file.openInputStream().pipe(response.outputStream); |
355 } else { | 355 } else { |
356 print("File not found: $fileName"); | 356 print("File not found: $fileName"); |
357 _notFoundHandler(request, response); | 357 _notFoundHandler(request, response); |
358 } | 358 } |
359 } | 359 } |
360 | 360 |
361 // Serve the not found page. | 361 // Serve the not found page. |
362 void _notFoundHandler(HttpRequest request, HttpResponse response) { | 362 void _notFoundHandler(HttpRequest request, HttpResponse response) { |
363 if (_notFoundPage == null) { | 363 if (_notFoundPage == null) { |
364 _notFoundPage = notFoundPageHtml.charCodes; | 364 _notFoundPage = notFoundPageHtml.codeUnits; |
365 } | 365 } |
366 response.statusCode = HttpStatus.NOT_FOUND; | 366 response.statusCode = HttpStatus.NOT_FOUND; |
367 response.headers.set("Content-Type", "text/html; charset=UTF-8"); | 367 response.headers.set("Content-Type", "text/html; charset=UTF-8"); |
368 response.contentLength = _notFoundPage.length; | 368 response.contentLength = _notFoundPage.length; |
369 response.outputStream.write(_notFoundPage); | 369 response.outputStream.write(_notFoundPage); |
370 response.outputStream.close(); | 370 response.outputStream.close(); |
371 } | 371 } |
372 | 372 |
373 // Unexpected protocol data. | 373 // Unexpected protocol data. |
374 void _protocolError(HttpRequest request, HttpResponse response) { | 374 void _protocolError(HttpRequest request, HttpResponse response) { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 } | 686 } |
687 } | 687 } |
688 | 688 |
689 int _timeRange; | 689 int _timeRange; |
690 List<int> _buckets; | 690 List<int> _buckets; |
691 int _currentBucket; | 691 int _currentBucket; |
692 int _currentBucketTime; | 692 int _currentBucketTime; |
693 num _bucketTimeRange; | 693 num _bucketTimeRange; |
694 int _sum; | 694 int _sum; |
695 } | 695 } |
OLD | NEW |