Interface HttpInput.Interceptor

All Known Implementing Classes:
GzipHttpInputInterceptor
Enclosing class:
HttpInput

public static interface HttpInput.Interceptor

HttpInput.Content interceptor that can be registered using HttpInput.setInterceptor(Interceptor) or HttpInput.addInterceptor(Interceptor). When HttpInput.Content instances are generated, they are passed to the registered interceptor (if any) that is then responsible for providing the actual content that is consumed by HttpInput.read(byte[], int, int) and its sibling methods.

A minimal implementation could be as simple as:
 public HttpInput.Content readFrom(HttpInput.Content content)
 {
     LOGGER.debug("read content: {}", asString(content));
     return content;
 }
 
which would not do anything with the content besides logging it. A more involved implementation could look like the following:
 public HttpInput.Content readFrom(HttpInput.Content content)
 {
     if (content.hasContent())
         this.processedContent = processContent(content.getByteBuffer());
     if (content.isEof())
         disposeResources();
     return content.isSpecial() ? content : this.processedContent;
 }
 
Implementors of this interface must keep the following in mind:
See Also:
  • Method Details

    • readFrom

      Parameters:
      content - The content to be intercepted. The content will be modified with any data the interceptor consumes. There is no requirement that all the data is consumed by the interceptor but at least one byte must be consumed unless the returned content is the passed content instance.
      Returns:
      The intercepted content or null if interception is completed for that content.