mirror of
https://github.com/lbr77/SideImpactor.git
synced 2026-05-06 11:14:01 -04:00
init
This commit is contained in:
39
frontend/src/anisette-libcurl-http.ts
Normal file
39
frontend/src/anisette-libcurl-http.ts
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user