diff --git a/CHANGELOG.md b/CHANGELOG.md index aec74ee..730a261 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 0.2.0 (2022-12-30) +- [FIXED] Fixed a bug that failed to apply censors to recorded data. + ## 0.1.1 (2022-12-12) - [ADDED] Documentation to README.md - [CHANGED] `AdvancedSettings` now named `AdvancedOptions` diff --git a/lib/src/request_elements/http_interaction.dart b/lib/src/request_elements/http_interaction.dart index 9ae283b..a678868 100644 --- a/lib/src/request_elements/http_interaction.dart +++ b/lib/src/request_elements/http_interaction.dart @@ -1,7 +1,6 @@ import 'dart:convert'; import 'package:dartvcr/src/censors.dart'; -import 'package:dartvcr/src/defaults.dart'; import 'package:dartvcr/src/request_elements/http_element.dart'; import 'package:dartvcr/src/request_elements/request.dart'; import 'package:dartvcr/src/request_elements/response.dart'; @@ -9,6 +8,8 @@ import 'package:dartvcr/src/request_elements/status.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:http/http.dart' as http; +import '../internal_utilities/content_type.dart'; + part 'http_interaction.g.dart'; @JsonSerializable(explicitToJson: true) @@ -44,14 +45,39 @@ class HttpInteraction extends HttpElement { return streamedResponse; } - factory HttpInteraction.fromHttpResponse(http.Response response, Censors censors) { + factory HttpInteraction.fromHttpResponse( + http.Response response, Censors censors) { final requestBody = ((response.request!) as http.Request).body; + ContentType? requestBodyContentType = + determineContentType(requestBody) ?? ContentType.text; + final censoredRequestBody = + censors.applyBodyParameterCensors(requestBody, requestBodyContentType); + final responseBody = response.body; - final headers = censors.applyHeaderCensors(response.headers); + ContentType? responseBodyContentType = + determineContentType(responseBody) ?? ContentType.text; + final censoredResponseBody = censors.applyBodyParameterCensors( + responseBody, responseBodyContentType); + + final requestHeaders = response.request!.headers; + final censoredRequestHeaders = censors.applyHeaderCensors(requestHeaders); + + final responseHeaders = response.headers; + final censoredResponseHeaders = censors.applyHeaderCensors(responseHeaders); + + final requestUrl = response.request!.url; + final censorRequestUrl = censors.applyQueryCensors(requestUrl.toString()); + + final requestMethod = response.request!.method; + final status = Status(response.statusCode, response.reasonPhrase); - final request = - Request(requestBody, headers, response.request!.method, response.request!.url); + + final censoredRequest = Request(censoredRequestBody, censoredRequestHeaders, + requestMethod, Uri.parse(censorRequestUrl)); + final censoredResponse = + Response(censoredResponseBody, censoredResponseHeaders, status); + return HttpInteraction( - 0, DateTime.now(), request, Response(responseBody, headers, status)); + 0, DateTime.now(), censoredRequest, censoredResponse); } } diff --git a/pubspec.yaml b/pubspec.yaml index 734ccdf..5b30b8e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dartvcr description: A Dart library for recording and replaying HTTP requests. Port of EasyVCR. -version: 0.1.1 +version: 0.2.0 repository: https://github.com/nwithan8/dartvcr environment: