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

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

Issue 11645044: Refactor handling of Transfer-Encoding (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
« no previous file with comments | « no previous file | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_headers.dart
diff --git a/sdk/lib/io/http_headers.dart b/sdk/lib/io/http_headers.dart
index e6566e5cbe7e2bd9ad93ea8520e4246599bd828e..46651c62ab16c5ffe639803eda44a61890c86fac 100644
--- a/sdk/lib/io/http_headers.dart
+++ b/sdk/lib/io/http_headers.dart
@@ -77,6 +77,21 @@ class _HttpHeaders implements HttpHeaders {
}
}
+ bool get chunkedTransferEncoding => _chunkedTransferEncoding;
+
+ void set chunkedTransferEncoding(bool chunkedTransferEncoding) {
+ _checkMutable();
+ _chunkedTransferEncoding = chunkedTransferEncoding;
+ List<String> values = _headers["transfer-encoding"];
+ if (values == null || values[values.length - 1] != "chunked") {
+ // Headers does not specify chunked encoding - add it if set.
+ if (chunkedTransferEncoding) _addValue("transfer-encoding", "chunked");
+ } else {
+ // Headers does specify chunked encoding - remove it if not set.
+ if (!chunkedTransferEncoding) remove("transfer-encoding", "chunked");
+ }
+ }
+
String get host => _host;
void set host(String host) {
@@ -175,6 +190,12 @@ class _HttpHeaders implements HttpHeaders {
} else {
throw new HttpException("Unexpected type for header named $name");
}
+ } else if (lowerCaseName == "transfer-encoding") {
+ if (value == "chunked") {
+ chunkedTransferEncoding = true;
+ } else {
+ _addValue(lowerCaseName, value);
+ }
} else if (lowerCaseName == "date") {
if (value is Date) {
date = value;
@@ -224,17 +245,20 @@ class _HttpHeaders implements HttpHeaders {
} else if (lowerCaseName == "content-type") {
_set("content-type", value);
} else {
- name = lowerCaseName;
- List<String> values = _headers[name];
- if (values == null) {
- values = new List<String>();
- _headers[name] = values;
- }
- if (value is Date) {
- values.add(_HttpUtils.formatDate(value));
- } else {
- values.add(value.toString());
- }
+ _addValue(lowerCaseName, value);
+ }
+ }
+
+ void _addValue(String name, Object value) {
+ List<String> values = _headers[name];
+ if (values == null) {
+ values = new List<String>();
+ _headers[name] = values;
+ }
+ if (value is Date) {
+ values.add(_HttpUtils.formatDate(value));
+ } else {
+ values.add(value.toString());
}
}
@@ -264,6 +288,22 @@ class _HttpHeaders implements HttpHeaders {
return true;
}
+ void _finalize(String protocolVersion) {
+ // If the content length is not known make sure chunked transfer
+ // encoding is used for HTTP 1.1.
+ if (contentLength < 0 && protocolVersion == "1.1") {
+ chunkedTransferEncoding = true;
+ }
+ // If a Transfer-Encoding header field is present the
+ // Content-Length header MUST NOT be sent (RFC 2616 section 4.4).
+ if (chunkedTransferEncoding &&
+ contentLength >= 0 &&
+ protocolVersion == "1.1") {
+ contentLength = -1;
+ }
+ _mutable = false;
+ }
+
_write(_HttpConnectionBase connection) {
final COLONSP = const [_CharCode.COLON, _CharCode.SP];
final COMMASP = const [_CharCode.COMMA, _CharCode.SP];
@@ -344,6 +384,7 @@ class _HttpHeaders implements HttpHeaders {
List<String> _noFoldingHeaders;
int _contentLength = -1;
+ bool _chunkedTransferEncoding = false;
String _host;
int _port;
}
« no previous file with comments | « no previous file | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698