summaryrefslogtreecommitdiff
path: root/u/server/response/pengueno.ts
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-07-27 18:50:33 -0700
committerElizabeth Hunt <me@liz.coffee>2025-07-27 19:31:06 -0700
commit7aa11b7a8abacf81dec20fff21216df35d333756 (patch)
tree40f6a76c37412cf1c5a67f99a4ee30e3aae863c9 /u/server/response/pengueno.ts
parente4df72cd446270cf867ec308995a05e21b3aa601 (diff)
downloadci-7aa11b7a8abacf81dec20fff21216df35d333756.tar.gz
ci-7aa11b7a8abacf81dec20fff21216df35d333756.zip
Pulls in pengueno from npm
Diffstat (limited to 'u/server/response/pengueno.ts')
-rw-r--r--u/server/response/pengueno.ts59
1 files changed, 0 insertions, 59 deletions
diff --git a/u/server/response/pengueno.ts b/u/server/response/pengueno.ts
deleted file mode 100644
index 5a953db..0000000
--- a/u/server/response/pengueno.ts
+++ /dev/null
@@ -1,59 +0,0 @@
-import {
- BaseResponse,
- Body,
- HttpStatusCodes,
- ITraceable,
- Metric,
- Optional,
- PenguenoRequest,
- ResponseOpts,
- ServerTrace,
-} from '@emprespresso/pengueno';
-
-const getHeaders = (req: PenguenoRequest, extraHeaders: Record<string, string>) => {
- const optHeaders = {
- ...req.getResponseHeaders(),
- ...extraHeaders,
- };
- optHeaders['Content-Type'] = (optHeaders['Content-Type'] ?? 'text/plain') + '; charset=utf-8';
- return optHeaders;
-};
-
-const ResponseCodeMetrics = [0, 1, 2, 3, 4, 5].map((x) => Metric.fromName(`response.${x}xx`).asResult());
-export const getResponseMetrics = (status: number, elapsedMs?: number) => {
- const index = Math.floor(status / 100);
- return ResponseCodeMetrics.flatMap((metric, i) =>
- Optional.from(i)
- .filter((i) => i === index)
- .map(() => [metric.count.withValue(1.0)])
- .flatMap((metricValues) =>
- Optional.from(elapsedMs)
- .map((ms) => metricValues.concat(metric.time.withValue(ms)))
- .orSome(() => metricValues),
- )
- .orSome(() => [metric.count.withValue(0.0)])
- .get(),
- );
-};
-
-export class PenguenoResponse implements BaseResponse {
- public readonly statusText: string;
- public readonly status: number;
- public readonly headers: Record<string, string>;
-
- constructor(
- req: ITraceable<PenguenoRequest, ServerTrace>,
- private readonly _body: Body,
- opts: ResponseOpts,
- ) {
- this.headers = getHeaders(req.get(), opts?.headers ?? {});
- this.status = opts.status;
- this.statusText = opts.statusText ?? HttpStatusCodes[this.status]!;
-
- req.trace.trace(getResponseMetrics(opts.status, req.get().elapsedTimeMs()));
- }
-
- public body() {
- return this._body;
- }
-}