@Override
    protected void encode(final ChannelHandlerContext channelHandlerContext, final RequestMessage requestMessage, final List<Object> objects) throws Exception {
        final String mimeType = serializer.mimeTypesSupported()[0];
        if (requestMessage.getField("gremlin") instanceof GremlinLang) {
            throw new ResponseException(HttpResponseStatus.BAD_REQUEST, String.format(
                    "An error occurred during serialization of this request [%s] - it could not be sent to the server - Reason: GremlinLang is not intended to be send as query.",
                    requestMessage));
        }

        final InetSocketAddress remoteAddress = getRemoteAddress(channelHandlerContext.channel());
        try {
            Map<String, String> headersMap = new HashMap<>();
            headersMap.put(HttpRequest.Headers.HOST, remoteAddress.getAddress().getHostAddress());
            headersMap.put(HttpRequest.Headers.ACCEPT, mimeType);
            headersMap.put(HttpRequest.Headers.ACCEPT_ENCODING, HttpRequest.Headers.DEFLATE);
            if (userAgentEnabled) {
                headersMap.put(HttpRequest.Headers.USER_AGENT, UserAgent.USER_AGENT);
            }
            if (bulkResults) {
                headersMap.put(Tokens.BULK_RESULTS, "true");
            }
            HttpRequest gremlinRequest = new HttpRequest(headersMap, requestMessage, uri);

            for (final Pair<String, ? extends RequestInterceptor> interceptor : interceptors) {
                gremlinRequest = interceptor.getRight().apply(gremlinRequest);
            }

            final FullHttpRequest finalRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
                    uri.getPath(), convertBody(gremlinRequest));
            gremlinRequest.headers().forEach((k, v) -> finalRequest.headers().add(k, v));

            objects.add(finalRequest);
            channelHandlerContext.channel().attr(REQUEST_SENT).set(true);
        } catch (AuthenticationException ex) {
            throw new ResponseException(HttpResponseStatus.BAD_REQUEST, String.format(
                    "An error occurred during authentication [%s] - it could not be sent to the server - Reason: %s",
                    requestMessage, ex));
        }
    }
Converts {@link RequestMessage} to a {@code HttpRequest}.
gremlin-driver/src/main/java/org/apache/tinkerpop/gremlin/driver/handler/HttpGremlinRequestEncoder.java