@Test
public void invalid_http_call_that_causes_Netty_DecoderFailure_should_result_in_expected_400_error() throws Exception {
NettyHttpClientRequestBuilder request = request()
.withMethod(HttpMethod.GET)
.withUri(BasicEndpoint.MATCHING_PATH)
.withPipelineAdjuster(
p -> p.addFirst(new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
String msgAsString = ((ByteBuf)msg).toString(CharsetUtil.UTF_8);
if (msgAsString.contains("HTTP/1.1")) {
msg = Unpooled.copiedBuffer(msgAsString.replace("HTTP/1.1", ""), CharsetUtil.UTF_8);
}
super.write(ctx, msg, promise);
}
})
);
NettyHttpClientResponse response = request.execute(downstreamServerConfig.endpointsPort(), 3000);
verifyErrorReceived(response.payload,
response.statusCode,
new ApiErrorWithMetadata(SampleCoreApiError.MALFORMED_REQUEST,
Pair.of("cause", "Invalid HTTP request"))
);
}