* @param {string|Uint8Array} chunk * @returns
(chunk)
| 8170 | * @returns |
| 8171 | */ |
| 8172 | write(chunk) { |
| 8173 | const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this; |
| 8174 | if (socket[kError]) { |
| 8175 | throw socket[kError]; |
| 8176 | } |
| 8177 | if (socket.destroyed) { |
| 8178 | return false; |
| 8179 | } |
| 8180 | const len = chunk instanceof Uint8Array ? chunk.byteLength : Buffer.byteLength(chunk); |
| 8181 | if (!len) { |
| 8182 | return true; |
| 8183 | } |
| 8184 | if (contentLength !== null && bytesWritten + len > contentLength) { |
| 8185 | if (client[kStrictContentLength]) { |
| 8186 | throw new RequestContentLengthMismatchError(); |
| 8187 | } |
| 8188 | process.emitWarning(new RequestContentLengthMismatchError()); |
| 8189 | } |
| 8190 | socket.cork(); |
| 8191 | if (bytesWritten === 0) { |
| 8192 | if (!expectsPayload && request.reset !== false) { |
| 8193 | socket[kReset] = true; |
| 8194 | } |
| 8195 | if (contentLength === null) { |
| 8196 | socket.write(`${header}transfer-encoding: chunked\r |
| 8197 | `, "latin1"); |
| 8198 | } else { |
| 8199 | socket.write(`${header}content-length: ${contentLength}\r |
| 8200 | \r |
| 8201 | `, "latin1"); |
| 8202 | } |
| 8203 | } |
| 8204 | if (contentLength === null) { |
| 8205 | socket.write(`\r |
| 8206 | ${len.toString(16)}\r |
| 8207 | `, "latin1"); |
| 8208 | } |
| 8209 | this.bytesWritten += len; |
| 8210 | const ret = socket.write(chunk); |
| 8211 | socket.uncork(); |
| 8212 | request.onBodySent(chunk); |
| 8213 | if (!ret) { |
| 8214 | if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) { |
| 8215 | if (socket[kParser].timeout.refresh) { |
| 8216 | socket[kParser].timeout.refresh(); |
| 8217 | } |
| 8218 | } |
| 8219 | } |
| 8220 | return ret; |
| 8221 | } |
| 8222 | /** |
| 8223 | * @returns {void} |
| 8224 | */ |
no test coverage detected