Skip to content

[Bug]: HttpWaitStrategy removes line breaks in http response body before responsePredicate invocation #7326

Open

Description

@antonovdmitriy

Module

Core

Testcontainers version

1.18.3

Using the latest Testcontainers version?

Yes

Host OS

Linux

Host Arch

x86

Docker version

Client:
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.1
 Git commit:        20.10.21-0ubuntu1~22.04.3
 Built:             Thu Apr 27 05:57:17 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.1
  Git commit:       20.10.21-0ubuntu1~22.04.3
  Built:            Thu Apr 27 05:37:25 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.12-0ubuntu1~22.04.3
  GitCommit:        
 runc:
  Version:          1.1.4-0ubuntu1~22.04.3
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:

What happened?

for some reason, the HttpWaitStrategy reads the response line by line, but does not save the line break characters. In some cases it is really bad, for example, parsing the prometheus metric of springboot application becomes a nightmare.

from org.testcontainers.containers.wait.strategy.HttpWaitStrategy

   private String getResponseBody(HttpURLConnection connection) throws IOException {
        BufferedReader reader;
        if (200 <= connection.getResponseCode() && connection.getResponseCode() <= 299) {
            reader = new BufferedReader(new InputStreamReader((connection.getInputStream())));
        } else {
            reader = new BufferedReader(new InputStreamReader((connection.getErrorStream())));
        }

        StringBuilder builder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line);  // THIS ROW!!!!!!!
        }
        return builder.toString();
    }

Relevant log output

No response

Additional Information

No response

Activity

  1. changed the title [-][Bug]: HttpWaitStrategry removes new lines in http response before responsePredicate invocation[/-] [+][Bug]: HttpWaitStrategy removes new lines in http response before responsePredicate invocation[/+] on Jul 24, 2023
  2. changed the title [-][Bug]: HttpWaitStrategy removes new lines in http response before responsePredicate invocation[/-] [+][Bug]: HttpWaitStrategy removes line breaks in http response before responsePredicate invocation[/+] on Jul 24, 2023
  3. changed the title [-][Bug]: HttpWaitStrategy removes line breaks in http response before responsePredicate invocation[/-] [+][Bug]: HttpWaitStrategy removes line breaks in http response body before responsePredicate invocation[/+] on Jul 24, 2023
  4. antonovdmitriy commented on Jul 24, 2023

    @antonovdmitriy
    Author

    @eddumelendez thanks but there is no HttpWaitStrategy with Predicate in your example. Only Wait.forLogMessage is using.

  5. ivankrn commented on Jul 19, 2026

    @ivankrn

    Hello team, I've opened a PR #11937 to resolve this bug. It replaces the manual stream reading loop with IOUtils.toString() to preserve line breaks and response formatting.
    Any feedback on the PR would be greatly appreciated. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    resolution/waiting-for-infoWaiting for more information of the issue author or another 3rd party.type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions