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

com.github.dreamhead.moco.dumper.HttpResponseDumper Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.dumper;

import com.github.dreamhead.moco.HttpResponse;
import com.github.dreamhead.moco.Response;
import com.google.common.base.Joiner;
import io.netty.util.internal.StringUtil;

import static com.github.dreamhead.moco.dumper.HttpDumpers.asContent;

public class HttpResponseDumper implements Dumper {
    private final Joiner.MapJoiner headerJoiner = Joiner.on(StringUtil.NEWLINE).withKeyValueSeparator(": ");

    @Override
    public String dump(final Response response) {
        HttpResponse httpResponse = (HttpResponse) response;
        StringBuilder buf = new StringBuilder();
        buf.append(responseProtocolLine(httpResponse))
                .append(StringUtil.NEWLINE)
                .append(headerJoiner.join(httpResponse.getHeaders()))
                .append(asContent(httpResponse));

        return buf.toString();
    }

    private String responseProtocolLine(final HttpResponse httpResponse) {
        return httpResponse.getVersion().text() + ' ' + httpResponse.getStatus();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy