org.apache.hc.core5.http.impl

## Class DefaultContentLengthStrategy

- java.lang.Object
- - org.apache.hc.core5.http.impl.DefaultContentLengthStrategy

- All Implemented Interfaces:
    ContentLengthStrategy

      @Contract(threading=IMMUTABLE)
      public class DefaultContentLengthStrategy
      extends Object
      implements ContentLengthStrategy

  The default implementation of the content length strategy. This class will throw `ProtocolException` if it encounters an unsupported transfer encoding, multiple `Content-Length` header values or a malformed `Content-Length` header value.

  This class recognizes "chunked" transfer-coding only.

  Since:
    5.0

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DefaultContentLengthStrategy` | `INSTANCE`

    - ### Fields inherited from interface org.apache.hc.core5.http.ContentLengthStrategy

      `CHUNKED, UNDEFINED`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultContentLengthStrategy()` Creates `DefaultContentLengthStrategy` instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `long` | `determineLength(HttpMessage message)` Returns length of the given message in bytes.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### INSTANCE

          public static final DefaultContentLengthStrategy INSTANCE

  - ### Constructor Detail

    - #### DefaultContentLengthStrategy

          public DefaultContentLengthStrategy()

      Creates `DefaultContentLengthStrategy` instance. `ContentLengthStrategy.UNDEFINED` is used per default when content length is not explicitly specified in the message.

  - ### Method Detail

    - #### determineLength

          public long determineLength(HttpMessage message)
                               throws HttpException

      Description copied from interface: `ContentLengthStrategy`
      Returns length of the given message in bytes. The returned value must be a non-negative number, `ContentLengthStrategy.CHUNKED` if the message is chunk coded, or `ContentLengthStrategy.UNDEFINED` if the message is not explicitly delineated.
      Specified by:
        `determineLength` in interface `ContentLengthStrategy`
      Parameters:
        `message` - HTTP message
      Returns:
        content length, `ContentLengthStrategy.UNDEFINED`, or `ContentLengthStrategy.CHUNKED`
      Throws:
        `HttpException` - in case of HTTP protocol violation

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.