This commit is contained in:
libr
2026-03-03 10:12:22 +08:00
commit ae4c58e56d
223 changed files with 42635 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
import type { HttpClient } from "@lbr77/anisette-js"
import { initLibcurl, libcurl } from "./anisette-libcurl-init"
export class LibcurlHttpClient implements HttpClient {
async get(url: string, headers: Record<string, string>): Promise<Uint8Array> {
await initLibcurl()
const response = await libcurl.fetch(url, {
method: "GET",
headers,
insecure: true,
_libcurl_http_version: 1.1,
})
if (!response.ok) {
throw new Error(`HTTP GET ${url} failed: ${response.status} ${response.statusText}`)
}
return new Uint8Array(await response.arrayBuffer())
}
async post(url: string, body: string, headers: Record<string, string>): Promise<Uint8Array> {
await initLibcurl()
const response = await libcurl.fetch(url, {
method: "POST",
body,
headers,
insecure: true,
_libcurl_http_version: 1.1,
})
if (!response.ok) {
throw new Error(`HTTP POST ${url} failed: ${response.status} ${response.statusText}`)
}
return new Uint8Array(await response.arrayBuffer())
}
}