Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function respond(code, headers, body) {
// Log the request
notify(item.method + " " + pathname + " " + code);
if (typeof body === "string") body = binary.fromUnicode(body);
var contentType, contentLength;
headers.forEach(function (pair) {
var key = pair[0].toLowerCase();
if (key === "content-type") contentType = pair[1];
else if (key === "content-length") contentLength = pair[1];
});
if (!contentType) headers.push(["Content-Type", "text/plain"]);
if (!contentLength) headers.push(["Content-Length", body.length]);
encode({
code: code,
headers: headers
});
encode(body);
encode();
}
}
return [301, { Location: url + "/" }];
}
// Load the actual tree listing, this should be cached by mem-cache.
var tree = yield repo.loadAs("tree", meta.hash);
// Look for a index file
if (tree["index.html"] && modes.isFile(tree["index.html"].mode)) {
meta = tree["index.html"];
url = pathJoin(url, "index.html");
// Fall through down to static file handler.
}
// Otherwise render a index file
else {
return [200, {
"ETag": '"' + meta.hash + '-html"',
"Content-Type": "text/html",
}, bodec.fromUnicode(formatTree(tree))];
}
}
if (modes.isFile(meta.mode)) {
var body = yield repo.loadAs("blob", meta.hash);
if (meta.mode === modes.exec) {
// #! but not #!/
if (body[0] === 0x23 && body[1] === 0x21 && body[2] !== 0x2f) {
var i = 2;
var language = "";
while (i < body.length && body[i] !== 0x0d && body[i] !== 0x0a) {
language += String.fromCharCode(body[i++]);
}
var runtime = runtimes[language];
if (!runtime) {
function respond(code, headers, body) {
// Log the request
notify(item.method + " " + pathname + " " + code);
if (typeof body === "string") body = bodec.fromUnicode(body);
var contentType, contentLength;
headers.forEach(function (pair) {
var key = pair[0].toLowerCase();
if (key === "content-type") contentType = pair[1];
else if (key === "content-length") contentLength = pair[1];
});
if (typeof body === "string") {
body = bodec.fromUnicode(body);
}
if (!contentType) headers.push(["Content-Type", "text/plain; charset=utf-8"]);
if (!contentLength) headers.push(["Content-Length", body.length]);
encode({
code: code,
headers: headers
});
encode(body);
function testEncodeBlob() {
blob = bodec.fromUnicode("Hello World\n");
blobBin = codec.frame({type: "blob", body: blob});
blobHash = sha1(blobBin);
if (blobHash !== '557db03de997c86a4a028e1ebd3a1ceb225be238') {
throw new Error("Invalid blob hash");
}
},
function testEncodeBlobInvalidType() {
return (item : string | Uint8Array | undefined | null) => {
if (item === undefined) return emit();
if (item === null) {
return emit(bodec.fromRaw("0000"));
}
if (typeof item === "string") {
item = bodec.fromUnicode(item);
}
return emit(bodec.join([frameHead(item.length + 4), item]));
};
}
paths: {},
headers: {},
};
function* load(path) {
var meta = yield repo.pathToEntry(root, path);
if (meta) {
recording.paths[path] = meta.hash;
meta.repo = repo;
}
return meta;
}
var result = yield* render(load, url);
if (result) {
if (typeof result[2] === "string") {
result[2] = bodec.fromUnicode(result[2]);
}
if (!result[1].ETag && bodec.isBinary(result[2])) {
result[1].ETag = '"' + sha1(result[2]) + '"';
}
recording.headers = result[1];
records[url] = recording;
}
return result;
}