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

Unified Diff: sdk/lib/io/http_headers.dart

Issue 11637017: Change the HTTP Content-Length handling (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/io/http_headers.dart
diff --git a/sdk/lib/io/http_headers.dart b/sdk/lib/io/http_headers.dart
index 55a9a8957f87c205664b41fe62363b35bf8e5272..e6566e5cbe7e2bd9ad93ea8520e4246599bd828e 100644
--- a/sdk/lib/io/http_headers.dart
+++ b/sdk/lib/io/http_headers.dart
@@ -65,6 +65,18 @@ class _HttpHeaders implements HttpHeaders {
_noFoldingHeaders.add(name);
}
+ int get contentLength => _contentLength;
+
+ void set contentLength(int contentLength) {
+ _checkMutable();
+ _contentLength = contentLength;
+ if (_contentLength >= 0) {
+ _set("content-length", contentLength.toString());
+ } else {
+ removeAll("content-length");
+ }
+ }
+
String get host => _host;
void set host(String host) {
@@ -155,7 +167,15 @@ class _HttpHeaders implements HttpHeaders {
void _add(String name, Object value) {
var lowerCaseName = name.toLowerCase();
// TODO(sgjesse): Add immutable state throw HttpException is immutable.
- if (lowerCaseName == "date") {
+ if (lowerCaseName == "content-length") {
+ if (value is int) {
+ contentLength = value;
+ } else if (value is String) {
+ contentLength = parseInt(value);
+ } else {
+ throw new HttpException("Unexpected type for header named $name");
+ }
+ } else if (lowerCaseName == "date") {
if (value is Date) {
date = value;
} else if (value is String) {
@@ -323,6 +343,7 @@ class _HttpHeaders implements HttpHeaders {
Map<String, List<String>> _headers;
List<String> _noFoldingHeaders;
+ int _contentLength = -1;
String _host;
int _port;
}

Powered by Google App Engine
This is Rietveld 408576698