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