MCPcopy Create free account
hub / github.com/angular/dev-infra / writeH1

Function writeH1

github-actions/browserstack/set-browserstack-env.js:6635–6756  ·  view source on GitHub ↗
(client, request)

Source from the content-addressed store, hash-verified

6633 socket[kParser].setTimeout(headersTimeout, TIMEOUT_HEADERS);
6634 }
6635 }
6636 }
6637 }
6638 function shouldSendContentLength(method) {
6639 return method !== "GET" && method !== "HEAD" && method !== "OPTIONS" && method !== "TRACE" && method !== "CONNECT";
6640 }
6641 function writeH1(client, request) {
6642 const { method, path: path4, host, upgrade, blocking, reset } = request;
6643 let { body, headers, contentLength } = request;
6644 const expectsPayload = method === "PUT" || method === "POST" || method === "PATCH" || method === "QUERY" || method === "PROPFIND" || method === "PROPPATCH";
6645 if (util.isFormDataLike(body)) {
6646 if (!extractBody) {
6647 extractBody = require_body().extractBody;
6648 }
6649 const [bodyStream, contentType] = extractBody(body);
6650 if (request.contentType == null) {
6651 headers.push("content-type", contentType);
6652 }
6653 body = bodyStream.stream;
6654 contentLength = bodyStream.length;
6655 } else if (util.isBlobLike(body) && request.contentType == null) {
6656 const contentType = body.type;
6657 if (contentType) {
6658 const contentTypeValue = `${contentType}`;
6659 if (!util.isValidHeaderValue(contentTypeValue)) {
6660 util.errorRequest(client, request, new InvalidArgumentError("invalid content-type header"));
6661 return false;
6662 }
6663 headers.push("content-type", contentTypeValue);
6664 }
6665 }
6666 if (body && typeof body.read === "function") {
6667 body.read(0);
6668 }
6669 const bodyLength = util.bodyLength(body);
6670 contentLength = bodyLength != null ? bodyLength : contentLength;
6671 if (contentLength === null) {
6672 contentLength = request.contentLength;
6673 }
6674 if (contentLength === 0 && !expectsPayload) {
6675 contentLength = null;
6676 }
6677 if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) {
6678 if (client[kStrictContentLength]) {
6679 util.errorRequest(client, request, new RequestContentLengthMismatchError());
6680 return false;
6681 }
6682 process.emitWarning(new RequestContentLengthMismatchError());
6683 }
6684 const socket = client[kSocket];
6685 clearIdleSocketValidation(socket);
6686 const abort = (err) => {
6687 if (request.aborted || request.completed) {
6688 return;
6689 }
6690 util.errorRequest(client, request, err || new RequestAbortedError());
6691 util.destroy(body);
6692 util.destroy(socket, new InformationalError("aborted"));

Callers 1

writeFunction · 0.70

Calls 10

extractBodyFunction · 0.70
shouldSendContentLengthFunction · 0.70
writeBufferFunction · 0.70
writeIterableFunction · 0.70
writeBlobFunction · 0.70
writeStreamFunction · 0.70
pushMethod · 0.45
onConnectMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected