Chromium Code Reviews| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 return new ContentType(); | 146 return new ContentType(); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void set contentType(ContentType contentType) { | 150 void set contentType(ContentType contentType) { |
| 151 _checkMutable(); | 151 _checkMutable(); |
| 152 _set("content-type", contentType.toString()); | 152 _set("content-type", contentType.toString()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void _add(String name, Object value) { | 155 void _add(String name, Object value) { |
| 156 var lowerCaseName = name.toLowerCase(); | |
| 156 // TODO(sgjesse): Add immutable state throw HttpException is immutable. | 157 // TODO(sgjesse): Add immutable state throw HttpException is immutable. |
| 157 if (name.toLowerCase() == "date") { | 158 if (lowerCaseName == "date") { |
| 158 if (value is Date) { | 159 if (value is Date) { |
| 159 date = value; | 160 date = value; |
| 160 } else if (value is String) { | 161 } else if (value is String) { |
| 161 _set("date", value); | 162 _set("date", value); |
| 162 } else { | 163 } else { |
| 163 throw new HttpException("Unexpected type for header named $name"); | 164 throw new HttpException("Unexpected type for header named $name"); |
| 164 } | 165 } |
| 165 } else if (name.toLowerCase() == "expires") { | 166 } else if (lowerCaseName == "expires") { |
| 166 if (value is Date) { | 167 if (value is Date) { |
| 167 expires = value; | 168 expires = value; |
| 168 } else if (value is String) { | 169 } else if (value is String) { |
| 169 _set("expires", value); | 170 _set("expires", value); |
| 170 } else { | 171 } else { |
| 171 throw new HttpException("Unexpected type for header named $name"); | 172 throw new HttpException("Unexpected type for header named $name"); |
| 172 } | 173 } |
| 173 } else if (name.toLowerCase() == "if-modified-since") { | 174 } else if (lowerCaseName == "if-modified-since") { |
| 174 if (value is Date) { | 175 if (value is Date) { |
| 175 ifModifiedSince = value; | 176 ifModifiedSince = value; |
| 176 } else if (value is String) { | 177 } else if (value is String) { |
| 177 _set("if-modified-since", value); | 178 _set("if-modified-since", value); |
| 178 } else { | 179 } else { |
| 179 throw new HttpException("Unexpected type for header named $name"); | 180 throw new HttpException("Unexpected type for header named $name"); |
| 180 } | 181 } |
| 181 } else if (name.toLowerCase() == "host") { | 182 } else if (lowerCaseName == "host") { |
| 182 int pos = value.indexOf(":"); | 183 int pos = value.indexOf(":"); |
| 183 if (pos == -1) { | 184 if (pos == -1) { |
| 184 _host = value; | 185 _host = value; |
| 185 _port = HttpClient.DEFAULT_HTTP_PORT; | 186 _port = HttpClient.DEFAULT_HTTP_PORT; |
| 186 } else { | 187 } else { |
| 187 if (pos > 0) { | 188 if (pos > 0) { |
| 188 _host = value.substring(0, pos); | 189 _host = value.substring(0, pos); |
| 189 } else { | 190 } else { |
| 190 _host = null; | 191 _host = null; |
| 191 } | 192 } |
| 192 if (pos + 1 == value.length) { | 193 if (pos + 1 == value.length) { |
| 193 _port = HttpClient.DEFAULT_HTTP_PORT; | 194 _port = HttpClient.DEFAULT_HTTP_PORT; |
| 194 } else { | 195 } else { |
| 195 try { | 196 try { |
| 196 _port = parseInt(value.substring(pos + 1)); | 197 _port = parseInt(value.substring(pos + 1)); |
| 197 } on FormatException catch (e) { | 198 } on FormatException catch (e) { |
| 198 _port = null; | 199 _port = null; |
| 199 } | 200 } |
| 200 } | 201 } |
| 201 _set("host", value); | 202 _set("host", value); |
| 202 } | 203 } |
| 203 } else if (name.toLowerCase() == "content-type") { | 204 } else if (lowerCaseName == "content-type") { |
| 204 _set("content-type", value); | 205 _set("content-type", value); |
| 205 } else { | 206 } else { |
| 206 name = name.toLowerCase(); | 207 name = lowerCaseName; |
|
Søren Gjesse
2012/11/15 12:24:11
This line is not needed. Just use lowerCaseName tw
| |
| 207 List<String> values = _headers[name]; | 208 List<String> values = _headers[name]; |
| 208 if (values == null) { | 209 if (values == null) { |
| 209 values = new List<String>(); | 210 values = new List<String>(); |
| 210 _headers[name] = values; | 211 _headers[name] = values; |
| 211 } | 212 } |
| 212 if (value is Date) { | 213 if (value is Date) { |
| 213 values.add(_HttpUtils.formatDate(value)); | 214 values.add(_HttpUtils.formatDate(value)); |
| 214 } else { | 215 } else { |
| 215 values.add(value.toString()); | 216 values.add(value.toString()); |
| 216 } | 217 } |
| (...skipping 2471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2688 | 2689 |
| 2689 | 2690 |
| 2690 class _RedirectInfo implements RedirectInfo { | 2691 class _RedirectInfo implements RedirectInfo { |
| 2691 const _RedirectInfo(int this.statusCode, | 2692 const _RedirectInfo(int this.statusCode, |
| 2692 String this.method, | 2693 String this.method, |
| 2693 Uri this.location); | 2694 Uri this.location); |
| 2694 final int statusCode; | 2695 final int statusCode; |
| 2695 final String method; | 2696 final String method; |
| 2696 final Uri location; | 2697 final Uri location; |
| 2697 } | 2698 } |
| OLD | NEW |