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

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

Issue 9602011: Add handling of HTTP header "Expires" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed accidental edit Created 8 years, 9 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
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 // Utility class for encoding a string into UTF-8 byte stream. 5 // Utility class for encoding a string into UTF-8 byte stream.
6 class _UTF8Encoder { 6 class _UTF8Encoder {
7 static List<int> encodeString(String string) { 7 static List<int> encodeString(String string) {
8 int size = _encodingSize(string); 8 int size = _encodingSize(string);
9 ByteArray result = new ByteArray(size); 9 ByteArray result = new ByteArray(size);
10 _encodeString(string, result); 10 _encodeString(string, result);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 class _HttpRequestResponseBase { 53 class _HttpRequestResponseBase {
54 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection) 54 _HttpRequestResponseBase(_HttpConnectionBase this._httpConnection)
55 : _contentLength = -1, 55 : _contentLength = -1,
56 _keepAlive = false, 56 _keepAlive = false,
57 _headers = new Map(); 57 _headers = new Map();
58 58
59 int get contentLength() => _contentLength; 59 int get contentLength() => _contentLength;
60 bool get keepAlive() => _keepAlive; 60 bool get keepAlive() => _keepAlive;
61 61
62 void _setHeader(String name, String value) { 62 void _setHeader(String name, String value) {
63 _headers[name] = value; 63 _headers[name.toLowerCase()] = value;
64 } 64 }
65 65
66 bool _write(List<int> data, bool copyBuffer) { 66 bool _write(List<int> data, bool copyBuffer) {
67 bool allWritten = true; 67 bool allWritten = true;
68 if (data.length > 0) { 68 if (data.length > 0) {
69 if (_contentLength < 0) { 69 if (_contentLength < 0) {
70 // Write chunk size if transfer encoding is chunked. 70 // Write chunk size if transfer encoding is chunked.
71 _writeHexString(data.length); 71 _writeHexString(data.length);
72 _writeCRLF(); 72 _writeCRLF();
73 _httpConnection.outputStream.write(data, copyBuffer); 73 _httpConnection.outputStream.write(data, copyBuffer);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 if (_outputStream != null) return new HttpException("Header already sent"); 273 if (_outputStream != null) return new HttpException("Header already sent");
274 _statusCode = statusCode; 274 _statusCode = statusCode;
275 } 275 }
276 276
277 String get reasonPhrase() => _findReasonPhrase(_statusCode); 277 String get reasonPhrase() => _findReasonPhrase(_statusCode);
278 void set reasonPhrase(String reasonPhrase) { 278 void set reasonPhrase(String reasonPhrase) {
279 if (_outputStream != null) return new HttpException("Header already sent"); 279 if (_outputStream != null) return new HttpException("Header already sent");
280 _reasonPhrase = reasonPhrase; 280 _reasonPhrase = reasonPhrase;
281 } 281 }
282 282
283 Date get expires() => _expires;
284 void set expires(Date expires) {
285 if (_outputStream != null) return new HttpException("Header already sent");
Anders Johnsen 2012/03/06 10:41:01 throw
Søren Gjesse 2012/03/06 12:01:16 Done.
286 _expires = expires;
287 // Format "Expires" header with date in Greenwich Mean Time (GMT).
288 String formatted =
289 _HttpUtils.formatDate(_expires.changeTimeZone(new TimeZone.utc()));
290 _setHeader("Expires", formatted);
291 }
292
283 // Set a header on the response. NOTE: If the same header is set 293 // Set a header on the response. NOTE: If the same header is set
284 // more than once only the last one will be part of the response. 294 // more than once only the last one will be part of the response.
285 void setHeader(String name, String value) { 295 void setHeader(String name, String value) {
286 if (_outputStream != null) return new HttpException("Header already sent"); 296 if (_outputStream != null) return new HttpException("Header already sent");
287 _setHeader(name, value); 297 if (name.toLowerCase() == "expires") {
298 expires = _HttpUtils.parseDate(value);
299 } else {
300 _setHeader(name, value);
301 }
288 } 302 }
289 303
290 OutputStream get outputStream() { 304 OutputStream get outputStream() {
291 if (_state == DONE) throw new HttpException("Response closed"); 305 if (_state == DONE) throw new HttpException("Response closed");
292 if (_outputStream == null) { 306 if (_outputStream == null) {
293 // Ensure that headers are written. 307 // Ensure that headers are written.
294 if (_state == START) { 308 if (_state == START) {
295 _writeHeader(); 309 _writeHeader();
296 } 310 }
297 _outputStream = new _HttpOutputStream(this); 311 _outputStream = new _HttpOutputStream(this);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 438
425 // Write headers. 439 // Write headers.
426 bool allWritten = _writeHeaders(); 440 bool allWritten = _writeHeaders();
427 _state = HEADERS_SENT; 441 _state = HEADERS_SENT;
428 return allWritten; 442 return allWritten;
429 } 443 }
430 444
431 // Response status code. 445 // Response status code.
432 int _statusCode; 446 int _statusCode;
433 String _reasonPhrase; 447 String _reasonPhrase;
448 Date _expires;
434 _HttpOutputStream _outputStream; 449 _HttpOutputStream _outputStream;
435 int _state; 450 int _state;
436 } 451 }
437 452
438 453
439 class _HttpInputStream extends _BaseDataInputStream implements InputStream { 454 class _HttpInputStream extends _BaseDataInputStream implements InputStream {
440 _HttpInputStream(_HttpRequestResponseBase this._requestOrResponse) { 455 _HttpInputStream(_HttpRequestResponseBase this._requestOrResponse) {
441 _checkScheduleCallbacks(); 456 _checkScheduleCallbacks();
442 } 457 }
443 458
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 826
812 class _HttpClientResponse 827 class _HttpClientResponse
813 extends _HttpRequestResponseBase implements HttpClientResponse { 828 extends _HttpRequestResponseBase implements HttpClientResponse {
814 _HttpClientResponse(_HttpClientConnection connection) 829 _HttpClientResponse(_HttpClientConnection connection)
815 : super(connection) { 830 : super(connection) {
816 _connection = connection; 831 _connection = connection;
817 } 832 }
818 833
819 int get statusCode() => _statusCode; 834 int get statusCode() => _statusCode;
820 String get reasonPhrase() => _reasonPhrase; 835 String get reasonPhrase() => _reasonPhrase;
836
837 Date get expires() {
838 String str = _headers["expires"];
839 if (str == null) return null;
840 return _HttpUtils.parseDate(str);
841 }
842
821 Map get headers() => _headers; 843 Map get headers() => _headers;
822 844
823 InputStream get inputStream() { 845 InputStream get inputStream() {
824 if (_inputStream == null) { 846 if (_inputStream == null) {
825 _inputStream = new _HttpInputStream(this); 847 _inputStream = new _HttpInputStream(this);
826 } 848 }
827 return _inputStream; 849 return _inputStream;
828 } 850 }
829 851
830 void _onRequestStart(String method, String uri) { 852 void _onRequestStart(String method, String uri) {
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 _onError = callback; 1144 _onError = callback;
1123 } 1145 }
1124 1146
1125 Function _onOpen; 1147 Function _onOpen;
1126 Function _onError; 1148 Function _onError;
1127 Map<String, Queue<_SocketConnection>> _openSockets; 1149 Map<String, Queue<_SocketConnection>> _openSockets;
1128 Set<_SocketConnection> _activeSockets; 1150 Set<_SocketConnection> _activeSockets;
1129 Timer _evictionTimer; 1151 Timer _evictionTimer;
1130 bool _shutdown; // Has this HTTP client been shutdown? 1152 bool _shutdown; // Has this HTTP client been shutdown?
1131 } 1153 }
OLDNEW
« no previous file with comments | « runtime/bin/http.dart ('k') | runtime/bin/http_utils.dart » ('j') | runtime/bin/http_utils.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698