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

Side by Side Diff: runtime/bin/http_impl.dart

Issue 10191013: Add handling of the HTTP Date header (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpHeadersTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _HttpHeaders implements HttpHeaders { 5 class _HttpHeaders implements HttpHeaders {
6 _HttpHeaders() : _headers = new Map<String, List<String>>(); 6 _HttpHeaders() : _headers = new Map<String, List<String>>();
7 7
8 List<String> operator[](String name) { 8 List<String> operator[](String name) {
9 name = name.toLowerCase(); 9 name = name.toLowerCase();
10 return _headers[name]; 10 return _headers[name];
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 _host = host; 56 _host = host;
57 _updateHostHeader(); 57 _updateHostHeader();
58 } 58 }
59 59
60 int get port() => _port; 60 int get port() => _port;
61 void set port(int port) { 61 void set port(int port) {
62 _port = port; 62 _port = port;
63 _updateHostHeader(); 63 _updateHostHeader();
64 } 64 }
65 65
66 Date get date() {
67 List<String> values = _headers["date"];
68 if (values != null) {
69 try {
70 return _HttpUtils.parseDate(values[0]);
71 } catch (Exception e) {
72 return null;
73 }
74 }
Anders Johnsen 2012/04/25 09:02:09 Maybe add an explicit return null.
Søren Gjesse 2012/04/25 14:14:36 Done.
75 }
76
77 void set date(Date date) {
78 // Format "Date" header with date in Greenwich Mean Time (GMT).
79 String formatted =
80 _HttpUtils.formatDate(expires.changeTimeZone(new TimeZone.utc()));
81 _set("date", formatted);
82 }
83
66 Date get expires() { 84 Date get expires() {
67 List<String> values = _headers["expires"]; 85 List<String> values = _headers["expires"];
68 if (values != null) { 86 if (values != null) {
69 try { 87 try {
70 return _HttpUtils.parseDate(values[0]); 88 return _HttpUtils.parseDate(values[0]);
71 } catch (Exception e) { 89 } catch (Exception e) {
72 return null; 90 return null;
73 } 91 }
74 } 92 }
75 } 93 }
Anders Johnsen 2012/04/25 09:02:09 Ditto.
Søren Gjesse 2012/04/25 14:14:36 Done.
76 94
77 void set expires(Date expires) { 95 void set expires(Date expires) {
78 // Format "Expires" header with date in Greenwich Mean Time (GMT). 96 // Format "Expires" header with date in Greenwich Mean Time (GMT).
79 String formatted = 97 String formatted =
80 _HttpUtils.formatDate(expires.changeTimeZone(new TimeZone.utc())); 98 _HttpUtils.formatDate(expires.changeTimeZone(new TimeZone.utc()));
81 _set("expires", formatted); 99 _set("expires", formatted);
82 } 100 }
83 101
84 void _add(String name, Object value) { 102 void _add(String name, Object value) {
85 // TODO(sgjesse): Add immutable state throw HttpException is immutable. 103 // TODO(sgjesse): Add immutable state throw HttpException is immutable.
86 if (name.toLowerCase() == "expires") { 104 if (name.toLowerCase() == "date") {
105 if (value is Date) {
106 date = value;
107 } else if (value is String) {
108 _set("date", value);
109 } else {
110 throw new HttpException("Unexpected type for header named $name");
111 }
112 } else if (name.toLowerCase() == "expires") {
87 if (value is Date) { 113 if (value is Date) {
88 expires = value; 114 expires = value;
89 } else if (value is String) { 115 } else if (value is String) {
90 _set("expires", value); 116 _set("expires", value);
91 } else { 117 } else {
92 throw new HttpException("Unexpected type for header named $name"); 118 throw new HttpException("Unexpected type for header named $name");
93 } 119 }
94 } else if (name.toLowerCase() == "host") { 120 } else if (name.toLowerCase() == "host") {
95 int pos = value.indexOf(":"); 121 int pos = value.indexOf(":");
96 if (pos == -1) { 122 if (pos == -1) {
(...skipping 1295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1392 _activeSockets.remove(socketConn); 1418 _activeSockets.remove(socketConn);
1393 sockets.addFirst(socketConn); 1419 sockets.addFirst(socketConn);
1394 } 1420 }
1395 1421
1396 Function _onOpen; 1422 Function _onOpen;
1397 Map<String, Queue<_SocketConnection>> _openSockets; 1423 Map<String, Queue<_SocketConnection>> _openSockets;
1398 Set<_SocketConnection> _activeSockets; 1424 Set<_SocketConnection> _activeSockets;
1399 Timer _evictionTimer; 1425 Timer _evictionTimer;
1400 bool _shutdown; // Has this HTTP client been shutdown? 1426 bool _shutdown; // Has this HTTP client been shutdown?
1401 } 1427 }
OLDNEW
« no previous file with comments | « runtime/bin/http.dart ('k') | tests/standalone/src/io/HttpHeadersTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698