Index: sdk/lib/io/http_headers.dart |
diff --git a/sdk/lib/io/http_headers.dart b/sdk/lib/io/http_headers.dart |
index 5dd5c55fd064e50f44e9c3e7d43047a2c3dc0518..b695f05b1fb73315e46b0408b48e4dc60ceefbb9 100644 |
--- a/sdk/lib/io/http_headers.dart |
+++ b/sdk/lib/io/http_headers.dart |
@@ -28,10 +28,10 @@ class _HttpHeaders implements HttpHeaders { |
} |
} |
- List<String> operator[](String name) => _headers[name.toLowerCase()]; |
+ List<String> operator[](String name) => _headers[_toLowerCase(name)]; |
String value(String name) { |
- name = name.toLowerCase(); |
+ name = _toLowerCase(name); |
List<String> values = _headers[name]; |
if (values == null) return null; |
if (values.length > 1) { |
@@ -42,7 +42,7 @@ class _HttpHeaders implements HttpHeaders { |
void add(String name, value) { |
_checkMutable(); |
- _addAll(name.toLowerCase(), value); |
+ _addAll(_toLowerCase(name), value); |
} |
void _addAll(String name, value) { |
@@ -55,14 +55,14 @@ class _HttpHeaders implements HttpHeaders { |
void set(String name, Object value) { |
_checkMutable(); |
- name = name.toLowerCase(); |
+ name = _toLowerCase(name); |
_headers.remove(name); |
_addAll(name, value); |
} |
void remove(String name, Object value) { |
_checkMutable(); |
- name = name.toLowerCase(); |
+ name = _toLowerCase(name); |
List<String> values = _headers[name]; |
if (values != null) { |
int index = values.indexOf(value); |
@@ -75,7 +75,7 @@ class _HttpHeaders implements HttpHeaders { |
void removeAll(String name) { |
_checkMutable(); |
- name = name.toLowerCase(); |
+ name = _toLowerCase(name); |
_headers.remove(name); |
} |
@@ -329,7 +329,7 @@ class _HttpHeaders implements HttpHeaders { |
break; |
case HttpHeaders.CONNECTION: |
- var lowerCaseValue = value.toLowerCase(); |
+ var lowerCaseValue = _toLowerCase(value); |
if (lowerCaseValue == 'close') { |
_persistentConnection = false; |
} else if (lowerCaseValue == 'keep-alive') { |
@@ -361,7 +361,7 @@ class _HttpHeaders implements HttpHeaders { |
} |
void _set(String name, String value) { |
- assert(name == name.toLowerCase()); |
+ assert(name == _toLowerCase(name)); |
List<String> values = new List<String>(); |
_headers[name] = values; |
values.add(value); |
@@ -518,6 +518,26 @@ class _HttpHeaders implements HttpHeaders { |
} |
return cookies; |
} |
+ |
+ static String _toLowerCase(String str) { |
+ int toLowerCase(int byte) { |
+ final int aCode = "A".codeUnitAt(0); |
kevmoo
2014/03/24 17:50:16
Is this only run the first time the method is call
Anders Johnsen
2014/03/24 19:02:59
When looking at the SSA of the VM, it's heavily in
kevmoo
2014/03/24 19:04:05
If they are only used in http_headers, just leave
Anders Johnsen
2014/03/24 19:05:04
Yeah, but so far there is two places it's used (pa
Søren Gjesse
2014/03/25 07:54:25
Yes, as you have noticed we have the _CharCodes co
|
+ final int zCode = "Z".codeUnitAt(0); |
+ final int delta = "a".codeUnitAt(0) - aCode; |
+ return (aCode <= byte && byte <= zCode) ? byte + delta : byte; |
+ } |
+ |
+ final length = str.length; |
+ var result = new List(length); |
+ for (int i = 0; i < length; i++) { |
+ int codeUnit = str.codeUnitAt(i); |
+ if (codeUnit > 127) { |
+ throw new HttpException("HTTP header must be in ASCII encoding"); |
+ } |
+ result[i] = toLowerCase(codeUnit); |
Søren Gjesse
2014/03/25 07:54:25
I don't see the need to a function call here (even
Anders Johnsen
2014/03/25 13:33:40
Pulled out and shared across all of IO.
|
+ } |
+ return new String.fromCharCodes(result); |
+ } |
} |