From e403f5da2d97d274f7247855ab2b456951281348 Mon Sep 17 00:00:00 2001 From: Tobe O Date: Sat, 20 Oct 2018 20:24:44 -0400 Subject: [PATCH] 2.0.0 --- CHANGELOG.md | 1 + lib/src/cache.dart | 14 +++++--------- lib/src/virtual_directory.dart | 3 ++- pubspec.yaml | 5 ++--- test/cache_test.dart | 3 ++- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 389d8478..66600ff0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 2.0.0 * Upgrade dependencies to Angel 2 + file@5. * Replace `useStream` with `useBuffer`. +* Remove `package:intl`, just use `HttpDate` instead. # 1.3.0+1 * Dart 2 fixes. diff --git a/lib/src/cache.dart b/lib/src/cache.dart index acb52b06..ae84cc93 100644 --- a/lib/src/cache.dart +++ b/lib/src/cache.dart @@ -1,16 +1,12 @@ import 'dart:async'; +import 'dart:io' show HttpDate; import 'package:angel_framework/angel_framework.dart'; import 'package:dart2_constant/convert.dart'; import 'package:file/file.dart'; -import 'package:intl/intl.dart'; +//import 'package:intl/intl.dart'; import 'package:mime/mime.dart'; import 'virtual_directory.dart'; -final DateFormat _fmt = new DateFormat('EEE, d MMM yyyy HH:mm:ss'); - -/// Formats a date (converted to UTC), ex: `Sun, 03 May 2015 23:02:37 GMT`. -String formatDateForHttp(DateTime dt) => _fmt.format(dt.toUtc()) + ' GMT'; - /// Generates a weak ETag from the given buffer. String weakEtag(List buf) { return 'W/${buf.length}' + base64Url.encode(buf.take(50).toList()); @@ -59,7 +55,7 @@ class CachingVirtualDirectory extends VirtualDirectory { this.onlyInProduction: false, this.useEtags: true, bool allowDirectoryListing, - bool useBuffer, + bool useBuffer: false, String publicPath, callback(File file, RequestContext req, ResponseContext res)}) : super(app, fileSystem, @@ -150,11 +146,11 @@ class CachingVirtualDirectory extends VirtualDirectory { res.headers ..['cache-control'] = '$privacy, max-age=${maxAge ?? 0}' - ..['last-modified'] = formatDateForHttp(modified); + ..['last-modified'] = HttpDate.format(modified); if (maxAge != null) { var expiry = new DateTime.now().add(new Duration(seconds: maxAge ?? 0)); - res.headers['expires'] = formatDateForHttp(expiry); + res.headers['expires'] = HttpDate.format(expiry); } } } diff --git a/lib/src/virtual_directory.dart b/lib/src/virtual_directory.dart index 1ba07ce9..fc90fe31 100644 --- a/lib/src/virtual_directory.dart +++ b/lib/src/virtual_directory.dart @@ -58,7 +58,7 @@ class VirtualDirectory { this.publicPath: '/', this.callback, this.allowDirectoryListing: false, - this.useBuffer: true}) { + this.useBuffer: false}) { _prefix = publicPath.replaceAll(_straySlashes, ''); if (source != null) { _source = source; @@ -230,6 +230,7 @@ class VirtualDirectory { res.contentType = new MediaType.parse(type); if (useBuffer == true) { + res.useBuffer(); await res.sendFile(file); } else { await res.streamFile(file); diff --git a/pubspec.yaml b/pubspec.yaml index c30ec1c3..b8e5a40f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,13 @@ name: angel_static -description: Static server middleware for Angel. +description: Static server middleware for Angel. Use this to serve files to users. environment: sdk: ">=1.8.0 <3.0.0" homepage: https://github.com/angel-dart/static author: Tobe O -version: 2.0.0-alpha +version: 2.0.0 dependencies: angel_framework: ^2.0.0-alpha file: ^5.0.0 - intl: ">=0.0.0 <1.0.0" mime: ^0.9.3 path: ^1.4.2 dev_dependencies: diff --git a/test/cache_test.dart b/test/cache_test.dart index 8fea55cc..c767cb58 100644 --- a/test/cache_test.dart +++ b/test/cache_test.dart @@ -1,3 +1,4 @@ +import 'dart:io' show HttpDate; import 'package:angel_framework/angel_framework.dart'; import 'package:angel_static/angel_static.dart'; import 'package:file/file.dart'; @@ -61,7 +62,7 @@ main() { test('if-modified-since', () async { var response = await client.get("$url", headers: { 'if-modified-since': - formatDateForHttp(new DateTime.now().add(new Duration(days: 365))) + HttpDate.format(new DateTime.now().add(new Duration(days: 365))) }); print('Response status: ${response.statusCode}');