All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cz.jalasoft.net.http.netty.NettyHttpResponse Maven / Gradle / Ivy

Go to download

An implementation of HttpClient API that takes advantage of the Netty framework.

The newest version!
/*
 * Copyright (c) 2015 Avast a.s., www.avast.com
 */
package cz.jalasoft.net.http.netty;

import cz.jalasoft.net.http.HttpResponse;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.FullHttpResponse;

import java.nio.charset.Charset;

/**
 * An absraction of a HTTP response.
 *
 * @author Jan Lastovicka ([email protected])
 * @since 2015-02-21
 */
final class NettyHttpResponse implements HttpResponse {

    private final FullHttpResponse nettyResponse;

    NettyHttpResponse(FullHttpResponse nettyResponse) {
        this.nettyResponse = nettyResponse;
    }

    @Override
    public boolean isStatusOK() {
        return getStatusCode() == HttpResponse.RESPONSE_CODE_OK;
    }

    @Override
    public int getStatusCode() {
        int code = nettyResponse.getStatus().code();
        return code;
    }

    @Override
    public String getReason() {
        return nettyResponse.getStatus().reasonPhrase();
    }

    @Override
    public byte[] getContent() {
        ByteBuf content = nettyResponse.content();
        return content.array();
    }

    @Override
    public String getContentAsString() {
        return nettyResponse.content().toString(Charset.defaultCharset());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy