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

Unified Diff: runtime/bin/http_impl.dart

Issue 10855197: Fix HttpHeaders.date and add HttpHeaders.ifModifiedSince. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Also parse other date values to a Http date format. Created 8 years, 4 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 | « runtime/bin/http.dart ('k') | tests/standalone/io/http_headers_test.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 c096e54360db26fe53bead0e457a626ba65c0b6c..9e2bdb004bfa101154ae0286351b6782d327e159 100644
--- a/runtime/bin/http_impl.dart
+++ b/runtime/bin/http_impl.dart
@@ -81,6 +81,25 @@ class _HttpHeaders implements HttpHeaders {
_updateHostHeader();
}
+ Date get ifModifiedSince() {
+ List<String> values = _headers["if-modified-since"];
+ if (values != null) {
+ try {
+ return _HttpUtils.parseDate(values[0]);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ void set ifModifiedSince(Date ifModifiedSince) {
+ _checkMutable();
+ // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT).
+ String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc());
+ _set("if-modified-since", formatted);
+ }
+
Date get date() {
List<String> values = _headers["date"];
if (values != null) {
@@ -96,7 +115,7 @@ class _HttpHeaders implements HttpHeaders {
void set date(Date date) {
_checkMutable();
// Format "Date" header with date in Greenwich Mean Time (GMT).
- String formatted = _HttpUtils.formatDate(expires.toUtc());
+ String formatted = _HttpUtils.formatDate(date.toUtc());
_set("date", formatted);
}
@@ -151,6 +170,14 @@ class _HttpHeaders implements HttpHeaders {
} else {
throw new HttpException("Unexpected type for header named $name");
}
+ } else if (name.toLowerCase() == "if-modified-since") {
+ if (value is Date) {
+ ifModifiedSince = value;
+ } else if (value is String) {
+ _set("if-modified-since", value);
+ } else {
+ throw new HttpException("Unexpected type for header named $name");
+ }
} else if (name.toLowerCase() == "host") {
int pos = value.indexOf(":");
if (pos == -1) {
@@ -182,7 +209,11 @@ class _HttpHeaders implements HttpHeaders {
values = new List<String>();
_headers[name] = values;
}
- values.add(value.toString());
+ if (value is Date) {
+ values.add(_HttpUtils.formatDate(value));
+ } else {
+ values.add(value.toString());
+ }
}
}
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/io/http_headers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698