Skip to content

Commit 41b1ded

Browse files
committed
Set the correct mime types for assets served via pub serve.
[email protected] BUG=14815 Review URL: https://codereview.chromium.org//131233011 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@32580 260f80e4-7a28-3924-810f-c04153c831b5
1 parent 5fcc295 commit 41b1ded

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

sdk/lib/_internal/pub/lib/src/barback/server.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'dart:convert';
99
import 'dart:io';
1010

1111
import 'package:barback/barback.dart';
12+
import 'package:mime/mime.dart';
1213
import 'package:path/path.dart' as path;
1314
import 'package:stack_trace/stack_trace.dart';
1415

@@ -114,6 +115,7 @@ class BarbackServer {
114115
return validateStream(asset.read()).then((stream) {
115116
_resultsController.add(
116117
new BarbackServerResult._success(request.uri, id));
118+
request.response.headers.add('content-type', lookupMimeType(id.path));
117119
// TODO(rnystrom): Set content-type based on asset type.
118120
return Chain.track(request.response.addStream(stream)).then((_) {
119121
// Log successful requests both so we can provide debugging
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS d.file
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.
4+
5+
library pub_tests;
6+
7+
import 'package:scheduled_test/scheduled_test.dart';
8+
9+
import '../descriptor.dart' as d;
10+
import '../test_pub.dart';
11+
import 'utils.dart';
12+
13+
main() {
14+
initConfig();
15+
integration("uses appropriate mime types", () {
16+
d.dir(appPath, [
17+
d.appPubspec(),
18+
d.dir("web", [
19+
d.file("index.html", "<body>"),
20+
d.file("file.dart", "main() => print('hello');"),
21+
d.file("file.js", "console.log('hello');"),
22+
d.file("file.css", "body {color: blue}")
23+
])
24+
]).create();
25+
26+
pubServe();
27+
requestShouldSucceed("index.html", anything,
28+
headers: containsPair('content-type', 'text/html'));
29+
requestShouldSucceed("file.dart", anything,
30+
headers: containsPair('content-type', 'application/dart'));
31+
requestShouldSucceed("file.js", anything,
32+
headers: containsPair('content-type', 'application/javascript'));
33+
requestShouldSucceed("file.css", anything,
34+
headers: containsPair('content-type', 'text/css'));
35+
endPubServe();
36+
});
37+
}

sdk/lib/_internal/pub/test/serve/utils.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,12 @@ void endPubServe() {
169169
/// verifies that it responds with a body that matches [expectation].
170170
///
171171
/// [expectation] may either be a [Matcher] or a string to match an exact body.
172-
void requestShouldSucceed(String urlPath, expectation) {
172+
/// [headers] may be either a [Matcher] or a map to match an exact headers map.
173+
void requestShouldSucceed(String urlPath, expectation, {headers}) {
173174
schedule(() {
174175
return http.get("http://127.0.0.1:$_port/$urlPath").then((response) {
175-
expect(response.body, expectation);
176+
if (expectation != null) expect(response.body, expectation);
177+
if (headers != null) expect(response.headers, headers);
176178
});
177179
}, "request $urlPath");
178180
}

0 commit comments

Comments
 (0)