| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 int get port() => _port; | 76 int get port() => _port; |
| 77 | 77 |
| 78 void set port(int port) { | 78 void set port(int port) { |
| 79 _checkMutable(); | 79 _checkMutable(); |
| 80 _port = port; | 80 _port = port; |
| 81 _updateHostHeader(); | 81 _updateHostHeader(); |
| 82 } | 82 } |
| 83 | 83 |
| 84 Date get ifModifiedSince() { |
| 85 List<String> values = _headers["if-modified-since"]; |
| 86 if (values != null) { |
| 87 try { |
| 88 return _HttpUtils.parseDate(values[0]); |
| 89 } catch (Exception e) { |
| 90 return null; |
| 91 } |
| 92 } |
| 93 return null; |
| 94 } |
| 95 |
| 96 void set ifModifiedSince(Date ifModifiedSince) { |
| 97 _checkMutable(); |
| 98 // Format "ifModifiedSince" header with date in Greenwich Mean Time (GMT). |
| 99 String formatted = _HttpUtils.formatDate(ifModifiedSince.toUtc()); |
| 100 _set("if-modified-since", formatted); |
| 101 } |
| 102 |
| 84 Date get date() { | 103 Date get date() { |
| 85 List<String> values = _headers["date"]; | 104 List<String> values = _headers["date"]; |
| 86 if (values != null) { | 105 if (values != null) { |
| 87 try { | 106 try { |
| 88 return _HttpUtils.parseDate(values[0]); | 107 return _HttpUtils.parseDate(values[0]); |
| 89 } catch (Exception e) { | 108 } catch (Exception e) { |
| 90 return null; | 109 return null; |
| 91 } | 110 } |
| 92 } | 111 } |
| 93 return null; | 112 return null; |
| 94 } | 113 } |
| 95 | 114 |
| 96 void set date(Date date) { | 115 void set date(Date date) { |
| 97 _checkMutable(); | 116 _checkMutable(); |
| 98 // Format "Date" header with date in Greenwich Mean Time (GMT). | 117 // Format "Date" header with date in Greenwich Mean Time (GMT). |
| 99 String formatted = _HttpUtils.formatDate(expires.toUtc()); | 118 String formatted = _HttpUtils.formatDate(date.toUtc()); |
| 100 _set("date", formatted); | 119 _set("date", formatted); |
| 101 } | 120 } |
| 102 | 121 |
| 103 Date get expires() { | 122 Date get expires() { |
| 104 List<String> values = _headers["expires"]; | 123 List<String> values = _headers["expires"]; |
| 105 if (values != null) { | 124 if (values != null) { |
| 106 try { | 125 try { |
| 107 return _HttpUtils.parseDate(values[0]); | 126 return _HttpUtils.parseDate(values[0]); |
| 108 } catch (Exception e) { | 127 } catch (Exception e) { |
| 109 return null; | 128 return null; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 throw new HttpException("Unexpected type for header named $name"); | 163 throw new HttpException("Unexpected type for header named $name"); |
| 145 } | 164 } |
| 146 } else if (name.toLowerCase() == "expires") { | 165 } else if (name.toLowerCase() == "expires") { |
| 147 if (value is Date) { | 166 if (value is Date) { |
| 148 expires = value; | 167 expires = value; |
| 149 } else if (value is String) { | 168 } else if (value is String) { |
| 150 _set("expires", value); | 169 _set("expires", value); |
| 151 } else { | 170 } else { |
| 152 throw new HttpException("Unexpected type for header named $name"); | 171 throw new HttpException("Unexpected type for header named $name"); |
| 153 } | 172 } |
| 173 } else if (name.toLowerCase() == "if-modified-since") { |
| 174 if (value is Date) { |
| 175 ifModifiedSince = value; |
| 176 } else if (value is String) { |
| 177 _set("if-modified-since", value); |
| 178 } else { |
| 179 throw new HttpException("Unexpected type for header named $name"); |
| 180 } |
| 154 } else if (name.toLowerCase() == "host") { | 181 } else if (name.toLowerCase() == "host") { |
| 155 int pos = value.indexOf(":"); | 182 int pos = value.indexOf(":"); |
| 156 if (pos == -1) { | 183 if (pos == -1) { |
| 157 _host = value; | 184 _host = value; |
| 158 _port = HttpClient.DEFAULT_HTTP_PORT; | 185 _port = HttpClient.DEFAULT_HTTP_PORT; |
| 159 } else { | 186 } else { |
| 160 if (pos > 0) { | 187 if (pos > 0) { |
| 161 _host = value.substring(0, pos); | 188 _host = value.substring(0, pos); |
| 162 } else { | 189 } else { |
| 163 _host = null; | 190 _host = null; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 175 } | 202 } |
| 176 } else if (name.toLowerCase() == "content-type") { | 203 } else if (name.toLowerCase() == "content-type") { |
| 177 _set("content-type", value); | 204 _set("content-type", value); |
| 178 } else { | 205 } else { |
| 179 name = name.toLowerCase(); | 206 name = name.toLowerCase(); |
| 180 List<String> values = _headers[name]; | 207 List<String> values = _headers[name]; |
| 181 if (values == null) { | 208 if (values == null) { |
| 182 values = new List<String>(); | 209 values = new List<String>(); |
| 183 _headers[name] = values; | 210 _headers[name] = values; |
| 184 } | 211 } |
| 185 values.add(value.toString()); | 212 if (value is Date) { |
| 213 values.add(_HttpUtils.formatDate(value)); |
| 214 } else { |
| 215 values.add(value.toString()); |
| 216 } |
| 186 } | 217 } |
| 187 } | 218 } |
| 188 | 219 |
| 189 void _set(String name, String value) { | 220 void _set(String name, String value) { |
| 190 name = name.toLowerCase(); | 221 name = name.toLowerCase(); |
| 191 List<String> values = new List<String>(); | 222 List<String> values = new List<String>(); |
| 192 _headers[name] = values; | 223 _headers[name] = values; |
| 193 values.add(value); | 224 values.add(value); |
| 194 } | 225 } |
| 195 | 226 |
| (...skipping 1939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2135 | 2166 |
| 2136 | 2167 |
| 2137 class _RedirectInfo implements RedirectInfo { | 2168 class _RedirectInfo implements RedirectInfo { |
| 2138 const _RedirectInfo(int this.statusCode, | 2169 const _RedirectInfo(int this.statusCode, |
| 2139 String this.method, | 2170 String this.method, |
| 2140 Uri this.location); | 2171 Uri this.location); |
| 2141 final int statusCode; | 2172 final int statusCode; |
| 2142 final String method; | 2173 final String method; |
| 2143 final Uri location; | 2174 final Uri location; |
| 2144 } | 2175 } |
| OLD | NEW |