zalando/logbook

The whole response is not written to the console

mimly-wkit opened this issue · 3 comments

Description

curl -vvv -X POST localhost:8989/api/login -H "content-type: application/json" -d '{"username":"a","password":"b"}'

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8989...
* Connected to localhost (127.0.0.1) port 8989 (#0)
> POST /api/login HTTP/1.1
> Host: localhost:8989
> User-Agent: curl/8.0.1
> Accept: */*
> content-type: application/json
> Content-Length: 31
> 
< HTTP/1.1 404 
< Vary: Origin
< Vary: Access-Control-Request-Method
< Vary: Access-Control-Request-Headers
< Content-Type: application/json
< Transfer-Encoding: chunked
< Date: Tue, 09 May 2023 16:17:37 GMT
< 
* Connection #0 to host localhost left intact
{"timestamp":"2023-05-09T16:17:37.162+00:00","status":404,"error":"Not Found","path":"/api/login"}

produces the following log output in the console:

2023-05-09T18:17:37.161+02:00 TRACE 18434 --- [nio-8989-exec-4] org.zalando.logbook.Logbook              : Outgoing Response: f3f81601ffef19ed
Duration: 6 ms
HTTP/1.1 404 Not Found
Vary: Origin, Access-Control-Request-Method, Access-Control-Request-Headers

It seems that multiple Vary headers might have caused the problem.

Expected Behavior

The whole response (incl. body) should be printed out.

Your Environment

build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.6'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.zalando:logbook-spring-boot-starter:3.0.0-RC.2'

    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}

application.yml:

logging:
  level:
    org.zalando.logbook: TRACE
server:
  port: 8989
spring:
  output:
    ansi:
      enabled: ALWAYS
logbook:
  format:
    style: http
  • Version used: 3.0.0-RC.2

In order to prioritize the support for Logbook, we would like to check whether the old issues are still relevant.
This issue has not been updated for over six months.

  • Please check if it is still relevant in latest version of the Logbook.
  • If so, please add a descriptive comment to keep the issue open.
  • Otherwise, the issue will automatically be closed after a week.

Looks like the issue is that Spring adds the Content-Type, Transfer-Encoding and Date headers as well as the default response body after the internal filters have finished processing the request for cases when the handler was not found.

One way to overcome this for logbook is to instruct Spring to throw the NoHandlerFoundException instead of falling back to error page as per docs. You may also need to enable problem details and disable default resource mappings.

spring.mvc.problemdetails.enabled=true
spring.web.resources.add-mappings=false
spring.mvc.throw-exception-if-no-handler-found=true

This issue has automatically been closed due to no activities. If the issue still exists in the latest version of the Logbook, please feel free to re-open it.