3535import java .util .TreeSet ;
3636
3737import static io .qameta .allure .attachment .http .HttpRequestAttachment .Builder .create ;
38- import static io .qameta .allure .attachment .http .HttpResponseAttachment .Builder .create ;
3938import static java .util .Optional .ofNullable ;
4039
4140/**
@@ -45,11 +44,18 @@ public class AllureRestAssured implements OrderedFilter {
4544
4645 private static final String HIDDEN_PLACEHOLDER = "[ BLACKLISTED ]" ;
4746
47+ private int maxAllowedPrettifyLength = 1048576 ;
48+
4849 private String requestTemplatePath = "http-request.ftl" ;
4950 private String responseTemplatePath = "http-response.ftl" ;
5051 private String requestAttachmentName = "Request" ;
5152 private String responseAttachmentName ;
5253
54+ public AllureRestAssured setMaxAllowedPrettifyLength (final int maxAllowedPrettifyLength ) {
55+ this .maxAllowedPrettifyLength = maxAllowedPrettifyLength ;
56+ return this ;
57+ }
58+
5359 public AllureRestAssured setRequestTemplate (final String templatePath ) {
5460 this .requestTemplatePath = templatePath ;
5561 return this ;
@@ -123,10 +129,13 @@ public Response filter(final FilterableRequestSpecification requestSpec,
123129 final String attachmentName = ofNullable (responseAttachmentName )
124130 .orElse (response .getStatusLine ());
125131
126- final HttpResponseAttachment responseAttachment = create (attachmentName )
132+ final String responseAsString = response .getBody ().asString ();
133+ final String body = responseAsString .length () > maxAllowedPrettifyLength ? responseAsString : prettifier .getPrettifiedBodyIfPossible (response , response .getBody ());
134+
135+ final HttpResponseAttachment responseAttachment = HttpResponseAttachment .Builder .create (attachmentName )
127136 .setResponseCode (response .getStatusCode ())
128137 .setHeaders (toMapConverter (response .getHeaders (), hiddenHeaders ))
129- .setBody (prettifier . getPrettifiedBodyIfPossible ( response , response . getBody ()) )
138+ .setBody (body )
130139 .build ();
131140
132141 new DefaultAttachmentProcessor ().addAttachment (
@@ -148,4 +157,4 @@ private static Map<String, String> toMapConverter(final Iterable<? extends NameA
148157 public int getOrder () {
149158 return Integer .MAX_VALUE ;
150159 }
151- }
160+ }
0 commit comments