This commit is contained in:
Tobe O 2018-10-20 20:24:44 -04:00
parent 2e8573cd96
commit e403f5da2d
5 changed files with 12 additions and 14 deletions

View file

@ -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.

View file

@ -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<int> 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);
}
}
}

View file

@ -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);

View file

@ -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 <thosakwe@gmail.com>
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:

View file

@ -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}');