Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #46 from platelk/master
Browse files Browse the repository at this point in the history
Correction error multiple read on shelf request
  • Loading branch information
luizmineo committed Oct 25, 2014
2 parents 673507d + 5ec9b7c commit 3ecc601
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lib/mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,13 @@ class MockRequest extends HttpRequestParser implements UnparsedRequest {

void parseBodyType() => parseHttpRequestBodyType(headers);

Future parseBody() => parseHttpRequestBody(shelfRequest.read());

Future parseBody() {
if (bodyHasBeenParsed() == false) {
return parseHttpRequestBody(_shelfRequest.read());
} else {
return parseHttpRequestBody(null);
}
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@ class HttpRequestParser {
}
}

bool bodyHasBeenParsed() {
return _bodyParsed != null;
}

Future parseHttpRequestBody(Stream<List<int>> body) {
if (_bodyParsed == null) {
_bodyParsed = _parseRequestBody(body, _contentType).then((HttpBody reqBody) {
Expand Down
9 changes: 8 additions & 1 deletion lib/src/server_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ class _RequestImpl extends HttpRequestParser implements UnparsedRequest {

void parseBodyType() => parseHttpRequestBodyType(headers);

Future parseBody() => parseHttpRequestBody(_shelfRequest.read());
Future parseBody() {
if (bodyHasBeenParsed() == false) {
return parseHttpRequestBody(_shelfRequest.read());
} else {
return parseHttpRequestBody(null);
}

}

}

Expand Down

0 comments on commit 3ecc601

Please sign in to comment.