Skip to content

Commit

Permalink
- Fix censoring bug, prep for 0.2.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nwithan8 committed Dec 30, 2022
1 parent c94ca19 commit d9fcb99
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
38 changes: 32 additions & 6 deletions lib/src/request_elements/http_interaction.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
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';
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)
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit d9fcb99

Please sign in to comment.