Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/handlers/map.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,19 @@ const MapGet = class MapGet {
} else {
outgoing.statusCode = 200;
outgoing.stream = file.stream;

outgoing.stream.on("error", (err) => {
this._log.info(`map:get - File stream error - ${err}`);
end({ labels: { success: false, status: 503, type: "map" } });
});

outgoing.stream.on("end", () => {
end({ labels: { status: outgoing.statusCode, type: "map" } });
});
}

this._log.debug(`map:get - Import map found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode, type: "map" } });

return outgoing;
// eslint-disable-next-line no-unused-vars
} catch (error) {
Expand Down
11 changes: 9 additions & 2 deletions lib/handlers/pkg.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,19 @@ const PkgGet = class PkgGet {
} else {
outgoing.statusCode = 200;
outgoing.stream = file.stream;

outgoing.stream.on("error", (err) => {
this._log.info(`pkg:get - File stream error - ${err}`);
end({ labels: { success: false, status: 503, type } });
});

outgoing.stream.on("end", () => {
end({ labels: { status: outgoing.statusCode, type } });
});
}

this._log.debug(`pkg:get - Asset found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
// eslint-disable-next-line no-unused-vars
} catch (error) {
Expand Down
11 changes: 9 additions & 2 deletions lib/handlers/pkg.log.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ const PkgLog = class PkgLog {
} else {
outgoing.statusCode = 200;
outgoing.stream = file.stream;

outgoing.stream.on("error", (err) => {
this._log.info(`pkg:log - File stream error - ${err}`);
end({ labels: { success: false, status: 503, type } });
});

outgoing.stream.on("end", () => {
end({ labels: { status: outgoing.statusCode, type } });
});
}

this._log.debug(`pkg:log - Package log found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
// eslint-disable-next-line no-unused-vars
} catch (error) {
Expand Down
11 changes: 9 additions & 2 deletions lib/handlers/versions.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,19 @@ const VersionsGet = class VersionsGet {
} else {
outgoing.statusCode = 200;
outgoing.stream = file.stream;

outgoing.stream.on("error", (err) => {
this._log.info(`pkg:latest - File stream error - ${err}`);
end({ labels: { success: false, status: 503, type } });
});

outgoing.stream.on("end", () => {
end({ labels: { status: outgoing.statusCode, type } });
});
}

this._log.debug(`pkg:latest - Package log found - Pathname: ${path}`);

end({ labels: { status: outgoing.statusCode, type } });

return outgoing;
// eslint-disable-next-line no-unused-vars
} catch (error) {
Expand Down
20 changes: 16 additions & 4 deletions lib/sinks/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const DEFAULT_ROOT_PATH = "/eik";
* @deprecated Use eik/sink-memory or implement your own. This class will be removed in a future version of core.
*/
export default class SinkTest extends Sink {
readDelay = 0;

constructor({ rootPath = DEFAULT_ROOT_PATH } = {}) {
super();
this._rootPath = rootPath;
Expand Down Expand Up @@ -193,12 +195,22 @@ export default class SinkTest extends Sink {
etag: entry.hash,
});

const readDelay = this.readDelay;
file.stream = new Readable({
read() {
payload.forEach((item) => {
this.push(item);
});
this.push(null);
if (readDelay) {
setTimeout(() => {
payload.forEach((item) => {
this.push(item);
});
this.push(null);
}, readDelay);
} else {
payload.forEach((item) => {
this.push(item);
});
this.push(null);
}
},
});

Expand Down
1 change: 1 addition & 0 deletions test/handlers/pkg.get.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const Request = class Request extends PassThrough {

tap.test("pkg.get() - URL parameters is URL encoded", async (t) => {
const sink = new Sink();
sink.readDelay = 10_000;
sink.set("/local/pkg/@foo/bar-lib/8.1.4-1/foo/main.js", "payload");

const h = new Handler({ sink });
Expand Down
Loading