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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 245 |
246 _write(_HttpConnectionBase connection) { | 246 _write(_HttpConnectionBase connection) { |
247 final COLONSP = const [_CharCode.COLON, _CharCode.SP]; | 247 final COLONSP = const [_CharCode.COLON, _CharCode.SP]; |
248 final COMMASP = const [_CharCode.COMMA, _CharCode.SP]; | 248 final COMMASP = const [_CharCode.COMMA, _CharCode.SP]; |
249 final CRLF = const [_CharCode.CR, _CharCode.LF]; | 249 final CRLF = const [_CharCode.CR, _CharCode.LF]; |
250 | 250 |
251 // Format headers. | 251 // Format headers. |
252 _headers.forEach((String name, List<String> values) { | 252 _headers.forEach((String name, List<String> values) { |
253 bool fold = _foldHeader(name); | 253 bool fold = _foldHeader(name); |
254 List<int> data; | 254 List<int> data; |
255 data = name.charCodes(); | 255 data = name.charCodes; |
256 connection._write(data); | 256 connection._write(data); |
257 connection._write(COLONSP); | 257 connection._write(COLONSP); |
258 for (int i = 0; i < values.length; i++) { | 258 for (int i = 0; i < values.length; i++) { |
259 if (i > 0) { | 259 if (i > 0) { |
260 if (fold) { | 260 if (fold) { |
261 connection._write(COMMASP); | 261 connection._write(COMMASP); |
262 } else { | 262 } else { |
263 connection._write(CRLF); | 263 connection._write(CRLF); |
264 data = name.charCodes(); | 264 data = name.charCodes; |
265 connection._write(data); | 265 connection._write(data); |
266 connection._write(COLONSP); | 266 connection._write(COLONSP); |
267 } | 267 } |
268 } | 268 } |
269 data = values[i].charCodes(); | 269 data = values[i].charCodes; |
270 connection._write(data); | 270 connection._write(data); |
271 } | 271 } |
272 connection._write(CRLF); | 272 connection._write(CRLF); |
273 }); | 273 }); |
274 } | 274 } |
275 | 275 |
276 String toString() { | 276 String toString() { |
277 StringBuffer sb = new StringBuffer(); | 277 StringBuffer sb = new StringBuffer(); |
278 _headers.forEach((String name, List<String> values) { | 278 _headers.forEach((String name, List<String> values) { |
279 sb.add(name); | 279 sb.add(name); |
(...skipping 823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 throw new HttpException("Content length required for HTTP 1.0"); | 1103 throw new HttpException("Content length required for HTTP 1.0"); |
1104 } | 1104 } |
1105 | 1105 |
1106 // Write status line. | 1106 // Write status line. |
1107 if (_protocolVersion == "1.1") { | 1107 if (_protocolVersion == "1.1") { |
1108 _httpConnection._write(_Const.HTTP11); | 1108 _httpConnection._write(_Const.HTTP11); |
1109 } else { | 1109 } else { |
1110 _httpConnection._write(_Const.HTTP10); | 1110 _httpConnection._write(_Const.HTTP10); |
1111 } | 1111 } |
1112 _writeSP(); | 1112 _writeSP(); |
1113 data = _statusCode.toString().charCodes(); | 1113 data = _statusCode.toString().charCodes; |
1114 _httpConnection._write(data); | 1114 _httpConnection._write(data); |
1115 _writeSP(); | 1115 _writeSP(); |
1116 data = reasonPhrase.charCodes(); | 1116 data = reasonPhrase.charCodes; |
1117 _httpConnection._write(data); | 1117 _httpConnection._write(data); |
1118 _writeCRLF(); | 1118 _writeCRLF(); |
1119 | 1119 |
1120 // Determine the value of the "Transfer-Encoding" header based on | 1120 // Determine the value of the "Transfer-Encoding" header based on |
1121 // whether the content length is known. | 1121 // whether the content length is known. |
1122 if (_contentLength >= 0) { | 1122 if (_contentLength >= 0) { |
1123 _headers.set(HttpHeaders.CONTENT_LENGTH, _contentLength.toString()); | 1123 _headers.set(HttpHeaders.CONTENT_LENGTH, _contentLength.toString()); |
1124 } else if (_contentLength < 0) { | 1124 } else if (_contentLength < 0) { |
1125 _headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); | 1125 _headers.set(HttpHeaders.TRANSFER_ENCODING, "chunked"); |
1126 } | 1126 } |
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 } | 1662 } |
1663 | 1663 |
1664 void _streamSetErrorHandler(callback(e)) { | 1664 void _streamSetErrorHandler(callback(e)) { |
1665 _streamErrorHandler = callback; | 1665 _streamErrorHandler = callback; |
1666 } | 1666 } |
1667 | 1667 |
1668 void _writeHeader() { | 1668 void _writeHeader() { |
1669 List<int> data; | 1669 List<int> data; |
1670 | 1670 |
1671 // Write request line. | 1671 // Write request line. |
1672 data = _method.toString().charCodes(); | 1672 data = _method.toString().charCodes; |
1673 _httpConnection._write(data); | 1673 _httpConnection._write(data); |
1674 _writeSP(); | 1674 _writeSP(); |
1675 // Send the path for direct connections and the whole URL for | 1675 // Send the path for direct connections and the whole URL for |
1676 // proxy connections. | 1676 // proxy connections. |
1677 if (!_connection._usingProxy) { | 1677 if (!_connection._usingProxy) { |
1678 String path = _uri.path; | 1678 String path = _uri.path; |
1679 if (path.length == 0) path = "/"; | 1679 if (path.length == 0) path = "/"; |
1680 if (_uri.query != "") { | 1680 if (_uri.query != "") { |
1681 if (_uri.fragment != "") { | 1681 if (_uri.fragment != "") { |
1682 path = "${path}?${_uri.query}#${_uri.fragment}"; | 1682 path = "${path}?${_uri.query}#${_uri.fragment}"; |
1683 } else { | 1683 } else { |
1684 path = "${path}?${_uri.query}"; | 1684 path = "${path}?${_uri.query}"; |
1685 } | 1685 } |
1686 } | 1686 } |
1687 data = path.charCodes(); | 1687 data = path.charCodes; |
1688 } else { | 1688 } else { |
1689 data = _uri.toString().charCodes(); | 1689 data = _uri.toString().charCodes; |
1690 } | 1690 } |
1691 _httpConnection._write(data); | 1691 _httpConnection._write(data); |
1692 _writeSP(); | 1692 _writeSP(); |
1693 _httpConnection._write(_Const.HTTP11); | 1693 _httpConnection._write(_Const.HTTP11); |
1694 _writeCRLF(); | 1694 _writeCRLF(); |
1695 | 1695 |
1696 // Determine the value of the "Transfer-Encoding" header based on | 1696 // Determine the value of the "Transfer-Encoding" header based on |
1697 // whether the content length is known. If there is no content | 1697 // whether the content length is known. If there is no content |
1698 // neither "Content-Length" nor "Transfer-Encoding" is set | 1698 // neither "Content-Length" nor "Transfer-Encoding" is set |
1699 if (_contentLength > 0) { | 1699 if (_contentLength > 0) { |
(...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 | 2346 |
2347 | 2347 |
2348 class _RedirectInfo implements RedirectInfo { | 2348 class _RedirectInfo implements RedirectInfo { |
2349 const _RedirectInfo(int this.statusCode, | 2349 const _RedirectInfo(int this.statusCode, |
2350 String this.method, | 2350 String this.method, |
2351 Uri this.location); | 2351 Uri this.location); |
2352 final int statusCode; | 2352 final int statusCode; |
2353 final String method; | 2353 final String method; |
2354 final Uri location; | 2354 final Uri location; |
2355 } | 2355 } |
OLD | NEW |