Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!protocol) {
protocol = state.options.protocol
}
debug('incoming socket protocol=%j', protocol)
// No way we can do anything with the socket
if (!protocol || protocol === 'http/1.1' || protocol === 'http/1.0') {
debug('to default handler it goes')
return this._invokeDefault(socket)
}
socket.setNoDelay(true)
var connection = transport.connection.create(socket, Object.assign({
protocol: /spdy/.test(protocol) ? 'spdy' : 'http2',
isServer: true
}, state.options.connection || {}))
// Set version when we are certain
if (protocol === 'http2') { connection.start(4) } else if (protocol === 'spdy/3.1') {
connection.start(3.1)
} else if (protocol === 'spdy/3') { connection.start(3) } else if (protocol === 'spdy/2') {
connection.start(2)
}
connection.on('error', function () {
socket.destroy()
})
var self = this
if (!protocol) {
protocol = state.options.protocol
}
debug('incoming socket protocol=%j', protocol)
// No way we can do anything with the socket
if (!protocol || protocol === 'http/1.1' || protocol === 'http/1.0') {
debug('to default handler it goes')
return this._invokeDefault(socket)
}
socket.setNoDelay(true)
var connection = transport.connection.create(socket, Object.assign({
protocol: /spdy/.test(protocol) ? 'spdy' : 'http2',
isServer: true
}, state.options.connection || {}))
// Set version when we are certain
if (protocol === 'http2') { connection.start(4) } else if (protocol === 'spdy/3.1') {
connection.start(3.1)
} else if (protocol === 'spdy/3') { connection.start(3) } else if (protocol === 'spdy/2') {
connection.start(2)
}
connection.on('error', function () {
socket.destroy()
})
var self = this
socket.alpnProtocol ||
state.options.protocol
} else {
protocol = state.options.protocol
}
// HTTP server - kill socket and switch to the fallback mode
if (!protocol || protocol === 'http/1.1' || protocol === 'http/1.0') {
debug('activating fallback')
socket.destroy()
state.fallback = true
return
}
debug('connected protocol=%j', protocol)
var connection = transport.connection.create(socket, Object.assign({
protocol: /spdy/.test(protocol) ? 'spdy' : 'http2',
isServer: false
}, state.options.connection || {}))
// Pass connection level errors are passed to the agent.
connection.on('error', function (err) {
self.emit('error', err)
})
// Set version when we are certain
if (protocol === 'h2') {
connection.start(4)
} else if (protocol === 'spdy/3.1') {
connection.start(3.1)
} else if (protocol === 'spdy/3') {
connection.start(3)
socket.alpnProtocol ||
state.options.protocol
} else {
protocol = state.options.protocol
}
// HTTP server - kill socket and switch to the fallback mode
if (!protocol || protocol === 'http/1.1' || protocol === 'http/1.0') {
debug('activating fallback')
socket.destroy()
state.fallback = true
return
}
debug('connected protocol=%j', protocol)
var connection = transport.connection.create(socket, Object.assign({
protocol: /spdy/.test(protocol) ? 'spdy' : 'http2',
isServer: false
}, state.options.connection || {}))
// Set version when we are certain
if (protocol === 'h2') {
connection.start(4)
} else if (protocol === 'spdy/3.1') {
connection.start(3.1)
} else if (protocol === 'spdy/3') {
connection.start(3)
} else if (protocol === 'spdy/2') {
connection.start(2)
} else {
socket.destroy()
callback(new Error('Unexpected protocol: ' + protocol))
it('can be created', () => {
const p = pair()
spdyMuxer = spdy.connection.create(toStream(p), {
protocol: 'spdy',
isServer: false
})
muxer = new Muxer(p, spdyMuxer)
})
function create (rawConn, isListener) {
const conn = toStream(rawConn)
conn.on('end', () => conn.destroy())
const spdyMuxer = spdy.connection.create(conn, {
protocol: 'spdy',
isServer: isListener
})
return new Muxer(rawConn, spdyMuxer)
}