'Check received headers for sanity and correctness, and stash any data
from them which will be required later.'

def validateHeaders(self):

    if (not is_websocket(self.headers)):
        log.msg('Not    handling    non-WS    request')
        return False
    if ('Host' in self.headers):
        self.host = self.headers['Host']
    if ('Origin' in self.headers):
        self.origin = self.headers['Origin']
    protocols = None
    if ('WebSocket-Protocol' in self.headers):
        protocols = self.headers['WebSocket-Protocol']
    elif ('Sec-WebSocket-Protocol' in self.headers):
        protocols = self.headers['Sec-WebSocket-Protocol']
    if isinstance(protocols, basestring):
        protocols = [p.strip() for p in protocols.split(',')]
        for protocol in protocols:
            if ((protocol in encoders) or (protocol in decoders)):
                log.msg(('Using    WS    protocol    %s!' % protocol))
                self.codec = protocol
                break
            log.msg(("Couldn't    handle    WS    protocol    %s!" % protocol))
        if (not self.codec):
            return False
    if is_hybi00(self.headers):
        log.msg('Starting    HyBi-00/Hixie-76    handshake')
        self.flavor = HYBI00
        self.state = CHALLENGE
    if ('Sec-WebSocket-Version' in self.headers):
        version = self.headers['Sec-WebSocket-Version']
        if (version == '7'):
            log.msg('Starting    HyBi-07    conversation')
            self.sendHyBi07Preamble()
            self.flavor = HYBI07
            self.state = FRAMES
        elif (version == '8'):
            log.msg('Starting    HyBi-10    conversation')
            self.sendHyBi07Preamble()
            self.flavor = HYBI10
            self.state = FRAMES
        elif (version == '13'):
            log.msg('Starting    RFC    6455    conversation')
            self.sendHyBi07Preamble()
            self.flavor = RFC6455
            self.state = FRAMES
        else:
            log.msg(("Can't    support    protocol    version    %s!" % version))
            return False
    self.validationMade()
    return True
