MCPcopy Create free account
hub / github.com/awslabs/llrt / writeHead

Function writeHead

example/register-hooks/src/http.js:102–120  ·  view source on GitHub ↗
(statusCode, statusMessageOrHeaders, maybeHeaders)

Source from the content-addressed store, hash-verified

100 return resHeaders[name];
101 },
102 writeHead(statusCode, statusMessageOrHeaders, maybeHeaders) {
103 if (headersSent) return;
104 if (typeof statusMessageOrHeaders === "string") {
105 this.statusCode = statusCode;
106 this.statusMessage = statusMessageOrHeaders;
107 Object.assign(resHeaders, maybeHeaders || {});
108 } else {
109 this.statusCode = statusCode;
110 this.statusMessage = "OK";
111 Object.assign(resHeaders, statusMessageOrHeaders || {});
112 }
113 const headerLines = Object.entries(resHeaders)
114 .map(([k, v]) => `${k}: ${v}`)
115 .join("\r\n");
116 socket.write(
117 `HTTP/1.1 ${this.statusCode} ${this.statusMessage}\r\n${headerLines}\r\n\r\n`
118 );
119 headersSent = true;
120 },
121 write(chunk) {
122 if (!headersSent) {
123 this.writeHead(this.statusCode);

Callers

nothing calls this directly

Calls 3

joinMethod · 0.80
writeMethod · 0.65
entriesMethod · 0.45

Tested by

no test coverage detected