Skip to content

A free, open-source alternative to Burp Suite: an intercepting proxy and web app security testing suite with Repeater, Intruder, Collaborator and a built-in OWASP ZAP scanner. Linux, AGPL-3.0.

794 B
Raw Blame
package opensuite.script.api;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;

import opensuite.core.HttpMessage;

/** What the request and the response read from a message in the same way. */
final class Messages {

    private Messages() {}

    static List<String> headers(HttpMessage m) { return List.copyOf(m.headerLines()); }

    static String bodyText(HttpMessage m) { return new String(m.body(), charset(m)); }

    /** The declared charset when Java knows it, else UTF-8. */
    static Charset charset(HttpMessage m) {
        String name = m.charsetName();
        if (!name.isEmpty()) {
            try { return Charset.forName(name); } catch (RuntimeException ignored) { }
        }
        return StandardCharsets.UTF_8;
    }
}