MCPcopy
hub / github.com/nodejs/undici / onRequestUpgrade

Method onRequestUpgrade

docs/examples/proxy/proxy.js:122–147  ·  view source on GitHub ↗
(controller, statusCode, _headers, socket)

Source from the content-addressed store, hash-verified

120 }
121
122 onRequestUpgrade (controller, statusCode, _headers, socket) {
123 this.socket.off('close', this.abort)
124
125 // TODO: Check statusCode?
126
127 if (this.head && this.head.length) {
128 socket.unshift(this.head)
129 }
130
131 setupSocket(socket)
132
133 const headers = getHeaders({
134 headers: controller.rawHeaders ?? [],
135 proxyName: this.proxyName,
136 httpVersion: this.httpVersion
137 })
138
139 let head = ''
140 for (let n = 0; n < headers.length; n += 2) {
141 head += `\r\n${headers[n]}: ${headers[n + 1]}`
142 }
143
144 this.socket.write(`HTTP/1.1 101 Switching Protocols\r\nconnection: upgrade\r\nupgrade: websocket${head}\r\n\r\n`)
145
146 pipeline(socket, this.socket, socket, this.callback)
147 }
148
149 onResponseError (_controller, err) {
150 this.socket.off('close', this.abort)

Callers

nothing calls this directly

Calls 5

setupSocketFunction · 0.85
getHeadersFunction · 0.85
pipelineFunction · 0.85
offMethod · 0.80
writeMethod · 0.45

Tested by

no test coverage detected