Package org.takes.rq

Class RqLengthAware

  • All Implemented Interfaces:
    Body, Head, Request

    public final class RqLengthAware
    extends RqWrap
    Request decorator that limits its body, according to the Content-Length header in its head.

    This decorator may help when you're planning to read the body of the request using its read() and available() methods, but you're not sure that available() is always saying the truth. In most cases, the browser will not close the request and will always return positive number in available() method. Thus, you won't be able to reach the end of the stream ever. The browser wants you to respect the "Content-Length" header and read as many bytes as it requests. To solve that, just wrap your request into this decorator.

    The class is immutable and thread-safe.

    Since:
    0.15
    See Also:
    RqMultipart, RqPrint
    • Constructor Detail

      • RqLengthAware

        public RqLengthAware​(Request req)
        Ctor.
        Parameters:
        req - Original request