@scalar/api-client
Version:
the open source API testing client
44 lines (43 loc) • 1.02 kB
JavaScript
import { getCookieHeaderKeys as i } from "./get-cookie-header-keys.js";
const l = ({
harResponse: t,
url: e = "",
method: n,
path: s,
duration: r = 0
}) => {
const o = b(t), { body: d, data: a, size: c } = x(t), u = i(o);
return {
...new Response(d, {
status: t.status,
statusText: t.statusText,
headers: o
}),
headers: Object.fromEntries(o.entries()),
cookieHeaderKeys: u,
duration: r,
status: t.status,
statusText: t.statusText,
method: n,
path: s,
data: a,
size: c,
url: e
};
}, b = (t) => {
const e = new Headers();
return t.headers.forEach(({ name: n, value: s }) => {
e.append(n, s);
}), e;
}, x = (t) => {
if (!t.content.text)
return { body: null, data: "", size: 0 };
const { text: e, encoding: n } = t.content;
if (n)
return { body: null, data: e, size: e.length };
const s = new TextEncoder().encode(e).buffer;
return { body: s, data: e, size: s.byteLength };
};
export {
l as harToFetchResponse
};