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

Unified Diff: pkg/http/lib/src/mock_client.dart

Issue 11348309: Keep around a copy of the http.Request that triggered each Response. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: pkg/http/lib/src/mock_client.dart
diff --git a/pkg/http/lib/src/mock_client.dart b/pkg/http/lib/src/mock_client.dart
index ce2916f97865c1bf910ade964a84d7c678bba098..90c5d1926038e148e3cf8f09076d04024ddf1841 100644
--- a/pkg/http/lib/src/mock_client.dart
+++ b/pkg/http/lib/src/mock_client.dart
@@ -25,10 +25,12 @@ class MockClient extends BaseClient {
/// [StreamedResponse]s.
final MockClientStreamHandler _handler;
+ MockClient._(this._handler);
+
/// Creates a [MockClient] with a handler that receives [Request]s and sends
/// [Response]s.
MockClient(MockClientHandler fn)
- : this.streaming((baseRequest, bodyStream) {
+ : this._((baseRequest, bodyStream) {
return consumeInputStream(bodyStream).chain((bodyBytes) {
var request = new Request(baseRequest.method, baseRequest.url);
request.persistentConnection = baseRequest.persistentConnection;
@@ -48,6 +50,7 @@ class MockClient extends BaseClient {
stream,
response.statusCode,
response.contentLength,
+ request: baseRequest,
headers: response.headers,
isRedirect: response.isRedirect,
persistentConnection: response.persistentConnection,
@@ -57,7 +60,20 @@ class MockClient extends BaseClient {
/// Creates a [MockClient] with a handler that receives [StreamedRequest]s and
/// sends [StreamedResponse]s.
- MockClient.streaming(MockClientStreamHandler this._handler);
+ MockClient.streaming(MockClientStreamHandler fn)
+ : this._((request, bodyStream) {
+ return fn(request, bodyStream).transform((response) {
+ return new StreamedResponse(
+ response.stream,
+ response.statusCode,
+ response.contentLength,
+ request: request,
+ headers: response.headers,
+ isRedirect: response.isRedirect,
+ persistentConnection: response.persistentConnection,
+ reasonPhrase: response.reasonPhrase);
+ });
+ });
/// Sends a request.
Future<StreamedResponse> send(BaseRequest request) {

Powered by Google App Engine
This is Rietveld 408576698