Example usage for io.netty.handler.codec.http DefaultLastHttpContent DefaultLastHttpContent

List of usage examples for io.netty.handler.codec.http DefaultLastHttpContent DefaultLastHttpContent

Introduction

In this page you can find the example usage for io.netty.handler.codec.http DefaultLastHttpContent DefaultLastHttpContent.

Prototype

public DefaultLastHttpContent(ByteBuf content, boolean validateHeaders) 

Source Link

Usage

From source file:com.linecorp.armeria.internal.http.Http1ObjectEncoder.java

License:Apache License

private LastHttpContent convertTrailingHeaders(int streamId, HttpHeaders headers) throws Http2Exception {
    final LastHttpContent lastContent;
    if (headers.isEmpty()) {
        lastContent = LastHttpContent.EMPTY_LAST_CONTENT;
    } else {/*from  w w  w .  j  a v a  2s  .  c o m*/
        lastContent = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, false);
        convert(streamId, headers, lastContent.trailingHeaders(), true);
    }
    return lastContent;
}

From source file:io.advantageous.conekt.http.impl.AssembledFullHttpRequest.java

License:Open Source License

private static LastHttpContent toLastContent(ByteBuf buf) {
    if (buf.isReadable()) {
        return new DefaultLastHttpContent(buf, false);
    } else {// ww  w . j  a  va  2  s . c o m
        return LastHttpContent.EMPTY_LAST_CONTENT;
    }
}

From source file:io.advantageous.conekt.http.impl.HttpClientRequestImpl.java

License:Open Source License

private void write(ByteBuf buff, boolean end) {
    int readableBytes = buff.readableBytes();
    if (readableBytes == 0 && !end) {
        // nothing to write to the connection just return
        return;/*ww w  .ja v a2 s  .  c om*/
    }

    if (end) {
        completed = true;
    }
    if (!end && !chunked && !contentLengthSet()) {
        throw new IllegalStateException(
                "You must set the Content-Length header to be the total size of the message "
                        + "body BEFORE sending any data if you are not using HTTP chunked encoding.");
    }

    written += buff.readableBytes();
    if (conn == null) {
        if (pendingChunks == null) {
            pendingChunks = buff;
        } else {
            CompositeByteBuf pending;
            if (pendingChunks instanceof CompositeByteBuf) {
                pending = (CompositeByteBuf) pendingChunks;
            } else {
                pending = Unpooled.compositeBuffer();
                pending.addComponent(pendingChunks).writerIndex(pendingChunks.writerIndex());
                pendingChunks = pending;
            }
            pending.addComponent(buff).writerIndex(pending.writerIndex() + buff.writerIndex());
        }
        connect();
    } else {
        if (!headWritten) {
            writeHeadWithContent(buff, end);
        } else {
            if (end) {
                if (buff.isReadable()) {
                    conn.writeToChannel(new DefaultLastHttpContent(buff, false));
                } else {
                    conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT);
                }
            } else {
                conn.writeToChannel(new DefaultHttpContent(buff));
            }
        }
        if (end) {
            conn.reportBytesWritten(written);

            if (respHandler != null) {
                conn.endRequest();
            }
        }
    }
}

From source file:io.advantageous.conekt.http.impl.HttpServerResponseImpl.java

License:Open Source License

@Override
public MultiMap trailers() {
    if (trailers == null) {
        if (trailing == null) {
            trailing = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, false);
        }/*from   ww  w  .  j a v  a  2 s.com*/
        trailers = new HeadersAdaptor(trailing.trailingHeaders());
    }
    return trailers;
}

From source file:io.advantageous.conekt.http.impl.HttpServerResponseImpl.java

License:Open Source License

private void end0(ByteBuf data) {
    checkWritten();/*from w w w.  j  av  a2  s. co  m*/
    bytesWritten += data.readableBytes();
    if (!headWritten) {
        // if the head was not written yet we can write out everything in one go
        // which is cheaper.
        prepareHeaders();
        FullHttpResponse resp;
        if (trailing != null) {
            resp = new AssembledFullHttpResponse(response, data, trailing.trailingHeaders(),
                    trailing.getDecoderResult());
        } else {
            resp = new AssembledFullHttpResponse(response, data);
        }
        channelFuture = conn.writeToChannel(resp);
    } else {
        if (!data.isReadable()) {
            if (trailing == null) {
                channelFuture = conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT);
            } else {
                channelFuture = conn.writeToChannel(trailing);
            }
        } else {
            LastHttpContent content;
            if (trailing != null) {
                content = new AssembledLastHttpContent(data, trailing.trailingHeaders(),
                        trailing.getDecoderResult());
            } else {
                content = new DefaultLastHttpContent(data, false);
            }
            channelFuture = conn.writeToChannel(content);
        }
    }

    if (!keepAlive) {
        closeConnAfterWrite();
        closed = true;
    }
    written = true;
    conn.responseComplete();
    if (bodyEndHandler != null) {
        bodyEndHandler.handle(null);
    }
}

From source file:io.jsync.http.impl.DefaultHttpClientRequest.java

License:Open Source License

private void writeEndChunk(ByteBuf buf) {
    if (buf.isReadable()) {
        conn.write(new DefaultLastHttpContent(buf, false));
    } else {/*from  w w  w.  j  a  v  a2 s. c o  m*/
        conn.write(LastHttpContent.EMPTY_LAST_CONTENT);
    }
}

From source file:io.jsync.http.impl.DefaultHttpServerResponse.java

License:Open Source License

@Override
public MultiMap trailers() {
    if (trailers == null) {
        if (trailing == null) {
            trailing = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, false);
        }/*  w  w w  .  j  a  v  a 2  s .  c o  m*/
        trailers = new HttpHeadersAdapter(trailing.trailingHeaders());
    }
    return trailers;
}

From source file:io.jsync.http.impl.DefaultHttpServerResponse.java

License:Open Source License

private void end0(ByteBuf data) {
    checkWritten();/*from   w ww  . j  a va2 s.co m*/

    if (!headWritten) {
        // if the head was not written yet we can write out everything in on go
        // which is more cheap.
        prepareHeaders();
        FullHttpResponse resp;
        if (trailing != null) {
            resp = new AssembledFullHttpResponse(response, data, trailing.trailingHeaders(),
                    trailing.decoderResult());
        } else {
            resp = new AssembledFullHttpResponse(response, data);
        }
        channelFuture = conn.write(resp);
        headWritten = true;
    } else {
        if (!data.isReadable()) {
            if (trailing == null) {
                channelFuture = conn.write(LastHttpContent.EMPTY_LAST_CONTENT);
            } else {
                channelFuture = conn.write(trailing);
            }
        } else {
            LastHttpContent content;
            if (trailing != null) {
                content = new AssembledLastHttpContent(data, trailing.trailingHeaders(),
                        trailing.decoderResult());
            } else {
                content = new DefaultLastHttpContent(data, false);
            }
            channelFuture = conn.write(content);
        }
    }

    if (!keepAlive) {
        closeConnAfterWrite();
    }
    written = true;
    conn.responseComplete();
}

From source file:io.vertx.core.http.impl.ClientConnection.java

License:Open Source License

@Override
public void writeBuffer(ByteBuf buff, boolean end) {
    if (end) {// w ww . j  av  a 2s.c om
        if (buff != null && buff.isReadable()) {
            writeToChannel(new DefaultLastHttpContent(buff, false));
        } else {
            writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT);
        }
    } else if (buff != null) {
        writeToChannel(new DefaultHttpContent(buff));
    }
}

From source file:io.vertx.core.http.impl.HttpServerResponseImpl.java

License:Open Source License

private void end0(ByteBuf data) {
    checkWritten();//from w w  w .  j  av a  2s  .  c  o m
    bytesWritten += data.readableBytes();
    if (!headWritten) {
        // if the head was not written yet we can write out everything in one go
        // which is cheaper.
        prepareHeaders();
        FullHttpResponse resp;
        if (trailing != null) {
            resp = new AssembledFullHttpResponse(response, data, trailing.trailingHeaders(),
                    trailing.getDecoderResult());
        } else {
            resp = new AssembledFullHttpResponse(response, data);
        }
        channelFuture = conn.writeToChannel(resp);
    } else {
        if (!data.isReadable()) {
            if (trailing == null) {
                channelFuture = conn.writeToChannel(LastHttpContent.EMPTY_LAST_CONTENT);
            } else {
                channelFuture = conn.writeToChannel(trailing);
            }
        } else {
            LastHttpContent content;
            if (trailing != null) {
                content = new AssembledLastHttpContent(data, trailing.trailingHeaders(),
                        trailing.getDecoderResult());
            } else {
                content = new DefaultLastHttpContent(data, false);
            }
            channelFuture = conn.writeToChannel(content);
        }
    }

    if (!keepAlive) {
        closeConnAfterWrite();
        closed = true;
    }
    written = true;
    conn.responseComplete();
    if (bodyEndHandler != null) {
        bodyEndHandler.handle(null);
    }
    if (endHandler != null) {
        endHandler.handle(null);
    }
}