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

Side by Side Diff: sdk/lib/io/http_headers.dart

Issue 16812004: Make some HTTP utility functions public (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: One more status file update Created 7 years, 6 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 | « sdk/lib/core/uri.dart ('k') | sdk/lib/io/http_utils.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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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(String this.protocolVersion) 8 _HttpHeaders(String this.protocolVersion)
9 : _headers = new Map<String, List<String>>(); 9 : _headers = new Map<String, List<String>>();
10 10
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 void set port(int port) { 133 void set port(int port) {
134 _checkMutable(); 134 _checkMutable();
135 _port = port; 135 _port = port;
136 _updateHostHeader(); 136 _updateHostHeader();
137 } 137 }
138 138
139 DateTime get ifModifiedSince { 139 DateTime get ifModifiedSince {
140 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE]; 140 List<String> values = _headers[HttpHeaders.IF_MODIFIED_SINCE];
141 if (values != null) { 141 if (values != null) {
142 try { 142 try {
143 return _HttpUtils.parseDate(values[0]); 143 return HttpDate.parse(values[0]);
144 } on Exception catch (e) { 144 } on Exception catch (e) {
145 return null; 145 return null;
146 } 146 }
147 } 147 }
148 return null; 148 return null;
149 } 149 }
150 150
151 void set ifModifiedSince(DateTime ifModifiedSince) { 151 void set ifModifiedSince(DateTime ifModifiedSince) {
152 _checkMutable(); 152 _checkMutable();
153 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). 153 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT).
154 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); 154 String formatted = HttpDate.format(ifModifiedSince.toUtc());
155 _set(HttpHeaders.IF_MODIFIED_SINCE, formatted); 155 _set(HttpHeaders.IF_MODIFIED_SINCE, formatted);
156 } 156 }
157 157
158 DateTime get date { 158 DateTime get date {
159 List<String> values = _headers[HttpHeaders.DATE]; 159 List<String> values = _headers[HttpHeaders.DATE];
160 if (values != null) { 160 if (values != null) {
161 try { 161 try {
162 return _HttpUtils.parseDate(values[0]); 162 return HttpDate.parse(values[0]);
163 } on Exception catch (e) { 163 } on Exception catch (e) {
164 return null; 164 return null;
165 } 165 }
166 } 166 }
167 return null; 167 return null;
168 } 168 }
169 169
170 void set date(DateTime date) { 170 void set date(DateTime date) {
171 _checkMutable(); 171 _checkMutable();
172 // Format "DateTime" header with date in Greenwich Mean Time (GMT). 172 // Format "DateTime" header with date in Greenwich Mean Time (GMT).
173 String formatted = _HttpUtils.formatDate(date.toUtc()); 173 String formatted = HttpDate.format(date.toUtc());
174 _set("date", formatted); 174 _set("date", formatted);
175 } 175 }
176 176
177 DateTime get expires { 177 DateTime get expires {
178 List<String> values = _headers[HttpHeaders.EXPIRES]; 178 List<String> values = _headers[HttpHeaders.EXPIRES];
179 if (values != null) { 179 if (values != null) {
180 try { 180 try {
181 return _HttpUtils.parseDate(values[0]); 181 return HttpDate.parse(values[0]);
182 } on Exception catch (e) { 182 } on Exception catch (e) {
183 return null; 183 return null;
184 } 184 }
185 } 185 }
186 return null; 186 return null;
187 } 187 }
188 188
189 void set expires(DateTime expires) { 189 void set expires(DateTime expires) {
190 _checkMutable(); 190 _checkMutable();
191 // Format "Expires" header with date in Greenwich Mean Time (GMT). 191 // Format "Expires" header with date in Greenwich Mean Time (GMT).
192 String formatted = _HttpUtils.formatDate(expires.toUtc()); 192 String formatted = HttpDate.format(expires.toUtc());
193 _set(HttpHeaders.EXPIRES, formatted); 193 _set(HttpHeaders.EXPIRES, formatted);
194 } 194 }
195 195
196 ContentType get contentType { 196 ContentType get contentType {
197 var values = _headers["content-type"]; 197 var values = _headers["content-type"];
198 if (values != null) { 198 if (values != null) {
199 return ContentType.parse(values[0]); 199 return ContentType.parse(values[0]);
200 } else { 200 } else {
201 return null; 201 return null;
202 } 202 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 } 281 }
282 } 282 }
283 283
284 void _addValue(String name, Object value) { 284 void _addValue(String name, Object value) {
285 List<String> values = _headers[name]; 285 List<String> values = _headers[name];
286 if (values == null) { 286 if (values == null) {
287 values = new List<String>(); 287 values = new List<String>();
288 _headers[name] = values; 288 _headers[name] = values;
289 } 289 }
290 if (value is DateTime) { 290 if (value is DateTime) {
291 values.add(_HttpUtils.formatDate(value)); 291 values.add(HttpDate.format(value));
292 } else { 292 } else {
293 values.add(value.toString()); 293 values.add(value.toString());
294 } 294 }
295 } 295 }
296 296
297 void _set(String name, String value) { 297 void _set(String name, String value) {
298 name = name.toLowerCase(); 298 name = name.toLowerCase();
299 List<String> values = new List<String>(); 299 List<String> values = new List<String>();
300 _headers[name] = values; 300 _headers[name] = values;
301 values.add(value); 301 values.add(value);
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 parseAttributes(); 743 parseAttributes();
744 } 744 }
745 745
746 String toString() { 746 String toString() {
747 StringBuffer sb = new StringBuffer(); 747 StringBuffer sb = new StringBuffer();
748 sb.write(name); 748 sb.write(name);
749 sb.write("="); 749 sb.write("=");
750 sb.write(value); 750 sb.write(value);
751 if (expires != null) { 751 if (expires != null) {
752 sb.write("; Expires="); 752 sb.write("; Expires=");
753 sb.write(_HttpUtils.formatDate(expires)); 753 sb.write(HttpDate.format(expires));
754 } 754 }
755 if (maxAge != null) { 755 if (maxAge != null) {
756 sb.write("; Max-Age="); 756 sb.write("; Max-Age=");
757 sb.write(maxAge); 757 sb.write(maxAge);
758 } 758 }
759 if (domain != null) { 759 if (domain != null) {
760 sb.write("; Domain="); 760 sb.write("; Domain=");
761 sb.write(domain); 761 sb.write(domain);
762 } 762 }
763 if (path != null) { 763 if (path != null) {
764 sb.write("; Path="); 764 sb.write("; Path=");
765 sb.write(path); 765 sb.write(path);
766 } 766 }
767 if (secure) sb.write("; Secure"); 767 if (secure) sb.write("; Secure");
768 if (httpOnly) sb.write("; HttpOnly"); 768 if (httpOnly) sb.write("; HttpOnly");
769 return sb.toString(); 769 return sb.toString();
770 } 770 }
771 771
772 String name; 772 String name;
773 String value; 773 String value;
774 DateTime expires; 774 DateTime expires;
775 int maxAge; 775 int maxAge;
776 String domain; 776 String domain;
777 String path; 777 String path;
778 bool httpOnly = false; 778 bool httpOnly = false;
779 bool secure = false; 779 bool secure = false;
780 } 780 }
OLDNEW
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | sdk/lib/io/http_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698