OLD | NEW |
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 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 class _HttpHeaders implements HttpHeaders { | 7 class _HttpHeaders implements HttpHeaders { |
8 _HttpHeaders() : _headers = new Map<String, List<String>>(); | 8 _HttpHeaders() : _headers = new Map<String, List<String>>(); |
9 | 9 |
10 List<String> operator[](String name) { | 10 List<String> operator[](String name) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 int get port => _port; | 105 int get port => _port; |
106 | 106 |
107 void set port(int port) { | 107 void set port(int port) { |
108 _checkMutable(); | 108 _checkMutable(); |
109 _port = port; | 109 _port = port; |
110 _updateHostHeader(); | 110 _updateHostHeader(); |
111 } | 111 } |
112 | 112 |
113 Date get ifModifiedSince { | 113 DateTime get ifModifiedSince { |
114 List<String> values = _headers["if-modified-since"]; | 114 List<String> values = _headers["if-modified-since"]; |
115 if (values != null) { | 115 if (values != null) { |
116 try { | 116 try { |
117 return _HttpUtils.parseDate(values[0]); | 117 return _HttpUtils.parseDate(values[0]); |
118 } on Exception catch (e) { | 118 } on Exception catch (e) { |
119 return null; | 119 return null; |
120 } | 120 } |
121 } | 121 } |
122 return null; | 122 return null; |
123 } | 123 } |
124 | 124 |
125 void set ifModifiedSince(Date ifModifiedSince) { | 125 void set ifModifiedSince(DateTime ifModifiedSince) { |
126 _checkMutable(); | 126 _checkMutable(); |
127 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). | 127 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). |
128 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); | 128 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); |
129 _set("if-modified-since", formatted); | 129 _set("if-modified-since", formatted); |
130 } | 130 } |
131 | 131 |
132 Date get date { | 132 DateTime get date { |
133 List<String> values = _headers["date"]; | 133 List<String> values = _headers["date"]; |
134 if (values != null) { | 134 if (values != null) { |
135 try { | 135 try { |
136 return _HttpUtils.parseDate(values[0]); | 136 return _HttpUtils.parseDate(values[0]); |
137 } on Exception catch (e) { | 137 } on Exception catch (e) { |
138 return null; | 138 return null; |
139 } | 139 } |
140 } | 140 } |
141 return null; | 141 return null; |
142 } | 142 } |
143 | 143 |
144 void set date(Date date) { | 144 void set date(DateTime date) { |
145 _checkMutable(); | 145 _checkMutable(); |
146 // Format "Date" header with date in Greenwich Mean Time (GMT). | 146 // Format "DateTime" header with date in Greenwich Mean Time (GMT). |
147 String formatted = _HttpUtils.formatDate(date.toUtc()); | 147 String formatted = _HttpUtils.formatDate(date.toUtc()); |
148 _set("date", formatted); | 148 _set("date", formatted); |
149 } | 149 } |
150 | 150 |
151 Date get expires { | 151 DateTime get expires { |
152 List<String> values = _headers["expires"]; | 152 List<String> values = _headers["expires"]; |
153 if (values != null) { | 153 if (values != null) { |
154 try { | 154 try { |
155 return _HttpUtils.parseDate(values[0]); | 155 return _HttpUtils.parseDate(values[0]); |
156 } on Exception catch (e) { | 156 } on Exception catch (e) { |
157 return null; | 157 return null; |
158 } | 158 } |
159 } | 159 } |
160 return null; | 160 return null; |
161 } | 161 } |
162 | 162 |
163 void set expires(Date expires) { | 163 void set expires(DateTime expires) { |
164 _checkMutable(); | 164 _checkMutable(); |
165 // Format "Expires" header with date in Greenwich Mean Time (GMT). | 165 // Format "Expires" header with date in Greenwich Mean Time (GMT). |
166 String formatted = _HttpUtils.formatDate(expires.toUtc()); | 166 String formatted = _HttpUtils.formatDate(expires.toUtc()); |
167 _set("expires", formatted); | 167 _set("expires", formatted); |
168 } | 168 } |
169 | 169 |
170 ContentType get contentType { | 170 ContentType get contentType { |
171 var values = _headers["content-type"]; | 171 var values = _headers["content-type"]; |
172 if (values != null) { | 172 if (values != null) { |
173 return new ContentType.fromString(values[0]); | 173 return new ContentType.fromString(values[0]); |
(...skipping 18 matching lines...) Expand all Loading... |
192 } else { | 192 } else { |
193 throw new HttpException("Unexpected type for header named $name"); | 193 throw new HttpException("Unexpected type for header named $name"); |
194 } | 194 } |
195 } else if (lowerCaseName == "transfer-encoding") { | 195 } else if (lowerCaseName == "transfer-encoding") { |
196 if (value == "chunked") { | 196 if (value == "chunked") { |
197 chunkedTransferEncoding = true; | 197 chunkedTransferEncoding = true; |
198 } else { | 198 } else { |
199 _addValue(lowerCaseName, value); | 199 _addValue(lowerCaseName, value); |
200 } | 200 } |
201 } else if (lowerCaseName == "date") { | 201 } else if (lowerCaseName == "date") { |
202 if (value is Date) { | 202 if (value is DateTime) { |
203 date = value; | 203 date = value; |
204 } else if (value is String) { | 204 } else if (value is String) { |
205 _set("date", value); | 205 _set("date", value); |
206 } else { | 206 } else { |
207 throw new HttpException("Unexpected type for header named $name"); | 207 throw new HttpException("Unexpected type for header named $name"); |
208 } | 208 } |
209 } else if (lowerCaseName == "expires") { | 209 } else if (lowerCaseName == "expires") { |
210 if (value is Date) { | 210 if (value is DateTime) { |
211 expires = value; | 211 expires = value; |
212 } else if (value is String) { | 212 } else if (value is String) { |
213 _set("expires", value); | 213 _set("expires", value); |
214 } else { | 214 } else { |
215 throw new HttpException("Unexpected type for header named $name"); | 215 throw new HttpException("Unexpected type for header named $name"); |
216 } | 216 } |
217 } else if (lowerCaseName == "if-modified-since") { | 217 } else if (lowerCaseName == "if-modified-since") { |
218 if (value is Date) { | 218 if (value is DateTime) { |
219 ifModifiedSince = value; | 219 ifModifiedSince = value; |
220 } else if (value is String) { | 220 } else if (value is String) { |
221 _set("if-modified-since", value); | 221 _set("if-modified-since", value); |
222 } else { | 222 } else { |
223 throw new HttpException("Unexpected type for header named $name"); | 223 throw new HttpException("Unexpected type for header named $name"); |
224 } | 224 } |
225 } else if (lowerCaseName == "host") { | 225 } else if (lowerCaseName == "host") { |
226 int pos = value.indexOf(":"); | 226 int pos = value.indexOf(":"); |
227 if (pos == -1) { | 227 if (pos == -1) { |
228 _host = value; | 228 _host = value; |
(...skipping 21 matching lines...) Expand all Loading... |
250 _addValue(lowerCaseName, value); | 250 _addValue(lowerCaseName, value); |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 void _addValue(String name, Object value) { | 254 void _addValue(String name, Object value) { |
255 List<String> values = _headers[name]; | 255 List<String> values = _headers[name]; |
256 if (values == null) { | 256 if (values == null) { |
257 values = new List<String>(); | 257 values = new List<String>(); |
258 _headers[name] = values; | 258 _headers[name] = values; |
259 } | 259 } |
260 if (value is Date) { | 260 if (value is DateTime) { |
261 values.add(_HttpUtils.formatDate(value)); | 261 values.add(_HttpUtils.formatDate(value)); |
262 } else { | 262 } else { |
263 values.add(value.toString()); | 263 values.add(value.toString()); |
264 } | 264 } |
265 } | 265 } |
266 | 266 |
267 void _set(String name, String value) { | 267 void _set(String name, String value) { |
268 name = name.toLowerCase(); | 268 name = name.toLowerCase(); |
269 List<String> values = new List<String>(); | 269 List<String> values = new List<String>(); |
270 _headers[name] = values; | 270 _headers[name] = values; |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 sb.add("; Path="); | 676 sb.add("; Path="); |
677 sb.add(path); | 677 sb.add(path); |
678 } | 678 } |
679 if (secure) sb.add("; Secure"); | 679 if (secure) sb.add("; Secure"); |
680 if (httpOnly) sb.add("; HttpOnly"); | 680 if (httpOnly) sb.add("; HttpOnly"); |
681 return sb.toString(); | 681 return sb.toString(); |
682 } | 682 } |
683 | 683 |
684 String name; | 684 String name; |
685 String value; | 685 String value; |
686 Date expires; | 686 DateTime expires; |
687 int maxAge; | 687 int maxAge; |
688 String domain; | 688 String domain; |
689 String path; | 689 String path; |
690 bool httpOnly = false; | 690 bool httpOnly = false; |
691 bool secure = false; | 691 bool secure = false; |
692 } | 692 } |
OLD | NEW |