@Override
    public HttpResponse convertResponse(ServiceRequestContext ctx,
                                        ResponseHeaders headers,
                                        @Nullable Object result,
                                        HttpHeaders trailers) throws Exception {
        final MediaType contentType = headers.contentType();
        if (contentType != null) {
            // @Produces("application/binary") or @ProducesBinary
            // @Produces("application/octet-stream") or @ProducesOctetStream
            if (contentType.is(MediaType.APPLICATION_BINARY) ||
                contentType.is(MediaType.OCTET_STREAM)) {
                // We assume that the publisher and stream produces HttpData or byte[].
                // An IllegalStateException will be raised for other types due to conversion failure.
                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();
    }
A {@link ResponseConverterFunction} which creates an {@link HttpResponse} when:
<ul>
  <li>the {@code result} is an instance of {@link HttpData} or {@code byte[]}</li>
  <li>the {@code result} is an instance of {@link Publisher} or {@link Stream} while the
      {@code "content-type"} of the {@link ResponseHeaders} is {@code "application/binary"} or
      {@code "application/octet-stream"}</li>
</ul>
Note that this {@link ResponseConverterFunction} is applied to an annotated service by default,
so you don't have to specify this converter explicitly.
core/src/main/java/com/linecorp/armeria/server/annotation/ByteArrayResponseConverterFunction.java