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

Unified Diff: runtime/bin/http_parser.dart

Issue 10205012: Initial web socket server implementation (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments from ajohnsen@ and ager@ Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/http_parser.dart
diff --git a/runtime/bin/http_parser.dart b/runtime/bin/http_parser.dart
index 074538d441d2ba23d76eebefc44607ddc63bf0a7..ee3dcc83662255818424cebb8cab3d5d37cc995b 100644
--- a/runtime/bin/http_parser.dart
+++ b/runtime/bin/http_parser.dart
@@ -145,6 +145,9 @@ class _HttpParser {
if (_state == _State.UPGRADED) {
throw new HttpParserException("Data on upgraded connection");
}
+ if (_state == _State.FAILURE) {
+ throw new HttpParserException("Data on failed connection");
+ }
while ((index < lastIndex) && _state != _State.FAILURE && _state != _State.UPGRADED) {
int byte = buffer[index];
switch (_state) {
@@ -368,9 +371,10 @@ class _HttpParser {
} else {
String headerField = _headerField.toString();
String headerValue =_headerValue.toString();
- // Ignore the Content-Length header if Transfer-Encoding
- // is chunked (RFC 2616 section 4.4)
+ bool reportHeader = true;
if (headerField == "content-length" && !_chunked) {
+ // Ignore the Content-Length header if Transfer-Encoding
+ // is chunked (RFC 2616 section 4.4)
_contentLength = Math.parseInt(headerValue);
} else if (headerField == "connection") {
List<String> tokens = _tokenizeFieldValue(headerValue);
@@ -383,13 +387,19 @@ class _HttpParser {
} else if (token == "upgrade") {
_connectionUpgrade = true;
}
+ if (headerReceived != null) {
+ headerReceived(headerField, token);
+ }
}
+ reportHeader = false;
} else if (headerField == "transfer-encoding" &&
headerValue.toLowerCase() == "chunked") {
+ // Ignore the Content-Length header if Transfer-Encoding
+ // is chunked (RFC 2616 section 4.4)
_chunked = true;
_contentLength = -1;
}
- if (headerReceived != null) {
+ if (reportHeader && headerReceived != null) {
headerReceived(headerField, headerValue);
}
_headerField.clear();
@@ -483,7 +493,7 @@ class _HttpParser {
break;
case _State.BODY:
- // The body is not handled one byte at the time but in blocks.
+ // The body is not handled one byte at a time but in blocks.
int dataAvailable = lastIndex - index;
ByteArray data;
if (_remainingContent == null ||

Powered by Google App Engine
This is Rietveld 408576698