Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The request body is being printed out only if the content type is set to application/x-www-form-urlencoded. Not otherwise. #339

Open
ghost opened this issue May 7, 2023 · 0 comments
Labels
type:bug A bug report or bug fix.

Comments

@ghost
Copy link

ghost commented May 7, 2023

Describe the bug

The request body is being printed out only if the content type is set to application/x-www-form-urlencoded. Otherwise, it will not be printed. Am I missing to include some extra dependencies or maybe some required configuration is missing?

To Reproduce

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 'dev.akkinoc.spring.boot:logback-access-spring-boot-starter:4.0.0'

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

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

application.yml:

logging:
  level:
    web: "TRACE"
server:
  port: 8989
spring:
  mvc:
    log-request-details: true

logback-access.xml:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%fullRequest%n%n%fullResponse</pattern>
    </encoder>
  </appender>

  <appender-ref ref="STDOUT" />
</configuration>

For example, curl -X POST localhost:8989/api/login -H "content-type: application/x-www-form-urlencoded" -d 'username=a&password=b' works as expected, while curl -X POST localhost:8989/api/login -H "content-type: application/json" -d '{"username":"a","password":"b"}' does NOT work at all - the request body is missing.

Expected behavior

It would be nice if it worked well even for some other content types, primarily for application/json.

POST /api/login HTTP/1.1
accept: */*
content-length: 21
content-type: application/json
host: localhost:8989
user-agent: curl/8.0.1

{"username":"a","password":"b"}

or even better, formatted as:

POST /api/login HTTP/1.1
accept: */*
content-length: 21
content-type: application/json
host: localhost:8989
user-agent: curl/8.0.1

{
  "username": "a",
  "password": "b"
}

Environment

  • Version of this library used: 4.0.0
  • Version of Java used: 17.0.7 | 20.0.1
  • Version of Spring Boot used: 3.0.6
  • Web server used (Tomcat, Jetty, Undertow or Netty): Tomcat
  • Web application type used (Servlet Stack or Reactive Stack): Servlet Stack
@ghost ghost added the type:bug A bug report or bug fix. label May 7, 2023
@ghost ghost changed the title The request body is being printed out only if the content type is set to application/x-www-form-urlencoded. The request body is being printed out only if the content type is set to application/x-www-form-urlencoded. Not otherwise. May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug A bug report or bug fix.
Projects
None yet
Development

No branches or pull requests

0 participants