from .Framework import SocketService


class HTTPSocket(SocketService):
    """
    I potentially want to update this later to check for the status code of each command.
    For example, the initial connection returns 220 on each line, EHLO does 250, and QUIT does 221
    """
    # def __init__(self, port=25):
    def __init__(self, port=None, tls=False):
        SocketService.__init__(self)
        if port:
            self.port = port
        elif tls:
            self.port = 443
        else:
            self.port = 80

        self.request = 'GET / HTTP/1.0 \r\n'.encode()
        self.tls = tls
        self.get_initial = False

    def _get_data(self):
        # For our Zabbix Triggers, 0 is good, 1 is bad.
        data = self._get_raw_data()
        if data and data.startswith('HTTP/1.'):
            return 0
        return 1

    def check(self):
        data = self.get_data()
        if data == 0:
            return True
        return False