Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: sdk/lib/_internal/pub/lib/src/barback/server.dart

Issue 131233011: Set the correct mime types for assets served via pub serve. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library pub.barback.server; 5 library pub.barback.server;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 10
11 import 'package:barback/barback.dart'; 11 import 'package:barback/barback.dart';
12 import 'package:mime/mime.dart';
12 import 'package:path/path.dart' as path; 13 import 'package:path/path.dart' as path;
13 import 'package:stack_trace/stack_trace.dart'; 14 import 'package:stack_trace/stack_trace.dart';
14 15
15 import '../barback.dart'; 16 import '../barback.dart';
16 import '../log.dart' as log; 17 import '../log.dart' as log;
17 import '../utils.dart'; 18 import '../utils.dart';
18 19
19 /// Callback for determining if an asset with [id] should be served or not. 20 /// Callback for determining if an asset with [id] should be served or not.
20 typedef bool AllowAsset(AssetId id); 21 typedef bool AllowAsset(AssetId id);
21 22
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if (allowAsset != null && !allowAsset(id)) { 108 if (allowAsset != null && !allowAsset(id)) {
108 _notFound(request, "Asset $id is not available in this configuration."); 109 _notFound(request, "Asset $id is not available in this configuration.");
109 return; 110 return;
110 } 111 }
111 112
112 _logRequest(request, "Loading $id"); 113 _logRequest(request, "Loading $id");
113 barback.getAssetById(id).then((asset) { 114 barback.getAssetById(id).then((asset) {
114 return validateStream(asset.read()).then((stream) { 115 return validateStream(asset.read()).then((stream) {
115 _resultsController.add( 116 _resultsController.add(
116 new BarbackServerResult._success(request.uri, id)); 117 new BarbackServerResult._success(request.uri, id));
118 request.response.headers.add('content-type', lookupMimeType(id.path));
Bob Nystrom 2014/02/11 19:11:14 Hurray for code reuse!
117 // TODO(rnystrom): Set content-type based on asset type. 119 // TODO(rnystrom): Set content-type based on asset type.
118 return Chain.track(request.response.addStream(stream)).then((_) { 120 return Chain.track(request.response.addStream(stream)).then((_) {
119 // Log successful requests both so we can provide debugging 121 // Log successful requests both so we can provide debugging
120 // information and so scheduled_test knows we haven't timed out while 122 // information and so scheduled_test knows we haven't timed out while
121 // loading transformers. 123 // loading transformers.
122 _logRequest(request, "Served $id"); 124 _logRequest(request, "Served $id");
123 request.response.close(); 125 request.response.close();
124 }); 126 });
125 }).catchError((error, trace) { 127 }).catchError((error, trace) {
126 _resultsController.add( 128 _resultsController.add(
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 bool get isSuccess => error == null; 303 bool get isSuccess => error == null;
302 304
303 /// Whether the request was served unsuccessfully. 305 /// Whether the request was served unsuccessfully.
304 bool get isFailure => !isSuccess; 306 bool get isFailure => !isSuccess;
305 307
306 BarbackServerResult._success(this.url, this.id) 308 BarbackServerResult._success(this.url, this.id)
307 : error = null; 309 : error = null;
308 310
309 BarbackServerResult._failure(this.url, this.id, this.error); 311 BarbackServerResult._failure(this.url, this.id, this.error);
310 } 312 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698