californium icon indicating copy to clipboard operation
californium copied to clipboard

Always a 5.02 response in ProxyHttpClientResource if http response contains no content-type header

Open basimons opened this issue 2 months ago • 12 comments

Hello,

After updating from californium 2.7.0 -> 3.12, I ran into a small issue.

I have a resource like this:

@Slf4j
public class HttpClientResourceForwarder extends ProxyHttpClientResource {

    public HttpClientResourceForwarder (HttpProxyProperties props, MeterRegistry meterRegistry) {
        super(props.getCoapProxyVersionPath(), props.getCoapProxyVisible(), true,
            new Coap2ForwarderHttpTranslator(props, meterRegistry), props.getHttpScheme());
    }

    @Override
    public Resource getChild(String name) {
        // This ensures that all paths after the version path (/v0/**) end up at this Resource
        return this;
    }

    @Override
    public void handleRequest(final Exchange exchange) {
        log.debug("Received COAP proxy request: {}", exchange.getRequest());
        super.handleRequest(exchange);
    }
}

This worked fine in 2.7.0, but after upgrading I sometimes encounter an issue. This is caused when the server that the ProxyHttpClientResource does a request to, returns a response WITHOUT a content-type header, the response will always be a 5.02, with the message being "content type must not be null", which is set on org.eclipse.californium.proxy2.http.ContentTypedEntity#49.

IMO this is a bug, because getting a response without a Content-Type header is fine as long as the Content-Length is also 0.

Kind regards,

Bram

basimons avatar Jun 20 '24 14:06 basimons