private void parse(String request, boolean skipMethod)
    {
        String parts[] = request.split("\r\n\r\n", 2);
        boolean hasHeader = false;

        for (String part : parts) {
            if (hasHeader) {
                this.body = part;
                break;
            }

            if (skipMethod) {
                this.headers.parse(part);
                continue;
            }

            String[] headerSplit = part.split("\r\n", 2);
            if (headerSplit.length < 1) {
                throw new RuntimeException("Bad headers: missing HTTP method");
            }

            Pattern p = Pattern.compile("^(?<method>GET|SET|POST|PUT|DELETE)\\s+(<?path>/[^\\?]*)(\\?(<?query>.*))?\\s+HTTP/1.\\d+\r\n");
            Matcher m = p.matcher(headerSplit[0]);

            if (!m.matches()) {
                throw new RuntimeException("Failed to parse HTTP request method.");
            }

            String query = m.group("query");

            if (query != null) {
                this.setQuery(query);
            }

            this.setMethod(m.group("method"))
                .setPath(m.group("path"));


            if (headerSplit.length > 1) {
                this.headers.parse(headerSplit[1]);
            }
        }
    }