private int findHeaderEndTag(int index) {
        int currentIdx = index;
        int depth = 0;
        while (currentIdx < buffer.length()) {
            byte currentByte = buffer.get(currentIdx);
            if (currentByte == (byte) '<') {
                boolean isEndTag = (currentIdx + 1) < buffer.length() && buffer.get(currentIdx+1) == '/';
                if (isEndTag && depth > 0) {
                    // Found an end tag corresponding to some header element within soap:Header
                    depth--;
                    currentIdx = findFrom('>', currentIdx + 1);
                    if (currentIdx == -1) {
                        return -1;
                    }
                } else if (isEndTag && depth == 0) {
                    // Found it!  Probably.
                    int end = findFrom('>', currentIdx + 1);
                    return end;
                } else {
                    // Found a start tag corresponding to a child element of soap:Header
                    depth++;
                    currentIdx = findFrom('>', currentIdx + 1);
                    if (currentIdx == -1) {
                        return -1;
                    }
                }
            } else {
                currentIdx++;
            }
        }
        return -1;
    }
Scans through the buffer, starting at the given index, looking for the
soap:Header end tag (</soap:Header>)  The end tag may have any prefix, or
none at all.  We'll actually just scan for end tags until we find one that
should match the current element.
@param index
gateway/engine/core/src/main/java/io/apiman/gateway/engine/soap/SoapHeaderScanner.java