code: private HttpResponse convertResponse(ServiceRequestContext ctx, HttpRequest req,
                                           @Nullable HttpHeaders headers, @Nullable Object result,
                                           HttpHeaders trailingHeaders) {
          final HttpHeaders newHeaders;
          final HttpHeaders newTrailingHeaders;
          if (result instanceof HttpResult) {
              final HttpResult<?> httpResult = (HttpResult<?>) result;
              newHeaders = setHttpStatus(addNegotiatedResponseMediaType(ctx, httpResult.headers()));
              result = httpResult.content().orElse(null);
              newTrailingHeaders = httpResult.trailingHeaders();
          } else {
              newHeaders = setHttpStatus(
                      headers == null ? addNegotiatedResponseMediaType(ctx, HttpHeaders.EMPTY_HEADERS)
                                      : headers);
              newTrailingHeaders = trailingHeaders;
          }
  
          if (result instanceof HttpResponse) {
              return new ExceptionFilteredHttpResponse(ctx, req, (HttpResponse) result, exceptionHandler);
          }
          if (result instanceof AggregatedHttpMessage) {
              return HttpResponse.of((AggregatedHttpMessage) result);
          }
          if (result instanceof CompletionStage) {
              return HttpResponse.from(
                      ((CompletionStage<?>) result)
                              .thenApply(object -> convertResponse(ctx, req, newHeaders, object,
                                                                   newTrailingHeaders))
                              .exceptionally(cause -> exceptionHandler.handleException(ctx, req, cause)));
          }
  
          try {
              final HttpResponse response =
                      responseConverter.convertResponse(ctx, newHeaders, result, newTrailingHeaders);
              if (response instanceof HttpResponseWriter) {
                  // A streaming response has more chance to get an exception.
                  return new ExceptionFilteredHttpResponse(ctx, req, response, exceptionHandler);
              } else {
                  return response;
              }
          } catch (Exception cause) {
              return exceptionHandler.handleException(ctx, req, cause);
          }
      }
docs: Converts the specified {@code result} to an {@link HttpResponse}.