(chunk)
| 6943 | writer.destroy(err); |
| 6944 | } finally { |
| 6945 | socket.off("close", onDrain).off("drain", onDrain); |
| 6946 | } |
| 6947 | }); |
| 6948 | } |
| 6949 | var AsyncWriter = class { |
| 6950 | constructor({ abort, socket, request, contentLength, client, expectsPayload, header }) { |
| 6951 | this.socket = socket; |
| 6952 | this.request = request; |
| 6953 | this.contentLength = contentLength; |
| 6954 | this.client = client; |
| 6955 | this.bytesWritten = 0; |
| 6956 | this.expectsPayload = expectsPayload; |
| 6957 | this.header = header; |
| 6958 | this.abort = abort; |
| 6959 | socket[kWriting] = true; |
| 6960 | } |
| 6961 | write(chunk) { |
| 6962 | const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this; |
| 6963 | if (socket[kError]) { |
| 6964 | throw socket[kError]; |
| 6965 | } |
| 6966 | if (socket.destroyed) { |
| 6967 | return false; |
| 6968 | } |
| 6969 | const len = Buffer.byteLength(chunk); |
| 6970 | if (!len) { |
| 6971 | return true; |
| 6972 | } |
| 6973 | if (contentLength !== null && bytesWritten + len > contentLength) { |
| 6974 | if (client[kStrictContentLength]) { |
| 6975 | throw new RequestContentLengthMismatchError(); |
| 6976 | } |
| 6977 | process.emitWarning(new RequestContentLengthMismatchError()); |
| 6978 | } |
| 6979 | socket.cork(); |
| 6980 | if (bytesWritten === 0) { |
| 6981 | if (!expectsPayload && request.reset !== false) { |
| 6982 | socket[kReset] = true; |
| 6983 | } |
| 6984 | if (contentLength === null) { |
| 6985 | socket.write(`${header}transfer-encoding: chunked\r |
| 6986 | `, "latin1"); |
| 6987 | } else { |
| 6988 | socket.write(`${header}content-length: ${contentLength}\r |
| 6989 | \r |
| 6990 | `, "latin1"); |
| 6991 | } |
| 6992 | } |
| 6993 | if (contentLength === null) { |
| 6994 | socket.write(`\r |
| 6995 | ${len.toString(16)}\r |
| 6996 | `, "latin1"); |
| 6997 | } |
no test coverage detected