Class RequestContent

java.lang.Object
org.apache.hc.core5.http.protocol.RequestContent
All Implemented Interfaces:
HttpRequestInterceptor

@Contract(threading=IMMUTABLE) public class RequestContent extends Object implements HttpRequestInterceptor
This request interceptor is responsible for delimiting the message content by adding Content-Length or Transfer-Content headers based on the properties of the enclosed entity and the protocol version.

This interceptor is essential for the HTTP protocol conformance and the correct operation of the client-side message processing pipeline.

Since:
4.0
  • Field Details

  • Constructor Details

    • RequestContent

      public RequestContent()
      Default constructor. The Content-Length or Transfer-Encoding will cause the interceptor to throw ProtocolException if already present in the response message.
    • RequestContent

      public RequestContent(boolean overwrite)
      Constructor that can be used to fine-tune behavior of this interceptor.
      Parameters:
      overwrite - If set to true the Content-Length and Transfer-Encoding headers will be created or updated if already present. If set to false the Content-Length and Transfer-Encoding headers will cause the interceptor to throw ProtocolException if already present in the response message.
      Since:
      4.2
  • Method Details

    • process

      public void process(HttpRequest request, EntityDetails entity, HttpContext context) throws HttpException, IOException
      Description copied from interface: HttpRequestInterceptor
      Processes a request. On the client side, this step is performed before the request is sent to the server. On the server side, this step is performed on incoming messages before the message body is evaluated.
      Specified by:
      process in interface HttpRequestInterceptor
      Parameters:
      request - the request to process
      entity - the request entity details or null if not available
      context - the context for the request
      Throws:
      HttpException - in case of an HTTP protocol violation
      IOException - in case of an I/O error
    • validateOptionsContentType

      public void validateOptionsContentType(HttpRequest request) throws ProtocolException
      Validates the presence of the Content-Type header for an OPTIONS request.

      According to the RFC specifications, an HTTP Method.OPTIONS request that contains content must have a Content-Type header. This method checks for the presence of the Content-Type header in such requests. It does not validate the actual value of the Content-Type header, as determining its validity would require knowledge of all valid media types, which is beyond the scope of this method. If the header is absent, a ProtocolException is thrown.

      Note: This method does not check the validity of the Content-Type header value, only its presence.

      Parameters:
      request - The HttpRequest to be validated for the presence of the Content-Type header. Must not be null.
      Throws:
      ProtocolException - If the Content-Type header is missing in an OPTIONS request with content.