def getNewHeader(self, requestInfo, token, isCookie):
        headers = requestInfo.getHeaders()
        if isCookie:
            cookieHeader = "Cookie:"
            newheader = cookieHeader
            previousCookies = []
            # NOTE: getHeaders has to be called again here cuz of java references
            for header in requestInfo.getHeaders():
                # Find and remove existing cookie header
                if str(header).startswith(cookieHeader):
                    previousCookies = str(header)[len(cookieHeader):].replace(" ","").split(";")
                    headers.remove(header)

            newCookies = token.replace(" ","").split(";")
            newCookieVariableNames = []
            for newCookie in newCookies:
                # If its a valid cookie
                equalsToken = newCookie.find("=")
                if equalsToken >= 0:
                    newCookieVariableNames.append(newCookie[0:equalsToken+1])

            # Add all the old unchanged cookies
            for previousCookie in previousCookies:
                # If its a valid cookie
                equalsToken = previousCookie.find("=")
                if equalsToken >= 0:
                    if previousCookie[0:equalsToken+1] not in newCookieVariableNames:
                        newCookies.append(previousCookie)

            # Remove whitespace
            newCookies = [x for x in newCookies if x]
            newheader = cookieHeader+" "+";".join(newCookies)

        else:
            # TODO: Support multiple headers with a newline somehow
            newheader = token
            # Remove previous HTTP Header
            colon = newheader.find(":")
            if colon >= 0:
                # getHeaders has to be called again here cuz of java references
                for header in requestInfo.getHeaders():
                    # If the header already exists, remove it
                    if str(header).startswith(newheader[0:colon+1]):
                        headers.remove(header)
        headers.add(newheader)
        return headers
dataset/ETHPy150Open SecurityInnovation/AuthMatrix/AuthMatrix.py/BurpExtender.getNewHeader/original