Skip to content

Mock server unable to handle HEAD HTTP method #1828

@RanABI

Description

@RanABI

Hi team,
I am using your Mock-Servers,
When mocking an HTTP HEAD request, I receive the following error:

sun.net.httpserver.ExchangeImpl sendResponseHeaders

WARNING: sendResponseHeaders: being invoked with a content length for a HEAD request

2024-09-17 10:52:09,159 APP ERROR - [34][HTTP-Dispatcher] [] Failed to generate response

java.io.IOException: response headers not sent yet

at sun.net.httpserver.PlaceholderOutputStream.checkWrap(ExchangeImpl.java:448) ~[jdk.httpserver:?]

I see the error's origin is at MockHttpServer.kt , in the pactResponseToHttpExchange function, I guess the exchange is closing before response headers are being sent.

My mock is very simple -

builder.expectsToReceiveHttpInteraction("Auth check",
        interaction -> interaction
            .withRequest(request -> request
                .path("/v1/my/path")
                .method("HEAD")
            .willRespondWith(response ->
                response.status(200)
    );

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions