def extract_traffic(self, issue, binary_data=False):
            raw_traffic = issue.xpath("RawTraffic")[0]
            raw_request_traffic = issue.xpath("RawTraffic/RequestTraffic")
            raw_response_traffic = issue.xpath("RawTraffic/ResponseTraffic")
            raw_merged_traffic = issue.xpath("RawTraffic/MergedTraffic")

            # New nodes
            request_node = etree.Element("RequestTraffic")
            response_node = etree.Element("ResponseTraffic")
            request_node.text = ''
            response_node.text = ''

            # Add base64 flag to traffic
            request_node.attrib['base64'] = 'false'
            response_node.attrib['base64'] = 'false'

            # Check if merged traffic is provided
            if len(raw_merged_traffic) > 0:
                # Split traffic
                http_data = HTTPParser.split_http_traffic(raw_merged_traffic[0].text)

                # Adjust XML data
                if http_data:
                    request_node.text = etree.CDATA(http_data['request'])
                    raw_traffic.append(request_node)

                    response_node.text = etree.CDATA(http_data['response'])
                    raw_traffic.append(response_node)

                # Remove MergedTraffic node
                raw_merged_traffic[0].getparent().remove(raw_merged_traffic[0])

            # Check if request traffic already provided
            # TODO: Do the same for request traffic?
            if len(raw_request_traffic) > 0:

                if len(raw_request_traffic[0].text) > 0:
                    base64_flag = False
                    if 'base64' in raw_request_traffic[0].attrib:
                        if raw_request_traffic[0].attrib['base64'] == 'true':
                            base64_flag = True

                    # Check if base64
                    if base64_flag:
                        # Replace binary data by plaintext data
                        decoded_request_data = base64.b64decode(raw_request_traffic[0].text).decode("utf-8")

                        raw_request_traffic[0].getparent().remove(raw_request_traffic[0])
                        new_request_traffic = etree.Element("RequestTraffic")
                        new_request_traffic.text = etree.CDATA(decoded_request_data)
                        new_request_traffic.attrib['base64'] = "false"

                        # Append new node
                        raw_traffic.append(new_request_traffic)

            else:
                # Add new nodes
                raw_traffic.append(request_node)
                raw_traffic.append(response_node)
Extract HTTP traffic from RawTraffic/MergedTraffic and adjust XML in single issue
dataset/ETHPy150Open dorneanu/appvulnms/src/core/parser/AppVulnXMLParser.py/AppVulnXMLParser.extract_traffic