Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
for (var path in recording.paths) {
var actual = (yield repo.pathToEntry(root, path)).hash;
var expected = recording.paths[path];
if (actual !== expected) {
console.log("change in " + path + " from " + expected + " to " + actual);
break outer;
}
}
return [304, recording.headers];
}
}
if (result === false) result = (yield* execute(root, code, url));
if (result) {
var headers = result[1];
if (bodec.isBinary(result[2])) {
// Auto deflate text files if request accepts it.
if (/\b(?:text|javascript)\b/.test(headers["Content-Type"]) &&
/\bgzip\b/.test(req.headers["accept-encoding"])) {
result[2] = yield function (callback) {
zlib.gzip(result[2], callback);
};
headers["Content-Encoding"] = "gzip";
}
// Auto-add Content-Length header for response bodies.
if (!headers["Content-Length"]) {
headers["Content-Length"] = result[2].length;
}
}
}
function testRoundTrip() {
const deflated = deflate(bin);
if (!bodec.isBinary(deflated)) {
throw new Error("deflate output should be native binary");
}
const inflated = inflate(deflated);
if (!bodec.isBinary(inflated)) {
throw new Error("inflate output should be native binary");
}
if (bodec.toRaw(bin) !== bodec.toRaw(inflated)) {
console.log([bin, inflated]);
throw new Error("Problem with roundtrip");
}
},
function testStream() {
items.forEach(item => {
if (!bodec.isBinary(item.body)) {
item.body = encoders[item.type](item.body);
}
write(item);
});
write();
};
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;
}
function onNak(line) {
if (line === undefined) return api.put();
if (line === null) return socket.take(onNak);
if (bodec.isBinary(line) || line.progress || line.error) {
packChannel = makeChannel();
progressChannel = makeChannel();
errorChannel = makeChannel();
api.put({
pack: { take: packChannel.take },
progress: { take: progressChannel.take },
error: { take: errorChannel.take },
});
return onMore(null, line);
}
let match = line.match(/^shallow ([0-9a-f]{40})$/);
if (match) {
refs.shallows.push(match[1]);
return socket.take(onNak);
}
match = line.match(/^ACK ([0-9a-f]{40})$/);
function encodeBlob(blob) {
if (typeof blob === "string") return {
content: bodec.encodeUtf8(blob),
encoding: "utf-8"
};
if (bodec.isBinary(blob)) return {
content: bodec.toBase64(blob),
encoding: "base64"
};
throw new TypeError("Invalid blob type, must be binary or string");
}
var toCreate = entries.filter(function (entry) {
return bodec.isBinary(entry.content);
});
return function (res) {
if (res === undefined) return write(undefined);
if (bodec.isBinary(res)) return write(res);
var head = "HTTP/1.1 " + res.code + " " + STATUS_CODES[res.code] + "\r\n";
res.headers.forEach(function (pair) {
head += pair[0] + ": " + pair[1] + "\r\n";
});
head += "\r\n";
write(bodec.fromUnicode(head));
};
}
function* execute(url) {
var recording = {
paths: {},
headers: {}
};
var result = yield* render(pathToEntryRecorded, url, runtimes);
if (!result) return;
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;
function* pathToEntryRecorded(path) {
var meta = yield* pathToEntry(path);
if (meta) recording.paths[path] = meta.hash;
return meta;
}
}
};