| 54205 | while (!this.paused && this.ptr) { |
| 54206 | const chunk = this.socket.read(); |
| 54207 | if (chunk === null) { |
| 54208 | break; |
| 54209 | } |
| 54210 | this.execute(chunk); |
| 54211 | } |
| 54212 | } |
| 54213 | execute(data) { |
| 54214 | assert2(this.ptr != null); |
| 54215 | assert2(currentParser == null); |
| 54216 | assert2(!this.paused); |
| 54217 | const { socket, llhttp } = this; |
| 54218 | if (data.length > currentBufferSize) { |
| 54219 | if (currentBufferPtr) { |
| 54220 | llhttp.free(currentBufferPtr); |
| 54221 | } |
| 54222 | currentBufferSize = Math.ceil(data.length / 4096) * 4096; |
| 54223 | currentBufferPtr = llhttp.malloc(currentBufferSize); |
| 54224 | } |
| 54225 | new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize).set(data); |
| 54226 | try { |
| 54227 | let ret; |
| 54228 | try { |
| 54229 | currentBufferRef = data; |
| 54230 | currentParser = this; |
| 54231 | ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, data.length); |
| 54232 | } catch (err) { |
| 54233 | throw err; |
| 54234 | } finally { |
| 54235 | currentParser = null; |
| 54236 | currentBufferRef = null; |
| 54237 | } |
| 54238 | const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr; |
| 54239 | if (ret === constants3.ERROR.PAUSED_UPGRADE) { |
| 54240 | this.onUpgrade(data.slice(offset)); |
| 54241 | } else if (ret === constants3.ERROR.PAUSED) { |
| 54242 | this.paused = true; |
| 54243 | socket.unshift(data.slice(offset)); |
| 54244 | } else if (ret !== constants3.ERROR.OK) { |
| 54245 | const ptr = llhttp.llhttp_get_error_reason(this.ptr); |
| 54246 | let message = ""; |
| 54247 | if (ptr) { |
| 54248 | const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0); |
| 54249 | message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")"; |
| 54250 | } |
| 54251 | throw new HTTPParserError(message, constants3.ERROR[ret], data.slice(offset)); |
| 54252 | } |
| 54253 | } catch (err) { |