| 7307 | return this.createError(ret, EMPTY_BUF); |
| 7308 | } |
| 7309 | createError(ret, data) { |
| 7310 | const { llhttp, contentLength, bytesRead } = this; |
| 7311 | if (contentLength !== -1 && bytesRead !== contentLength) { |
| 7312 | return new ResponseContentLengthMismatchError(); |
| 7313 | } |
| 7314 | const ptr = llhttp.llhttp_get_error_reason(this.ptr); |
| 7315 | let message = ""; |
| 7316 | if (ptr) { |
| 7317 | const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0); |
| 7318 | message = "Response does not match the HTTP/1.1 protocol (" + Buffer.from(llhttp.memory.buffer, ptr, len).toString() + ")"; |
| 7319 | } |
| 7320 | return new HTTPParserError(message, constants.ERROR[ret], data); |
| 7321 | } |
| 7322 | destroy() { |
| 7323 | assert(currentParser === null); |
| 7324 | assert(this.ptr != null); |