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

com.github.dreamhead.moco.dumper.HttpRequestDumper 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.HttpRequest;
import com.github.dreamhead.moco.Request;
import com.google.common.base.Joiner;
import io.netty.util.internal.StringUtil;

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

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

    @Override
    public String dump(final Request request) {
        HttpRequest httpRequest = (HttpRequest) request;
        StringBuilder buf = new StringBuilder();
        buf.append(requestProtocolLine(httpRequest))
                .append(StringUtil.NEWLINE)
                .append(headerJoiner.join(httpRequest.getHeaders()))
                .append(asContent(httpRequest));
        return buf.toString();
    }

    private String requestProtocolLine(final HttpRequest request) {
        return request.getMethod().name() + ' ' + request.getUri() + ' ' + request.getVersion().text();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy