<commit_before>utils = require('./utils')

websocket_hixie76 = require('./trans-websocket-hixie76')
websocket_hybi10 = require('./trans-websocket-hybi10')


exports.app =
    websocket: (req, connection, head) ->
        if req.headers.upgrade.toLowerCase() isnt 'websocket'
            throw {
                status: 406
                message: "Can upgrade only to websockets."
            }
        origin = req.headers.origin
        if not utils.verify_origin(origin, req.sockjs_server.options.origins)
            throw {
                status: 403
                message: "Unverified origin."
            }
        location = (if origin and origin[0...5] is 'https' then 'wss' else 'ws')
        location += '://' + req.headers.host + req.url


        if req.headers['sec-websocket-version'] is '8'
            new websocket_hybi10.WebHandshake8(req, connection, head or '', origin, location)
        else
            new websocket_hixie76.WebHandshakeHixie76(req, connection, head or '', origin, location)
        return true
<commit_msg>Naively assuming that Hybi-10 is the same as Hybi-07<commit_after>utils = require('./utils')

websocket_hixie76 = require('./trans-websocket-hixie76')
websocket_hybi10 = require('./trans-websocket-hybi10')


exports.app =
    websocket: (req, connection, head) ->
        if req.headers.upgrade.toLowerCase() isnt 'websocket'
            throw {
                status: 406
                message: "Can upgrade only to websockets."
            }
        origin = req.headers.origin
        if not utils.verify_origin(origin, req.sockjs_server.options.origins)
            throw {
                status: 403
                message: "Unverified origin."
            }
        location = (if origin and origin[0...5] is 'https' then 'wss' else 'ws')
        location += '://' + req.headers.host + req.url


        ver = req.headers['sec-websocket-version']
        if  ver is '8' or ver is '7'
            new websocket_hybi10.WebHandshake8(req, connection, head or '', origin, location)
        else
            new websocket_hixie76.WebHandshakeHixie76(req, connection, head or '', origin, location)
        return true

{'fraction_non_alphanumeric': 0.11361545538178473, 'fraction_numerical': 0.02437902483900644, 'mean_word_length': 2.1385281385281387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '329174', 'n_tokens_mistral': 676, 'n_tokens_neox': 625, 'n_words': 156}