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

no.sb1.troxy.http.common.Packet Maven / Gradle / Ivy

Go to download

Troxy is a proxy intended for simulating a remote service without actually connecting to the server. Incoming requests are matched using regular expressions and responses are created from a recorded response from the remote service and optionally modified by inserting values caught from the regular expression used to match the request.

There is a newer version: 3.2.49
Show newest version
package no.sb1.troxy.http.common;

/**
 * Common utility functions for Request and Response.

 */
public abstract class Packet {
    protected String discoverCharset(String header) {
        int start = header!=null ? header.indexOf("charset=") : -1;
        if (start >= 0) {
            start += 8;
            int end = header.indexOf(";", start);
            int pos = header.indexOf(" ", start);
            if (end == -1 || (pos != -1 && pos < end))
                end = pos;
            pos = header.indexOf("\n", start);
            if (end == -1 || (pos != -1 && pos < end))
                end = pos;
            if (end == -1)
                end = header.length();
            if (header.charAt(start) == '"' && header.charAt(end - 1) == '"') {
                ++start;
                --end;
            }
            return header.substring(start, end);
        }
        return "iso-8859-1";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy