2.0.0
This commit is contained in:
parent
2e8573cd96
commit
e403f5da2d
5 changed files with 12 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
# 2.0.0
|
# 2.0.0
|
||||||
* Upgrade dependencies to Angel 2 + file@5.
|
* Upgrade dependencies to Angel 2 + file@5.
|
||||||
* Replace `useStream` with `useBuffer`.
|
* Replace `useStream` with `useBuffer`.
|
||||||
|
* Remove `package:intl`, just use `HttpDate` instead.
|
||||||
|
|
||||||
# 1.3.0+1
|
# 1.3.0+1
|
||||||
* Dart 2 fixes.
|
* Dart 2 fixes.
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io' show HttpDate;
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:dart2_constant/convert.dart';
|
import 'package:dart2_constant/convert.dart';
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
import 'package:intl/intl.dart';
|
//import 'package:intl/intl.dart';
|
||||||
import 'package:mime/mime.dart';
|
import 'package:mime/mime.dart';
|
||||||
import 'virtual_directory.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.
|
/// Generates a weak ETag from the given buffer.
|
||||||
String weakEtag(List<int> buf) {
|
String weakEtag(List<int> buf) {
|
||||||
return 'W/${buf.length}' + base64Url.encode(buf.take(50).toList());
|
return 'W/${buf.length}' + base64Url.encode(buf.take(50).toList());
|
||||||
|
@ -59,7 +55,7 @@ class CachingVirtualDirectory extends VirtualDirectory {
|
||||||
this.onlyInProduction: false,
|
this.onlyInProduction: false,
|
||||||
this.useEtags: true,
|
this.useEtags: true,
|
||||||
bool allowDirectoryListing,
|
bool allowDirectoryListing,
|
||||||
bool useBuffer,
|
bool useBuffer: false,
|
||||||
String publicPath,
|
String publicPath,
|
||||||
callback(File file, RequestContext req, ResponseContext res)})
|
callback(File file, RequestContext req, ResponseContext res)})
|
||||||
: super(app, fileSystem,
|
: super(app, fileSystem,
|
||||||
|
@ -150,11 +146,11 @@ class CachingVirtualDirectory extends VirtualDirectory {
|
||||||
|
|
||||||
res.headers
|
res.headers
|
||||||
..['cache-control'] = '$privacy, max-age=${maxAge ?? 0}'
|
..['cache-control'] = '$privacy, max-age=${maxAge ?? 0}'
|
||||||
..['last-modified'] = formatDateForHttp(modified);
|
..['last-modified'] = HttpDate.format(modified);
|
||||||
|
|
||||||
if (maxAge != null) {
|
if (maxAge != null) {
|
||||||
var expiry = new DateTime.now().add(new Duration(seconds: maxAge ?? 0));
|
var expiry = new DateTime.now().add(new Duration(seconds: maxAge ?? 0));
|
||||||
res.headers['expires'] = formatDateForHttp(expiry);
|
res.headers['expires'] = HttpDate.format(expiry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class VirtualDirectory {
|
||||||
this.publicPath: '/',
|
this.publicPath: '/',
|
||||||
this.callback,
|
this.callback,
|
||||||
this.allowDirectoryListing: false,
|
this.allowDirectoryListing: false,
|
||||||
this.useBuffer: true}) {
|
this.useBuffer: false}) {
|
||||||
_prefix = publicPath.replaceAll(_straySlashes, '');
|
_prefix = publicPath.replaceAll(_straySlashes, '');
|
||||||
if (source != null) {
|
if (source != null) {
|
||||||
_source = source;
|
_source = source;
|
||||||
|
@ -230,6 +230,7 @@ class VirtualDirectory {
|
||||||
res.contentType = new MediaType.parse(type);
|
res.contentType = new MediaType.parse(type);
|
||||||
|
|
||||||
if (useBuffer == true) {
|
if (useBuffer == true) {
|
||||||
|
res.useBuffer();
|
||||||
await res.sendFile(file);
|
await res.sendFile(file);
|
||||||
} else {
|
} else {
|
||||||
await res.streamFile(file);
|
await res.streamFile(file);
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
name: angel_static
|
name: angel_static
|
||||||
description: Static server middleware for Angel.
|
description: Static server middleware for Angel. Use this to serve files to users.
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=1.8.0 <3.0.0"
|
sdk: ">=1.8.0 <3.0.0"
|
||||||
homepage: https://github.com/angel-dart/static
|
homepage: https://github.com/angel-dart/static
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
version: 2.0.0-alpha
|
version: 2.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_framework: ^2.0.0-alpha
|
angel_framework: ^2.0.0-alpha
|
||||||
file: ^5.0.0
|
file: ^5.0.0
|
||||||
intl: ">=0.0.0 <1.0.0"
|
|
||||||
mime: ^0.9.3
|
mime: ^0.9.3
|
||||||
path: ^1.4.2
|
path: ^1.4.2
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'dart:io' show HttpDate;
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_static/angel_static.dart';
|
import 'package:angel_static/angel_static.dart';
|
||||||
import 'package:file/file.dart';
|
import 'package:file/file.dart';
|
||||||
|
@ -61,7 +62,7 @@ main() {
|
||||||
test('if-modified-since', () async {
|
test('if-modified-since', () async {
|
||||||
var response = await client.get("$url", headers: {
|
var response = await client.get("$url", headers: {
|
||||||
'if-modified-since':
|
'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}');
|
print('Response status: ${response.statusCode}');
|
||||||
|
|
Loading…
Reference in a new issue