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

Side by Side Diff: sdk/lib/io/http_headers.dart

Issue 443373003: Make the default HTTP server configuration more secure (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed more review comments Created 6 years, 4 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
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpHeaders implements HttpHeaders { 7 class _HttpHeaders implements HttpHeaders {
8 final Map<String, List<String>> _headers; 8 final Map<String, List<String>> _headers;
9 final String protocolVersion; 9 final String protocolVersion;
10 10
11 bool _mutable = true; // Are the headers currently mutable? 11 bool _mutable = true; // Are the headers currently mutable?
12 List<String> _noFoldingHeaders; 12 List<String> _noFoldingHeaders;
13 13
14 int _contentLength = -1; 14 int _contentLength = -1;
15 bool _persistentConnection = true; 15 bool _persistentConnection = true;
16 bool _chunkedTransferEncoding = false; 16 bool _chunkedTransferEncoding = false;
17 String _host; 17 String _host;
18 int _port; 18 int _port;
19 19
20 final int _defaultPortForScheme; 20 final int _defaultPortForScheme;
21 21
22 _HttpHeaders(this.protocolVersion, 22 _HttpHeaders(this.protocolVersion,
23 {int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT}) 23 {int defaultPortForScheme: HttpClient.DEFAULT_HTTP_PORT,
24 _HttpHeaders initialHeaders})
24 : _headers = new HashMap<String, List<String>>(), 25 : _headers = new HashMap<String, List<String>>(),
25 _defaultPortForScheme = defaultPortForScheme { 26 _defaultPortForScheme = defaultPortForScheme {
27 if (initialHeaders != null) {
28 initialHeaders._headers.forEach((name, value) => _headers[name] = value);
29 _contentLength = initialHeaders._contentLength;
30 _persistentConnection = initialHeaders._persistentConnection;
31 _chunkedTransferEncoding = initialHeaders._chunkedTransferEncoding;
32 _host = initialHeaders._host;
33 _port = initialHeaders._port;
34 }
26 if (protocolVersion == "1.0") { 35 if (protocolVersion == "1.0") {
27 _persistentConnection = false; 36 _persistentConnection = false;
37 _chunkedTransferEncoding = false;
28 } 38 }
29 } 39 }
30 40
31 List<String> operator[](String name) => _headers[name.toLowerCase()]; 41 List<String> operator[](String name) => _headers[name.toLowerCase()];
32 42
33 String value(String name) { 43 String value(String name) {
34 name = name.toLowerCase(); 44 name = name.toLowerCase();
35 List<String> values = _headers[name]; 45 List<String> values = _headers[name];
36 if (values == null) return null; 46 if (values == null) return null;
37 if (values.length > 1) { 47 if (values.length > 1) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 } else { 255 } else {
246 return null; 256 return null;
247 } 257 }
248 } 258 }
249 259
250 void set contentType(ContentType contentType) { 260 void set contentType(ContentType contentType) {
251 _checkMutable(); 261 _checkMutable();
252 _set(HttpHeaders.CONTENT_TYPE, contentType.toString()); 262 _set(HttpHeaders.CONTENT_TYPE, contentType.toString());
253 } 263 }
254 264
265 void clear() {
266 _checkMutable();
267 _headers.clear();
268 _contentLength = -1;
269 _persistentConnection = true;
270 _chunkedTransferEncoding = false;
271 _host = null;
272 _port = null;
273 }
274
255 // [name] must be a lower-case version of the name. 275 // [name] must be a lower-case version of the name.
256 void _add(String name, value) { 276 void _add(String name, value) {
257 assert(name == _validateField(name)); 277 assert(name == _validateField(name));
258 // Use the length as index on what method to call. This is notable 278 // Use the length as index on what method to call. This is notable
259 // faster than computing hash and looking up in a hash-map. 279 // faster than computing hash and looking up in a hash-map.
260 switch (name.length) { 280 switch (name.length) {
261 case 4: 281 case 4:
262 if (HttpHeaders.DATE == name) { 282 if (HttpHeaders.DATE == name) {
263 _addDate(name, value); 283 _addDate(name, value);
264 return; 284 return;
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 String name; 814 String name;
795 String value; 815 String value;
796 DateTime expires; 816 DateTime expires;
797 int maxAge; 817 int maxAge;
798 String domain; 818 String domain;
799 String path; 819 String path;
800 bool httpOnly = false; 820 bool httpOnly = false;
801 bool secure = false; 821 bool secure = false;
802 822
803 _Cookie([this.name, this.value]) { 823 _Cookie([this.name, this.value]) {
824 // Default value of httponly is true.
825 httpOnly = true;
804 _validate(); 826 _validate();
805 } 827 }
806 828
807 _Cookie.fromSetCookieValue(String value) { 829 _Cookie.fromSetCookieValue(String value) {
808 // Parse the 'set-cookie' header value. 830 // Parse the 'set-cookie' header value.
809 _parseSetCookieValue(value); 831 _parseSetCookieValue(value);
810 } 832 }
811 833
812 // Parse a 'set-cookie' header value according to the rules in RFC 6265. 834 // Parse a 'set-cookie' header value according to the rules in RFC 6265.
813 void _parseSetCookieValue(String s) { 835 void _parseSetCookieValue(String s) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 (codeUnit >= 0x23 && codeUnit <= 0x2B) || 957 (codeUnit >= 0x23 && codeUnit <= 0x2B) ||
936 (codeUnit >= 0x2D && codeUnit <= 0x3A) || 958 (codeUnit >= 0x2D && codeUnit <= 0x3A) ||
937 (codeUnit >= 0x3C && codeUnit <= 0x5B) || 959 (codeUnit >= 0x3C && codeUnit <= 0x5B) ||
938 (codeUnit >= 0x5D && codeUnit <= 0x7E))) { 960 (codeUnit >= 0x5D && codeUnit <= 0x7E))) {
939 throw new FormatException( 961 throw new FormatException(
940 "Invalid character in cookie value, code unit: '$codeUnit'"); 962 "Invalid character in cookie value, code unit: '$codeUnit'");
941 } 963 }
942 } 964 }
943 } 965 }
944 } 966 }
OLDNEW
« no previous file with comments | « sdk/lib/io/http.dart ('k') | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698