selectively send contentLength, if defined in response
diff --git a/lib/shelf_proxy.dart b/lib/shelf_proxy.dart
index 6adc1a1..6758d96 100644
--- a/lib/shelf_proxy.dart
+++ b/lib/shelf_proxy.dart
@@ -24,8 +24,15 @@
return client.openUrl(request.method, url).then((ioRequest) {
return ioRequest.close();
}).then((ioResponse) {
+ var headers = {};
+ // dart:io - HttpClientResponse.contentLength is -1 if not defined
+ if (ioResponse.contentLength >= 0) {
+ headers[HttpHeaders.CONTENT_LENGTH] =
+ ioResponse.contentLength.toString();
+ }
- return new Response(ioResponse.statusCode, body: ioResponse);
+ return new Response(ioResponse.statusCode, body: ioResponse,
+ headers: headers);
});
};
}
diff --git a/test/static_file_test.dart b/test/static_file_test.dart
index 2705f23..411ad58 100644
--- a/test/static_file_test.dart
+++ b/test/static_file_test.dart
@@ -12,7 +12,7 @@
import 'test_util.dart';
void main() {
- test('foo', () {
+ test('default document', () {
_scheduleServer(_handler);
schedule(() {
@@ -23,7 +23,7 @@
expect(response.statusCode, HttpStatus.OK);
expect(response.readAsString(),
completion(contains('<title>shelf_static</title>')));
- expect(response.contentLength, isNotNull);
+ expect(response.contentLength, 228);
});
});
});