Skip to content

Commit

Permalink
Cleanup (flutter#20)
Browse files Browse the repository at this point in the history
* dartfmt
* use new Travis CI Dart tasks
* A couple of lint fixes
* use recommended name for analysis_options
  • Loading branch information
kevmoo authored Jun 8, 2017
1 parent b6e30c8 commit 70112b6
Show file tree
Hide file tree
Showing 15 changed files with 56 additions and 54 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
language: dart
sudo: false
dart:
- stable
- dev
script: ./tool/travis.sh
- stable
- 1.23.0
- 1.22.1
cache:
directories:
- $HOME/.pub-cache
dart_task:
- test: --platform vm
- dartfmt
- dartanalyzer
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
* The preferred top-level method is now `createStaticHandler`. `getHandler` is deprecated.
* Set `content-type` header if the mime type of the requested file can be determined from the file extension.
* Respond with `304-Not modified` against `IF-MODIFIED-SINCE` request header.
* Better error when provided a non-existant `fileSystemPath`.
* Better error when provided a non-existent `fileSystemPath`.
* Added `example/example_server.dart`.

## 0.1.1+1
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
`shelf_static` is a `Handler` for the Dart `shelf` package.

[![Build Status](https://travis-ci.org/dart-lang/shelf_static.svg?branch=master)](https://travis-ci.org/dart-lang/shelf_static?branch=master)
[![Coverage Status](https://coveralls.io/repos/dart-lang/shelf_static/badge.svg?branch=master&service=github)](https://coveralls.io/github/dart-lang/shelf_static?branch=master)

### Example
```dart
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion example/example_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ArgParser _getParser() => new ArgParser()
abbr: 'f',
defaultsTo: false,
negatable: false,
help: 'List the files in the source directory instead of servering the default document - "$_defaultDoc".');
help: 'List the files in the source directory instead of serving the '
'default document - "$_defaultDoc".');

const _defaultDoc = 'index.html';
9 changes: 6 additions & 3 deletions lib/src/directory_listing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,12 @@ Response listDirectory(String fileSystemPath, String dirPath) {
controller.add(encoding.encode(string));
}

String heading = path.relative(dirPath, from: fileSystemPath);
if (heading == '.') heading = '/';
else heading = '/$heading/';
var heading = path.relative(dirPath, from: fileSystemPath);
if (heading == '.') {
heading = '/';
} else {
heading = '/$heading/';
}

add(_getHeader(sanitizer.convert(heading)));
new Directory(dirPath).list().listen((FileSystemEntity entity) {
Expand Down
9 changes: 5 additions & 4 deletions lib/src/static_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Handler createStaticHandler(String fileSystemPath,

var entityType = FileSystemEntity.typeSync(fsPath, followLinks: true);

File file = null;
File file;

if (entityType == FileSystemEntityType.FILE) {
file = new File(fsPath);
Expand Down Expand Up @@ -115,14 +115,15 @@ Handler createStaticHandler(String fileSystemPath,

String contentType;
if (useHeaderBytesForContentType) {
var length =
math.min(contentTypeResolver.magicNumbersMaxLength, file.lengthSync());
var length = math.min(
contentTypeResolver.magicNumbersMaxLength, file.lengthSync());

var byteSink = new ByteAccumulatorSink();

await file.openRead(0, length).listen(byteSink.add).asFuture();

contentType = contentTypeResolver.lookup(file.path, headerBytes: byteSink.bytes);
contentType =
contentTypeResolver.lookup(file.path, headerBytes: byteSink.bytes);
} else {
contentType = contentTypeResolver.lookup(file.path);
}
Expand Down
6 changes: 2 additions & 4 deletions test/alternative_root_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ void main() {
});

d.file('root.txt', 'root txt').create();
d
.dir('files', [
d.dir('files', [
d.file('test.txt', 'test txt content'),
d.file('with space.txt', 'with space content')
])
.create();
]).create();

currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
Expand Down
19 changes: 14 additions & 5 deletions test/basic_file_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'dart:convert';
import 'dart:io';

import 'package:http_parser/http_parser.dart';
import 'package:mime/mime.dart' as mime;
import 'package:path/path.dart' as p;
Expand Down Expand Up @@ -35,7 +36,8 @@ void main() {
r"OJE7pB/VXmF3CdseucmjxaAruR41Pl9p/Gbyoq5B9FeL2OR7zJ+3aC/X8QdQCyIArPs"
r"HkQAAAABJRU5ErkJggg==";

var webpBytesContent = r"UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAQAcJaQAA3AA/v3AgAA=";
var webpBytesContent =
r"UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAQAcJaQAA3AA/v3AgAA=";

d.dir('files', [
d.file('test.txt', 'test txt content'),
Expand Down Expand Up @@ -226,8 +228,16 @@ void main() {
test('header_bytes_test_webp should be image/webp', () {
schedule(() {
final mime.MimeTypeResolver resolver = new mime.MimeTypeResolver();
resolver.addMagicNumber(<int>[0x52,0x49,0x46,0x46,0x00,0x00,0x00,0x00,0x57,0x45,0x42,0x50], "image/webp",
mask: <int>[0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF]);
resolver.addMagicNumber(
<int>[
0x52, 0x49, 0x46, 0x46, 0x00, 0x00, //
0x00, 0x00, 0x57, 0x45, 0x42, 0x50
],
"image/webp",
mask: <int>[
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, //
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF
]);
final dynamic handler = createStaticHandler(d.defaultRoot,
useHeaderBytesForContentType: true, contentTypeResolver: resolver);

Expand All @@ -237,6 +247,5 @@ void main() {
});
});
});

});
}
6 changes: 2 additions & 4 deletions test/default_document_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ void main() {

d.file('index.html', '<html></html>').create();
d.file('root.txt', 'root txt').create();
d
.dir('files', [
d.dir('files', [
d.file('index.html', '<html><body>files</body></html>'),
d.file('with space.txt', 'with space content')
])
.create();
]).create();

currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
Expand Down
12 changes: 6 additions & 6 deletions test/directory_listing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ void main() {

d.file('index.html', '<html></html>').create();
d.file('root.txt', 'root txt').create();
d
.dir('files', [
d.dir('files', [
d.file('index.html', '<html><body>files</body></html>'),
d.file('with space.txt', 'with space content'),
d.dir('empty subfolder', []),
])
.create();
]).create();

currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
Expand Down Expand Up @@ -77,8 +75,10 @@ void main() {

return makeRequest(handler, '/files/empty subfolder').then((response) {
expect(response.statusCode, HttpStatus.MOVED_PERMANENTLY);
expect(response.headers, containsPair(HttpHeaders.LOCATION,
'http://localhost/files/empty%20subfolder/'));
expect(
response.headers,
containsPair(HttpHeaders.LOCATION,
'http://localhost/files/empty%20subfolder/'));
});
});
});
Expand Down
6 changes: 2 additions & 4 deletions test/get_handler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ void main() {
});

d.file('root.txt', 'root txt').create();
d
.dir('files', [
d.dir('files', [
d.file('test.txt', 'test txt content'),
d.file('with space.txt', 'with space content')
])
.create();
]).create();

currentSchedule.onComplete.schedule(() {
d.defaultRoot = null;
Expand Down
4 changes: 3 additions & 1 deletion test/symbolic_link_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ void main() {
});
});

d.dir('originals', [d.file('index.html', '<html></html>'),]).create();
d.dir('originals', [
d.file('index.html', '<html></html>'),
]).create();

d.dir('alt_root').create();

Expand Down
6 changes: 3 additions & 3 deletions test/test_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class _SecondResolutionDateTimeMatcher extends Matcher {
return datesEqualToSecond(_target, item);
}

Description describe(Description descirption) => descirption.add(
'Must be at the same moment as $_target with resolution '
'to the second.');
Description describe(Description description) =>
description.add('Must be at the same moment as $_target with resolution '
'to the second.');
}

bool datesEqualToSecond(DateTime d1, DateTime d2) {
Expand Down
15 changes: 0 additions & 15 deletions tool/travis.sh

This file was deleted.

0 comments on commit 70112b6

Please sign in to comment.