MCPcopy Create free account
hub / github.com/PIKACHUIM/CFWorkerACME / HttpClient

Class HttpClient

src/http.js:26–326  ·  view source on GitHub ↗

* ACME HTTP client * * @class * @param {string} directoryUrl ACME directory URL * @param {buffer} accountKey PEM encoded account private key * @param {object} [opts.externalAccountBinding] * @param {string} [opts.externalAccountBinding.kid] External account binding KID * @param {string} [opts

Source from the content-addressed store, hash-verified

24 */
25
26class HttpClient {
27 constructor(directoryUrl, accountKey, externalAccountBinding = {}) {
28 this.directoryUrl = directoryUrl;
29 this.accountKey = accountKey;
30 this.externalAccountBinding = externalAccountBinding;
31
32 this.maxBadNonceRetries = 5;
33 this.jwk = null;
34
35 this.directoryCache = null;
36 this.directoryMaxAge = 86400;
37 this.directoryTimestamp = 0;
38 }
39
40 /**
41 * HTTP request
42 *
43 * @param {string} url HTTP URL
44 * @param {string} method HTTP method
45 * @param {object} [opts] Request options
46 * @returns {Promise<object>} HTTP response
47 */
48
49 async request(url, method, opts = {}) {
50 opts.url = url;
51 opts.method = method;
52 opts.validateStatus = null;
53 console.log("Request URL: " + opts.url)
54 /* Headers */
55 if (typeof opts.headers === 'undefined') {
56 opts.headers = {};
57 }
58
59 opts.headers['Content-Type'] = 'application/jose+json';
60
61 /* Request */
62 log(`HTTP request: ${method} ${url}`);
63 // const resp = await axios.request(opts);
64 let resp = await xior.request(opts);
65 const headers = {};
66 for (const [key, value] of resp.headers) {
67 headers[key] = value;
68 }
69 resp.headers = headers
70
71 log(`RESP ${resp.status} ${method} ${url}`);
72 // return new_resp;
73 return resp;
74 }
75 /**
76 * Get ACME provider directory
77 *
78 * https://datatracker.ietf.org/doc/html/rfc8555#section-7.1.1
79 *
80 * @returns {Promise<object>} ACME directory contents
81 */
82
83 async getDirectory() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected