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

io.github.mike10004.vhs.harbridge.HarResponseData Maven / Gradle / Ivy

There is a newer version: 0.32
Show newest version
package io.github.mike10004.vhs.harbridge;

import com.google.common.io.ByteSource;
import com.google.common.net.MediaType;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Interface representing response data.
 */
public interface HarResponseData {

    List> headers();
    MediaType getContentType();
    ByteSource getBody();

    static HarResponseData of(Iterable> headers, @Nullable MediaType contentType, @Nullable ByteSource body) {
        return new SimpleHarResponseData(headers, contentType, body);
    }

    default HarResponseDataTransformer transformer() {
        return new HarResponseDataTransformer(this);
    }

    @Nullable
    default String getFirstHeaderValue(String headerName) {
        Objects.requireNonNull(headerName, "name");
        for (Map.Entry entry : headers()) {
            if (headerName.equalsIgnoreCase(entry.getKey())) {
                return entry.getValue();
            }
        }
        return null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy