Java Code Examples for org.eclipse.jetty.http.MetaData#Response

The following examples show how to use org.eclipse.jetty.http.MetaData#Response . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JettyService.java    From armeria with Apache License 2.0 6 votes vote down vote up
private static ResponseHeaders toResponseHeaders(ArmeriaHttpTransport transport) {
    final MetaData.Response info = transport.info;
    if (info == null) {
        throw new IllegalStateException("response metadata unavailable");
    }

    final ResponseHeadersBuilder headers = ResponseHeaders.builder();
    headers.status(info.getStatus());
    info.getFields().forEach(e -> headers.add(HttpHeaderNames.of(e.getName()), e.getValue()));

    if (transport.method != HttpMethod.HEAD) {
        headers.setLong(HttpHeaderNames.CONTENT_LENGTH, transport.contentLength);
    }

    return headers.build();
}
 
Example 2
Source File: JettyService.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Override
public void send(@Nullable MetaData.Response info, boolean head,
                 ByteBuffer content, boolean lastContent, Callback callback) {

    if (info != null) {
        this.info = info;
    }

    final int length = content.remaining();
    if (length == 0) {
        callback.succeeded();
        return;
    }

    if (content.hasArray()) {
        final int from = content.arrayOffset() + content.position();
        out.add(HttpData.wrap(Arrays.copyOfRange(content.array(), from, from + length)));
        content.position(content.position() + length);
    } else {
        final byte[] data = new byte[length];
        content.get(data);
        out.add(HttpData.wrap(data));
    }

    contentLength += length;
    callback.succeeded();
}
 
Example 3
Source File: Response.java    From onedev with MIT License 4 votes vote down vote up
protected MetaData.Response newResponseMetaData()
{
    MetaData.Response info = new MetaData.Response(_channel.getRequest().getHttpVersion(), getStatus(), getReason(), _fields, getLongContentLength());
    info.setTrailerSupplier(getTrailers());
    return info;
}
 
Example 4
Source File: Response.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Get the MetaData.Response committed for this response.
 * This may differ from the meta data in this response for
 * exceptional responses (eg 4xx and 5xx responses generated
 * by the container) and the committedMetaData should be used
 * for logging purposes.
 *
 * @return The committed MetaData or a {@link #newResponseMetaData()}
 * if not yet committed.
 */
public MetaData.Response getCommittedMetaData()
{
    MetaData.Response meta = _channel.getCommittedMetaData();
    if (meta == null)
        return newResponseMetaData();
    return meta;
}