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

Unified Diff: runtime/bin/http_impl.dart

Issue 9956175: Add test of the HTTP headers object (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/standalone/src/io/HttpHeadersTest.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/http_impl.dart
diff --git a/runtime/bin/http_impl.dart b/runtime/bin/http_impl.dart
index f8475ca2ab5a99c940052e0d2d8570afd56a8976..69d346df6502f5a3608600b50b5d27a0b319f2a7 100644
--- a/runtime/bin/http_impl.dart
+++ b/runtime/bin/http_impl.dart
@@ -23,7 +23,7 @@ class _HttpHeaders implements HttpHeaders {
void add(String name, Object value) {
if (value is List) {
for (int i = 0; i < value.length; i++) {
- _add(name, vlaie[i]);
+ _add(name, value[i]);
}
} else {
_add(name, value);
@@ -64,20 +64,20 @@ class _HttpHeaders implements HttpHeaders {
}
Date get expires() {
Anders Johnsen 2012/04/18 06:34:53 Did we remove expires, host and port from the othe
Søren Gjesse 2012/04/18 06:40:16 expires, host and port was removed from the other
- if (_expires == null) {
- List<String> values = _headers["expires"];
- if (values != null) {
- _expires = _HttpUtils.parseDate(values[0]);
+ List<String> values = _headers["expires"];
+ if (values != null) {
+ try {
+ return _HttpUtils.parseDate(values[0]);
+ } catch (Exception e) {
+ return null;
}
}
- return _expires;
}
void set expires(Date expires) {
- _expires = expires;
// Format "Expires" header with date in Greenwich Mean Time (GMT).
String formatted =
- _HttpUtils.formatDate(_expires.changeTimeZone(new TimeZone.utc()));
+ _HttpUtils.formatDate(expires.changeTimeZone(new TimeZone.utc()));
_set("expires", formatted);
}
@@ -87,7 +87,7 @@ class _HttpHeaders implements HttpHeaders {
if (value is Date) {
expires = value;
} else if (value is String) {
- expires = _HttpUtils.parseDate(value);
+ _set("expires", value);
} else {
throw new HttpException("Unexpected type for header named $name");
}
@@ -97,14 +97,22 @@ class _HttpHeaders implements HttpHeaders {
_host = value;
_port = HttpClient.DEFAULT_HTTP_PORT;
} else {
- _host = value.substring(0, pos);
+ if (pos > 0) {
+ _host = value.substring(0, pos);
+ } else {
+ _host = null;
+ }
if (pos + 1 == value.length) {
_port = HttpClient.DEFAULT_HTTP_PORT;
} else {
- _port = Math.parseInt(value.substring(pos + 1));
+ try {
+ _port = Math.parseInt(value.substring(pos + 1));
+ } catch (BadNumberFormatException e) {
+ _port = null;
+ }
}
+ _set("host", value);
}
- _updateHostHeader();
} else {
name = name.toLowerCase();
List<String> values = _headers[name];
@@ -124,7 +132,8 @@ class _HttpHeaders implements HttpHeaders {
}
_updateHostHeader() {
- String portPart = _port == HttpClient.DEFAULT_HTTP_PORT ? "" : ":$_port";
+ bool defaultPort = _port == null || _port == HttpClient.DEFAULT_HTTP_PORT;
+ String portPart = defaultPort ? "" : ":$_port";
_set("host", "$host$portPart");
}
@@ -170,7 +179,6 @@ class _HttpHeaders implements HttpHeaders {
String _host;
int _port;
- Date _expires;
}
« no previous file with comments | « no previous file | tests/standalone/src/io/HttpHeadersTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698