(client, request)
| 7851 | } |
| 7852 | __name(shouldSendContentLength, "shouldSendContentLength"); |
| 7853 | function writeH1(client, request) { |
| 7854 | const { method, path, host, upgrade, blocking, reset } = request; |
| 7855 | let { body, headers, contentLength } = request; |
| 7856 | const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH"; |
| 7857 | if (util.isFormDataLike(body)) { |
| 7858 | if (!extractBody) { |
| 7859 | extractBody = require_body().extractBody; |
| 7860 | } |
| 7861 | const [bodyStream, contentType] = extractBody(body); |
| 7862 | if (request.contentType == null) { |
| 7863 | headers.push("content-type", contentType); |
| 7864 | } |
| 7865 | body = bodyStream.stream; |
| 7866 | contentLength = bodyStream.length; |
| 7867 | } else if (util.isBlobLike(body) && request.contentType == null && body.type) { |
| 7868 | headers.push("content-type", body.type); |
| 7869 | } |
| 7870 | if (body && typeof body.read === "function") { |
| 7871 | body.read(0); |
| 7872 | } |
| 7873 | const bodyLength = util.bodyLength(body); |
| 7874 | contentLength = bodyLength ?? contentLength; |
| 7875 | if (contentLength === null) { |
| 7876 | contentLength = request.contentLength; |
| 7877 | } |
| 7878 | if (contentLength === 0 && !expectsPayload) { |
| 7879 | contentLength = null; |
| 7880 | } |
| 7881 | if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) { |
| 7882 | if (client[kStrictContentLength]) { |
| 7883 | util.errorRequest(client, request, new RequestContentLengthMismatchError()); |
| 7884 | return false; |
| 7885 | } |
| 7886 | process.emitWarning(new RequestContentLengthMismatchError()); |
| 7887 | } |
| 7888 | const socket = client[kSocket]; |
| 7889 | clearIdleSocketValidation(socket); |
| 7890 | const abort = /* @__PURE__ */ __name((err) => { |
| 7891 | if (request.aborted || request.completed) { |
| 7892 | return; |
| 7893 | } |
| 7894 | util.errorRequest(client, request, err || new RequestAbortedError()); |
| 7895 | util.destroy(body); |
| 7896 | util.destroy(socket, new InformationalError("aborted")); |
| 7897 | }, "abort"); |
| 7898 | try { |
| 7899 | request.onRequestStart(abort, null); |
| 7900 | } catch (err) { |
| 7901 | util.errorRequest(client, request, err); |
| 7902 | } |
| 7903 | if (request.aborted) { |
| 7904 | return false; |
| 7905 | } |
| 7906 | if (method === "HEAD") { |
| 7907 | socket[kReset] = true; |
| 7908 | } |
| 7909 | if (upgrade || method === "CONNECT") { |
| 7910 | socket[kReset] = true; |
no test coverage detected
searching dependent graphs…