code: function getHeader(data, headerStart)
  {
    // 'start' position of the header.
    let start = headerStart;
    // 'end' position of the header.
    let end = 0;
    // 'partial end' position of the header.
    let partialEnd = 0;
  
    // End of message.
    if (data.substring(start, start + 2).match(/(^\r\n)/))
    {
      return -2;
    }
  
    while (end === 0)
    {
      // Partial End of Header.
      partialEnd = data.indexOf('\r\n', start);
  
      // 'indexOf' returns -1 if the value to be found never occurs.
      if (partialEnd === -1)
      {
        return partialEnd;
      }
  
      if (!data.substring(partialEnd + 2, partialEnd + 4).match(/(^\r\n)/) && data.charAt(partialEnd + 2).match(/(^\s+)/))
      {
        // Not the end of the message. Continue from the next position.
        start = partialEnd + 2;
      }
      else
      {
        end = partialEnd;
      }
    }
  
    return end;
  }
docs: Extract and parse every header of a SIP message.