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

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

Issue 11359085: Refactor HTTP parser to hold current buffer (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed more comments Created 8 years, 1 month 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 | « no previous file | sdk/lib/io/http_parser.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) 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 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 1300
1301 void _onData() { 1301 void _onData() {
1302 int available = _socket.available(); 1302 int available = _socket.available();
1303 if (available == 0) { 1303 if (available == 0) {
1304 return; 1304 return;
1305 } 1305 }
1306 1306
1307 List<int> buffer = new Uint8List(available); 1307 List<int> buffer = new Uint8List(available);
1308 int bytesRead = _socket.readList(buffer, 0, available); 1308 int bytesRead = _socket.readList(buffer, 0, available);
1309 if (bytesRead > 0) { 1309 if (bytesRead > 0) {
1310 int parsed = _httpParser.writeList(buffer, 0, bytesRead); 1310 _httpParser.writeList(buffer, 0, bytesRead);
1311 if (!_httpParser.upgrade) {
1312 if (parsed != bytesRead) {
1313 if (_socket != null) {
1314 // TODO(sgjesse): Error handling.
1315 _destroy();
1316 }
1317 }
1318 }
1319 } 1311 }
1320 } 1312 }
1321 1313
1322 void _onClosed() { 1314 void _onClosed() {
1323 _closing = true; 1315 _closing = true;
1324 _onConnectionClosed(null); 1316 _onConnectionClosed(null);
1325 } 1317 }
1326 1318
1327 void _onError(e) { 1319 void _onError(e) {
1328 // If an error occurs, make sure to close the socket if one is associated. 1320 // If an error occurs, make sure to close the socket if one is associated.
1329 _error = true; 1321 _error = true;
1330 if (_socket != null) { 1322 if (_socket != null) {
1331 _socket.close(); 1323 _socket.close();
1332 } 1324 }
1333 _onConnectionClosed(e); 1325 _onConnectionClosed(e);
1334 } 1326 }
1335 1327
1336 DetachedSocket _detachSocket() { 1328 DetachedSocket _detachSocket() {
1337 _socket.onData = null; 1329 _socket.onData = null;
1338 _socket.onClosed = null; 1330 _socket.onClosed = null;
1339 _socket.onError = null; 1331 _socket.onError = null;
1340 _socket.outputStream.onNoPendingWrites = null; 1332 _socket.outputStream.onNoPendingWrites = null;
1341 Socket socket = _socket; 1333 Socket socket = _socket;
1342 _socket = null; 1334 _socket = null;
1343 if (onDetach != null) onDetach(); 1335 if (onDetach != null) onDetach();
1344 return new _DetachedSocket(socket, _httpParser.unparsedData); 1336 return new _DetachedSocket(socket, _httpParser.readUnparsedData());
1345 } 1337 }
1346 1338
1347 HttpConnectionInfo get connectionInfo { 1339 HttpConnectionInfo get connectionInfo {
1348 if (_socket == null || _closing || _error) return null; 1340 if (_socket == null || _closing || _error) return null;
1349 try { 1341 try {
1350 _HttpConnectionInfo info = new _HttpConnectionInfo(); 1342 _HttpConnectionInfo info = new _HttpConnectionInfo();
1351 info.remoteHost = _socket.remoteHost; 1343 info.remoteHost = _socket.remoteHost;
1352 info.remotePort = _socket.remotePort; 1344 info.remotePort = _socket.remotePort;
1353 info.localPort = _socket.port; 1345 info.localPort = _socket.port;
1354 return info; 1346 return info;
(...skipping 1305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2660 2652
2661 2653
2662 class _RedirectInfo implements RedirectInfo { 2654 class _RedirectInfo implements RedirectInfo {
2663 const _RedirectInfo(int this.statusCode, 2655 const _RedirectInfo(int this.statusCode,
2664 String this.method, 2656 String this.method,
2665 Uri this.location); 2657 Uri this.location);
2666 final int statusCode; 2658 final int statusCode;
2667 final String method; 2659 final String method;
2668 final Uri location; 2660 final Uri location;
2669 } 2661 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/http_parser.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698