ByteArrayResponseConverterFunction implements ResponseConverterFunction { @Override public HttpResponse convertResponse(ServiceRequestContext ctx, ResponseHeaders headers, @Nullable Object result, HttpHeaders trailers) throws Exception { final MediaType contentType = headers.contentType(); if (contentType != null) { if (contentType.is(MediaType.APPLICATION_BINARY) || contentType.is(MediaType.OCTET_STREAM)) { if (result instanceof Publisher) { return streamingFrom((Publisher<?>) result, headers, trailers, ByteArrayResponseConverterFunction::toHttpData); } if (result instanceof Stream) { return streamingFrom((Stream<?>) result, headers, trailers, ByteArrayResponseConverterFunction::toHttpData, ctx.blockingTaskExecutor()); } } if (result instanceof HttpData) { return HttpResponse.of(headers, (HttpData) result, trailers); } if (result instanceof byte[]) { return HttpResponse.of(headers, HttpData.wrap((byte[]) result), trailers); } return ResponseConverterFunction.fallthrough(); } if (result instanceof HttpData) { return HttpResponse.of(headers.toBuilder().contentType(MediaType.OCTET_STREAM).build(), (HttpData) result, trailers); } if (result instanceof byte[]) { return HttpResponse.of(headers.toBuilder().contentType(MediaType.OCTET_STREAM).build(), HttpData.wrap((byte[]) result), trailers); } return ResponseConverterFunction.fallthrough(); }  @Override HttpResponse convertResponse(ServiceRequestContext ctx,
                                        ResponseHeaders headers,
                                        @Nullable Object result,
                                        HttpHeaders trailers);  }
@Test void withoutContentType() throws Exception { StepVerifier.create(function.convertResponse(ctx, ResponseHeaders.of(HttpStatus.OK), HttpData.ofUtf8("foo"), DEFAULT_TRAILERS)) .expectNext(OCTET_STREAM_HEADERS.toBuilder() .addInt(HttpHeaderNames.CONTENT_LENGTH, 3) .build()) .expectNext(HttpData.ofUtf8("foo")) .expectComplete() .verify(); StepVerifier.create(function.convertResponse(ctx, ResponseHeaders.of(HttpStatus.OK), "foo".getBytes(), DEFAULT_TRAILERS)) .expectNext(OCTET_STREAM_HEADERS.toBuilder() .addInt(HttpHeaderNames.CONTENT_LENGTH, 3) .build()) .expectNext(HttpData.wrap("foo".getBytes())) .expectComplete() .verify(); assertThatThrownBy(() -> from("Unsupported type.")).isInstanceOf(FallthroughException.class); }