@Override
    public HttpResponse convertResponse(ServiceRequestContext ctx,
                                        ResponseHeaders headers,
                                        @Nullable Object result,
                                        HttpHeaders trailers) throws Exception {
        final MediaType mediaType = headers.contentType();
        if (mediaType != null) {
            // @Produces("text/plain") or @ProducesText is specified.
            if (mediaType.is(MediaType.ANY_TEXT_TYPE)) {
                // Use 'utf-8' charset by default.
                final Charset charset = mediaType.charset(ArmeriaHttpUtil.HTTP_DEFAULT_CONTENT_CHARSET);

                // To avoid sending an unfinished text to the client, always aggregate the published strings.
                if (result instanceof Publisher) {
                    return aggregateFrom((Publisher<?>) result, headers, trailers,
                                         o -> toHttpData(o, charset), ctx);
                }
                if (result instanceof Stream) {
                    return aggregateFrom((Stream<?>) result, headers, trailers,
                                         o -> toHttpData(o, charset), ctx.blockingTaskExecutor());
                }
                return HttpResponse.of(headers, toHttpData(result, charset), trailers);
            }
        } else if (result instanceof CharSequence) {
            return HttpResponse.of(headers.toBuilder().contentType(MediaType.PLAIN_TEXT_UTF_8).build(),
                                   HttpData.ofUtf8(((CharSequence) result).toString()),
                                   trailers);
        }

        return ResponseConverterFunction.fallthrough();
    }
A {@link ResponseConverterFunction} which creates an {@link HttpResponse} when:
<ul>
  <li>the {@code result} is an instance of {@link CharSequence}</li>
  <li>the {@code "content-type"} of the {@link ResponseHeaders} is {@link MediaType#ANY_TEXT_TYPE}</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/StringResponseConverterFunction.java