* @param {import('./client.js')} client * @param {import('../core/request.js')} request * @returns
(client, request)
| 1140 | * @returns |
| 1141 | */ |
| 1142 | function writeH1 (client, request) { |
| 1143 | const { method, path, host, upgrade, blocking, reset } = request |
| 1144 | |
| 1145 | let { body, headers, contentLength } = request |
| 1146 | |
| 1147 | // https://tools.ietf.org/html/rfc7231#section-4.3.1 |
| 1148 | // https://tools.ietf.org/html/rfc7231#section-4.3.2 |
| 1149 | // https://tools.ietf.org/html/rfc7231#section-4.3.5 |
| 1150 | |
| 1151 | // Sending a payload body on a request that does not |
| 1152 | // expect it can cause undefined behavior on some |
| 1153 | // servers and corrupt connection state. Do not |
| 1154 | // re-use the connection for further requests. |
| 1155 | |
| 1156 | const expectsPayload = ( |
| 1157 | method === 'PUT' || |
| 1158 | method === 'POST' || |
| 1159 | method === 'PATCH' || |
| 1160 | method === 'QUERY' || |
| 1161 | method === 'PROPFIND' || |
| 1162 | method === 'PROPPATCH' |
| 1163 | ) |
| 1164 | |
| 1165 | if (util.isFormDataLike(body)) { |
| 1166 | if (!extractBody) { |
| 1167 | extractBody = require('../web/fetch/body.js').extractBody |
| 1168 | } |
| 1169 | |
| 1170 | const [bodyStream, contentType] = extractBody(body) |
| 1171 | if (request.contentType == null) { |
| 1172 | headers.push('content-type', contentType) |
| 1173 | } |
| 1174 | body = bodyStream.stream |
| 1175 | contentLength = bodyStream.length |
| 1176 | } else if (util.isBlobLike(body) && request.contentType == null && body.type) { |
| 1177 | headers.push('content-type', body.type) |
| 1178 | } |
| 1179 | |
| 1180 | if (body && typeof body.read === 'function') { |
| 1181 | // Try to read EOF in order to get length. |
| 1182 | body.read(0) |
| 1183 | } |
| 1184 | |
| 1185 | const bodyLength = util.bodyLength(body) |
| 1186 | |
| 1187 | contentLength = bodyLength ?? contentLength |
| 1188 | |
| 1189 | if (contentLength === null) { |
| 1190 | contentLength = request.contentLength |
| 1191 | } |
| 1192 | |
| 1193 | if (contentLength === 0 && !expectsPayload) { |
| 1194 | // https://tools.ietf.org/html/rfc7230#section-3.3.2 |
| 1195 | // A user agent SHOULD NOT send a Content-Length header field when |
| 1196 | // the request message does not contain a payload body and the method |
| 1197 | // semantics do not anticipate such a body. |
| 1198 | |
| 1199 | contentLength = null |
no test coverage detected
searching dependent graphs…