OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 void _sendJSONResponse(HttpResponse response, Map responseData) { | 304 void _sendJSONResponse(HttpResponse response, Map responseData) { |
305 response.headers.set("Content-Type", "application/json; charset=UTF-8"); | 305 response.headers.set("Content-Type", "application/json; charset=UTF-8"); |
306 response.addString(json.stringify(responseData)); | 306 response.addString(json.stringify(responseData)); |
307 response.close(); | 307 response.close(); |
308 } | 308 } |
309 | 309 |
310 void redirectPageHandler(HttpRequest request, | 310 void redirectPageHandler(HttpRequest request, |
311 HttpResponse response, | 311 HttpResponse response, |
312 String redirectPath) { | 312 String redirectPath) { |
313 if (_redirectPage == null) { | 313 if (_redirectPage == null) { |
314 _redirectPage = redirectPageHtml.charCodes; | 314 _redirectPage = redirectPageHtml.codeUnits; |
315 } | 315 } |
316 response.statusCode = HttpStatus.FOUND; | 316 response.statusCode = HttpStatus.FOUND; |
317 response.headers.set( | 317 response.headers.set( |
318 "Location", "http://$_host:$_port/${redirectPath}"); | 318 "Location", "http://$_host:$_port/${redirectPath}"); |
319 response.contentLength = _redirectPage.length; | 319 response.contentLength = _redirectPage.length; |
320 response.add(_redirectPage); | 320 response.add(_redirectPage); |
321 response.close(); | 321 response.close(); |
322 } | 322 } |
323 | 323 |
324 // Serve the content of a file. | 324 // Serve the content of a file. |
(...skipping 23 matching lines...) Expand all Loading... |
348 file.openRead().pipe(response); | 348 file.openRead().pipe(response); |
349 } else { | 349 } else { |
350 print("File not found: $fileName"); | 350 print("File not found: $fileName"); |
351 _notFoundHandler(request, response); | 351 _notFoundHandler(request, response); |
352 } | 352 } |
353 } | 353 } |
354 | 354 |
355 // Serve the not found page. | 355 // Serve the not found page. |
356 void _notFoundHandler(HttpRequest request, HttpResponse response) { | 356 void _notFoundHandler(HttpRequest request, HttpResponse response) { |
357 if (_notFoundPage == null) { | 357 if (_notFoundPage == null) { |
358 _notFoundPage = notFoundPageHtml.charCodes; | 358 _notFoundPage = notFoundPageHtml.codeUnits; |
359 } | 359 } |
360 response.statusCode = HttpStatus.NOT_FOUND; | 360 response.statusCode = HttpStatus.NOT_FOUND; |
361 response.headers.set("Content-Type", "text/html; charset=UTF-8"); | 361 response.headers.set("Content-Type", "text/html; charset=UTF-8"); |
362 response.contentLength = _notFoundPage.length; | 362 response.contentLength = _notFoundPage.length; |
363 response.add(_notFoundPage); | 363 response.add(_notFoundPage); |
364 response.close(); | 364 response.close(); |
365 } | 365 } |
366 | 366 |
367 // Unexpected protocol data. | 367 // Unexpected protocol data. |
368 void _protocolError(HttpRequest request, HttpResponse response) { | 368 void _protocolError(HttpRequest request, HttpResponse response) { |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 int _timeRange; | 674 int _timeRange; |
675 List<int> _buckets; | 675 List<int> _buckets; |
676 int _currentBucket; | 676 int _currentBucket; |
677 int _currentBucketTime; | 677 int _currentBucketTime; |
678 num _bucketTimeRange; | 678 num _bucketTimeRange; |
679 int _sum; | 679 int _sum; |
680 } | 680 } |
OLD | NEW |