Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.TreeSet;

import static io.qameta.allure.attachment.http.HttpRequestAttachment.Builder.create;
import static io.qameta.allure.attachment.http.HttpResponseAttachment.Builder.create;
import static java.util.Optional.ofNullable;

/**
Expand All @@ -45,11 +44,18 @@ public class AllureRestAssured implements OrderedFilter {

private static final String HIDDEN_PLACEHOLDER = "[ BLACKLISTED ]";

private int maxAllowedPrettifyLength = 1048576;

private String requestTemplatePath = "http-request.ftl";
private String responseTemplatePath = "http-response.ftl";
private String requestAttachmentName = "Request";
private String responseAttachmentName;

public AllureRestAssured setMaxAllowedPrettifyLength(final int maxAllowedPrettifyLength) {
this.maxAllowedPrettifyLength = maxAllowedPrettifyLength;
return this;
}

public AllureRestAssured setRequestTemplate(final String templatePath) {
this.requestTemplatePath = templatePath;
return this;
Expand Down Expand Up @@ -123,10 +129,13 @@ public Response filter(final FilterableRequestSpecification requestSpec,
final String attachmentName = ofNullable(responseAttachmentName)
.orElse(response.getStatusLine());

final HttpResponseAttachment responseAttachment = create(attachmentName)
final String responseAsString = response.getBody().asString();
final String body = responseAsString.length() > maxAllowedPrettifyLength ? responseAsString : prettifier.getPrettifiedBodyIfPossible(response, response.getBody());

final HttpResponseAttachment responseAttachment = HttpResponseAttachment.Builder.create(attachmentName)
.setResponseCode(response.getStatusCode())
.setHeaders(toMapConverter(response.getHeaders(), hiddenHeaders))
.setBody(prettifier.getPrettifiedBodyIfPossible(response, response.getBody()))
.setBody(body)
.build();

new DefaultAttachmentProcessor().addAttachment(
Expand Down
Loading