Interface HttpDeframer<T>

All Superinterfaces:
org.reactivestreams.Processor<HttpObject,​T>, org.reactivestreams.Publisher<T>, StreamMessage<T>, org.reactivestreams.Subscriber<HttpObject>

@UnstableApi
public interface HttpDeframer<T>
extends org.reactivestreams.Processor<HttpObject,​T>, StreamMessage<T>
A Processor implementation that decodes a stream of HttpObjects to N objects.

Follow the below steps to deframe HTTP payload using HttpDeframer.

  1. Implement your deframing logic in HttpDeframerHandler.
    
           > class FixedLengthDecoder implements HttpDeframerHandler<String> {
           >     private final int length;
           >
           >     FixedLengthDecoder(int length) {
           >         this.length = length;
           >     }
           >
           >     @Override
           >     public void process(HttpDeframerInput in, HttpDeframerOutput<String> out) {
           >         int remaining = in.readableBytes();
           >         if (remaining < length) {
           >             // The input is not enough to process. Waiting for more data.
           >             return;
           >         }
           >
           >         do {
           >             // Read data from 'HttpDeframerInput' and
           >             // write the processed result to 'HttpDeframerOutput'.
           >             ByteBuf buf = in.readBytes(length);
           >             out.add(buf.toString(StandardCharsets.UTF_8));
           >             // Should release the returned 'ByteBuf'
           >             buf.release();
           >             remaining -= length;
           >         } while (remaining >= length);
           >     }
           > }
           
  2. Create an HttpDeframer with the HttpDeframerHandler instance.
    
           FixedLengthDecoder decoder = new FixedLengthDecoder(11);
           HttpDeframer<String> deframer = HttpDeframer.of(decoder, ByteBufAllocator.DEFAULT);
           
  3. Subscribe to an HttpRequest using the HttpDeframer.
    
           HttpRequest request = ...;
           request.subscribe(deframer);
           
  4. Subscribe to the Publisher of the deframed data and connect to your business logic.
    
           import reactor.core.publisher.Flux;
           Flux.from(deframer).map(...); // Consume and manipulate the deframed data.