'read a WebSocket frame header'

@classmethod
def from_file(cls, fp):

    (first_byte, second_byte) = fp.safe_read(2)
    fin = bits.getbit(first_byte, 7)
    rsv1 = bits.getbit(first_byte, 6)
    rsv2 = bits.getbit(first_byte, 5)
    rsv3 = bits.getbit(first_byte, 4)
    opcode = (first_byte & 15)
    mask_bit = bits.getbit(second_byte, 7)
    length_code = (second_byte & 127)
    if (length_code <= 125):
        payload_length = length_code
    elif (length_code == 126):
        (payload_length,) = struct.unpack('!H', fp.safe_read(2))
    else:
        (payload_length,) = struct.unpack('!Q', fp.safe_read(8))
    if (mask_bit == 1):
        masking_key = fp.safe_read(4)
    else:
        masking_key = None
    return cls(fin=fin, rsv1=rsv1, rsv2=rsv2, rsv3=rsv3, opcode=opcode, mask=mask_bit, length_code=length_code, payload_length=payload_length, masking_key=masking_key)
