| 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 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 _checkMutable(); | 79 _checkMutable(); |
| 80 _port = port; | 80 _port = port; |
| 81 _updateHostHeader(); | 81 _updateHostHeader(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 Date get ifModifiedSince { | 84 Date get ifModifiedSince { |
| 85 List<String> values = _headers["if-modified-since"]; | 85 List<String> values = _headers["if-modified-since"]; |
| 86 if (values != null) { | 86 if (values != null) { |
| 87 try { | 87 try { |
| 88 return _HttpUtils.parseDate(values[0]); | 88 return _HttpUtils.parseDate(values[0]); |
| 89 } catch (Exception e) { | 89 } on Exception catch (e) { |
| 90 return null; | 90 return null; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 return null; | 93 return null; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void set ifModifiedSince(Date ifModifiedSince) { | 96 void set ifModifiedSince(Date ifModifiedSince) { |
| 97 _checkMutable(); | 97 _checkMutable(); |
| 98 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). | 98 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). |
| 99 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); | 99 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); |
| 100 _set("if-modified-since", formatted); | 100 _set("if-modified-since", formatted); |
| 101 } | 101 } |
| 102 | 102 |
| 103 Date get date { | 103 Date get date { |
| 104 List<String> values = _headers["date"]; | 104 List<String> values = _headers["date"]; |
| 105 if (values != null) { | 105 if (values != null) { |
| 106 try { | 106 try { |
| 107 return _HttpUtils.parseDate(values[0]); | 107 return _HttpUtils.parseDate(values[0]); |
| 108 } catch (Exception e) { | 108 } on Exception catch (e) { |
| 109 return null; | 109 return null; |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 return null; | 112 return null; |
| 113 } | 113 } |
| 114 | 114 |
| 115 void set date(Date date) { | 115 void set date(Date date) { |
| 116 _checkMutable(); | 116 _checkMutable(); |
| 117 // Format "Date" header with date in Greenwich Mean Time (GMT). | 117 // Format "Date" header with date in Greenwich Mean Time (GMT). |
| 118 String formatted = _HttpUtils.formatDate(date.toUtc()); | 118 String formatted = _HttpUtils.formatDate(date.toUtc()); |
| 119 _set("date", formatted); | 119 _set("date", formatted); |
| 120 } | 120 } |
| 121 | 121 |
| 122 Date get expires { | 122 Date get expires { |
| 123 List<String> values = _headers["expires"]; | 123 List<String> values = _headers["expires"]; |
| 124 if (values != null) { | 124 if (values != null) { |
| 125 try { | 125 try { |
| 126 return _HttpUtils.parseDate(values[0]); | 126 return _HttpUtils.parseDate(values[0]); |
| 127 } catch (Exception e) { | 127 } on Exception catch (e) { |
| 128 return null; | 128 return null; |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 return null; | 131 return null; |
| 132 } | 132 } |
| 133 | 133 |
| 134 void set expires(Date expires) { | 134 void set expires(Date expires) { |
| 135 _checkMutable(); | 135 _checkMutable(); |
| 136 // Format "Expires" header with date in Greenwich Mean Time (GMT). | 136 // Format "Expires" header with date in Greenwich Mean Time (GMT). |
| 137 String formatted = _HttpUtils.formatDate(expires.toUtc()); | 137 String formatted = _HttpUtils.formatDate(expires.toUtc()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 if (pos > 0) { | 187 if (pos > 0) { |
| 188 _host = value.substring(0, pos); | 188 _host = value.substring(0, pos); |
| 189 } else { | 189 } else { |
| 190 _host = null; | 190 _host = null; |
| 191 } | 191 } |
| 192 if (pos + 1 == value.length) { | 192 if (pos + 1 == value.length) { |
| 193 _port = HttpClient.DEFAULT_HTTP_PORT; | 193 _port = HttpClient.DEFAULT_HTTP_PORT; |
| 194 } else { | 194 } else { |
| 195 try { | 195 try { |
| 196 _port = parseInt(value.substring(pos + 1)); | 196 _port = parseInt(value.substring(pos + 1)); |
| 197 } catch (FormatException e) { | 197 } on FormatException catch (e) { |
| 198 _port = null; | 198 _port = null; |
| 199 } | 199 } |
| 200 } | 200 } |
| 201 _set("host", value); | 201 _set("host", value); |
| 202 } | 202 } |
| 203 } else if (name.toLowerCase() == "content-type") { | 203 } else if (name.toLowerCase() == "content-type") { |
| 204 _set("content-type", value); | 204 _set("content-type", value); |
| 205 } else { | 205 } else { |
| 206 name = name.toLowerCase(); | 206 name = name.toLowerCase(); |
| 207 List<String> values = _headers[name]; | 207 List<String> values = _headers[name]; |
| (...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 HttpConnectionInfo get connectionInfo { | 1281 HttpConnectionInfo get connectionInfo { |
| 1282 if (_socket == null || _closing || _error) return null; | 1282 if (_socket == null || _closing || _error) return null; |
| 1283 try { | 1283 try { |
| 1284 _HttpConnectionInfo info = new _HttpConnectionInfo(); | 1284 _HttpConnectionInfo info = new _HttpConnectionInfo(); |
| 1285 info.remoteHost = _socket.remoteHost; | 1285 info.remoteHost = _socket.remoteHost; |
| 1286 info.remotePort = _socket.remotePort; | 1286 info.remotePort = _socket.remotePort; |
| 1287 info.localPort = _socket.port; | 1287 info.localPort = _socket.port; |
| 1288 return info; | 1288 return info; |
| 1289 } catch (var e) { } | 1289 } catch (e) { } |
| 1290 return null; | 1290 return null; |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 abstract void _onConnectionClosed(e); | 1293 abstract void _onConnectionClosed(e); |
| 1294 abstract void _responseDone(); | 1294 abstract void _responseDone(); |
| 1295 | 1295 |
| 1296 void set _onNoPendingWrites(void callback()) { | 1296 void set _onNoPendingWrites(void callback()) { |
| 1297 if (!_error) { | 1297 if (!_error) { |
| 1298 _socket.outputStream.onNoPendingWrites = callback; | 1298 _socket.outputStream.onNoPendingWrites = callback; |
| 1299 } | 1299 } |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 void set onError(void callback(e)) { | 1491 void set onError(void callback(e)) { |
| 1492 _onError = callback; | 1492 _onError = callback; |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 void _handleRequest(HttpRequest request, HttpResponse response) { | 1495 void _handleRequest(HttpRequest request, HttpResponse response) { |
| 1496 for (int i = 0; i < _handlers.length; i++) { | 1496 for (int i = 0; i < _handlers.length; i++) { |
| 1497 if (_handlers[i]._matcher(request)) { | 1497 if (_handlers[i]._matcher(request)) { |
| 1498 Function handler = _handlers[i]._handler; | 1498 Function handler = _handlers[i]._handler; |
| 1499 try { | 1499 try { |
| 1500 handler(request, response); | 1500 handler(request, response); |
| 1501 } catch (var e) { | 1501 } catch (e) { |
| 1502 if (_onError != null) { | 1502 if (_onError != null) { |
| 1503 _onError(e); | 1503 _onError(e); |
| 1504 } else { | 1504 } else { |
| 1505 throw e; | 1505 throw e; |
| 1506 } | 1506 } |
| 1507 } | 1507 } |
| 1508 return; | 1508 return; |
| 1509 } | 1509 } |
| 1510 } | 1510 } |
| 1511 | 1511 |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2166 | 2166 |
| 2167 | 2167 |
| 2168 class _RedirectInfo implements RedirectInfo { | 2168 class _RedirectInfo implements RedirectInfo { |
| 2169 const _RedirectInfo(int this.statusCode, | 2169 const _RedirectInfo(int this.statusCode, |
| 2170 String this.method, | 2170 String this.method, |
| 2171 Uri this.location); | 2171 Uri this.location); |
| 2172 final int statusCode; | 2172 final int statusCode; |
| 2173 final String method; | 2173 final String method; |
| 2174 final Uri location; | 2174 final Uri location; |
| 2175 } | 2175 } |
| OLD | NEW |