Class HttpRequest

java.lang.Object
org.apache.tinkerpop.gremlin.driver.HttpRequest

public class HttpRequest extends Object
Represents the HTTP request that will be sent to the server. It is passed through the RequestInterceptor chain where interceptors can modify headers, body, URI, and method.

The body starts as a RequestMessage and can be serialized to JSON bytes via serializeBody(). After all interceptors run, if the body is still a RequestMessage, the driver will call serializeBody() automatically before sending.

  • Constructor Details

  • Method Details

    • headers

      public Map<String,String> headers()
      Get the headers of the request.
      Returns:
      a map of headers. This can be used to directly update the entries.
    • getBody

      public Object getBody()
      Get the body of the request.
      Returns:
      an Object representing the body (RequestMessage or byte[]).
    • getUri

      public URI getUri()
      Get the URI of the request.
      Returns:
      the request URI.
    • getMethod

      public String getMethod()
      Get the HTTP method of the request. The standard /gremlin endpoint only supports POST.
      Returns:
      the HTTP method.
    • setBody

      public HttpRequest setBody(Object body)
      Set the HTTP body of the request.
      Returns:
      this HttpRequest for method chaining.
    • setMethod

      public HttpRequest setMethod(String method)
      Set the HTTP method of the request.
      Returns:
      this HttpRequest for method chaining.
    • setUri

      public HttpRequest setUri(URI uri)
      Set the URI of the request.
      Returns:
      this HttpRequest for method chaining.
    • serializeBody

      public byte[] serializeBody()
      Serialize the body to JSON bytes if it is still a RequestMessage. If the body is already byte[], this method is idempotent and returns the existing bytes. This method also sets the Content-Type header to application/json and the Content-Length header to the byte length of the serialized body.

      Interceptors that need the serialized payload (e.g., for computing a signature hash) should call this method rather than serializing independently.

      Returns:
      the serialized body bytes
      Throws:
      IllegalStateException - if the body is neither a RequestMessage nor byte[]