logbook icon indicating copy to clipboard operation
logbook copied to clipboard

Strategy 'BodyOnlyIfStatusAtLeastStrategy' does not log response attributes

Open MrShruikhan opened this issue 6 months ago • 1 comments

Description

As mentioned in #2024 there was a bug if you use the BodyOnlyIfStatusAtLeastStrategy and AttributeExtractors. This is also true to response attributes if the response status is less than the minimum status.

Expected Behavior

withoutBody() should only remove the body from the response.

Actual Behavior

Attributes are not logged for response.

Possible Fix

Give the treatment that was given to FilteredHttpRequest also to FilteredHttpResponse

Steps to Reproduce

  1. log with strategy BodyOnlyIfStatusAtLeastStrategy and status=400
  2. create ResponseExtractor:
@Component
public class CustomResponseExtractor implements AttributeExtractor

@Override
public HttpAttributes extract(HttpRequest request, HttpResponse response) {
  return new HttpAttributes(Map.of("customAttribute", "someValue"));
}
  1. use CustomResponseExtractor in application.yml
logbook:
  strategy: body-only-if-status-at-least
  minimum-status: 400
  attribute-extractors:
    - type: CustomResponseExtractor

MrShruikhan avatar Jun 17 '25 10:06 MrShruikhan

Hi @MrShruikhan ,

i will check that.

ChristianLohmann avatar Jun 20 '25 14:06 ChristianLohmann