@caido-utils/backend 1.8.1 → 1.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/http/index.d.ts +1 -1
- package/dist/http/index.js +1 -7
- package/dist/index.d.ts +5 -1
- package/dist/index.js +4 -4
- package/dist/requests/index.d.ts +14 -0
- package/dist/requests/index.js +10 -0
- package/package.json +1 -1
- package/dist/http/helpers/index.d.ts +0 -5
- package/dist/http/helpers/index.js +0 -5
- package/dist/http/helpers/request.d.ts +0 -16
- package/dist/http/helpers/request.js +0 -77
- /package/dist/{http/helpers/headers.d.ts → headers/index.d.ts} +0 -0
- /package/dist/{http/helpers/headers.js → headers/index.js} +0 -0
- /package/dist/http/{helpers/status.d.ts → status/index.d.ts} +0 -0
- /package/dist/http/{helpers/status.js → status/index.js} +0 -0
- /package/dist/{http/helpers/query.d.ts → query/index.d.ts} +0 -0
- /package/dist/{http/helpers/query.js → query/index.js} +0 -0
- /package/dist/{http/helpers/url.d.ts → url/index.d.ts} +0 -0
- /package/dist/{http/helpers/url.js → url/index.js} +0 -0
package/dist/http/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { applyCloseConnection, applyContentLength, checkSignal, HttpClient, RawHttpClient, resolveRedirectUrl, sendRawRequest, waitForUnpause, type BatchCallbacks, type HttpClientOptions, type HttpClientRequest, type HttpClientResponse, type HttpMethod, type RawHttpConfig, type RawHttpSettings, type RawRequest, type RawSendResult, type RedirectPolicy, type Result, type Signal, } from "./client";
|
|
2
|
-
export {
|
|
2
|
+
export { getStatusText } from "./status";
|
package/dist/http/index.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
export { spawnCommand } from "./process";
|
|
2
2
|
export { sha256 } from "./crypto";
|
|
3
3
|
export { resolveFilterQuery } from "./filter";
|
|
4
|
-
export { HttpClient,
|
|
4
|
+
export { HttpClient, RawHttpClient, applyCloseConnection, applyContentLength, checkSignal, getStatusText, resolveRedirectUrl, sendRawRequest, waitForUnpause, type BatchCallbacks, type HttpClientOptions, type HttpClientRequest, type HttpClientResponse, type HttpMethod, type RawHttpConfig, type RawHttpSettings, type RawRequest, type RawSendResult, type RedirectPolicy, type Result, type Signal, } from "./http";
|
|
5
5
|
export { JobManager, WorkerPool } from "./jobs";
|
|
6
6
|
export type { Job, JobSignal, JobStatus } from "./jobs";
|
|
7
7
|
export { Queue } from "./pool";
|
|
8
8
|
export type { PoolCallbacks, PoolConfig } from "./pool";
|
|
9
|
+
export { filterAuthHeaders } from "./headers";
|
|
9
10
|
export { getProjectId } from "./project";
|
|
11
|
+
export { queryRequests, type QueryRequestsOptions } from "./query";
|
|
12
|
+
export { parseUrl } from "./url";
|
|
13
|
+
export { getRequestResponse, type RequestResponseData } from "./requests";
|
|
10
14
|
export { deleteFile, fileExists, readFile, storeFile } from "./storage";
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,20 @@ export { sha256 } from "./crypto/index.js";
|
|
|
3
3
|
export { resolveFilterQuery } from "./filter/index.js";
|
|
4
4
|
export {
|
|
5
5
|
HttpClient,
|
|
6
|
-
HttpRequest,
|
|
7
6
|
RawHttpClient,
|
|
8
7
|
applyCloseConnection,
|
|
9
8
|
applyContentLength,
|
|
10
9
|
checkSignal,
|
|
11
|
-
filterAuthHeaders,
|
|
12
10
|
getStatusText,
|
|
13
|
-
parseUrl,
|
|
14
|
-
queryRequests,
|
|
15
11
|
resolveRedirectUrl,
|
|
16
12
|
sendRawRequest,
|
|
17
13
|
waitForUnpause
|
|
18
14
|
} from "./http/index.js";
|
|
19
15
|
export { JobManager, WorkerPool } from "./jobs/index.js";
|
|
20
16
|
export { Queue } from "./pool/index.js";
|
|
17
|
+
export { filterAuthHeaders } from "./headers/index.js";
|
|
21
18
|
export { getProjectId } from "./project/index.js";
|
|
19
|
+
export { queryRequests } from "./query/index.js";
|
|
20
|
+
export { parseUrl } from "./url/index.js";
|
|
21
|
+
export { getRequestResponse } from "./requests/index.js";
|
|
22
22
|
export { deleteFile, fileExists, readFile, storeFile } from "./storage/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RequestResponseData = {
|
|
2
|
+
request: string | undefined;
|
|
3
|
+
response: string | undefined;
|
|
4
|
+
url: string | undefined;
|
|
5
|
+
headers: Record<string, string[]> | undefined;
|
|
6
|
+
};
|
|
7
|
+
type RequestResponseOptions = {
|
|
8
|
+
request?: boolean;
|
|
9
|
+
response?: boolean;
|
|
10
|
+
url?: boolean;
|
|
11
|
+
headers?: boolean;
|
|
12
|
+
};
|
|
13
|
+
export declare function getRequestResponse(sdk: any, caidoId: string, options?: RequestResponseOptions): Promise<RequestResponseData | undefined>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export async function getRequestResponse(sdk, caidoId, options) {
|
|
2
|
+
const result = await sdk.requests.get(caidoId);
|
|
3
|
+
if (result === void 0) return void 0;
|
|
4
|
+
return {
|
|
5
|
+
request: options?.request === false ? void 0 : result.request.getRaw().toText(),
|
|
6
|
+
response: options?.response === false ? void 0 : result.response?.getRaw().toText(),
|
|
7
|
+
url: options?.url === false ? void 0 : result.request.getUrl(),
|
|
8
|
+
headers: options?.headers === false ? void 0 : result.request.getHeaders()
|
|
9
|
+
};
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { SDK } from "caido:plugin";
|
|
2
|
-
export type HttpRequestOptions = {
|
|
3
|
-
url: string;
|
|
4
|
-
method?: "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" | "OPTIONS";
|
|
5
|
-
headers?: Record<string, string> | Array<{
|
|
6
|
-
name: string;
|
|
7
|
-
value: string;
|
|
8
|
-
}>;
|
|
9
|
-
body?: string;
|
|
10
|
-
};
|
|
11
|
-
export declare class HttpRequest {
|
|
12
|
-
private sdk;
|
|
13
|
-
private maxRedirects;
|
|
14
|
-
constructor(sdk: SDK, maxRedirects?: number);
|
|
15
|
-
send(options: HttpRequestOptions): Promise<any>;
|
|
16
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { RequestSpec } from "caido:utils";
|
|
2
|
-
import parse from "url-parse";
|
|
3
|
-
const DEFAULT_HEADERS = {
|
|
4
|
-
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36",
|
|
5
|
-
"Sec-Fetch-Site": "same-origin",
|
|
6
|
-
"Sec-Fetch-Mode": "navigate",
|
|
7
|
-
"Sec-Fetch-User": "?1",
|
|
8
|
-
"Sec-Fetch-Dest": "document"
|
|
9
|
-
};
|
|
10
|
-
function normalizeHeaders(headers) {
|
|
11
|
-
if (headers === void 0) {
|
|
12
|
-
return {};
|
|
13
|
-
}
|
|
14
|
-
if (Array.isArray(headers)) {
|
|
15
|
-
return headers.reduce(
|
|
16
|
-
(acc, { name, value }) => {
|
|
17
|
-
acc[name] = value;
|
|
18
|
-
return acc;
|
|
19
|
-
},
|
|
20
|
-
{}
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
return headers;
|
|
24
|
-
}
|
|
25
|
-
function resolveRedirectUrl(currentUrl, location) {
|
|
26
|
-
if (location.startsWith("http://") || location.startsWith("https://")) {
|
|
27
|
-
return location;
|
|
28
|
-
}
|
|
29
|
-
const parsed = parse(currentUrl);
|
|
30
|
-
if (location.startsWith("/")) {
|
|
31
|
-
return `${parsed.protocol}//${parsed.host}${location}`;
|
|
32
|
-
}
|
|
33
|
-
const basePath = parsed.pathname.substring(
|
|
34
|
-
0,
|
|
35
|
-
parsed.pathname.lastIndexOf("/") + 1
|
|
36
|
-
);
|
|
37
|
-
return `${parsed.protocol}//${parsed.host}${basePath}${location}`;
|
|
38
|
-
}
|
|
39
|
-
export class HttpRequest {
|
|
40
|
-
sdk;
|
|
41
|
-
maxRedirects;
|
|
42
|
-
constructor(sdk, maxRedirects = 5) {
|
|
43
|
-
this.sdk = sdk;
|
|
44
|
-
this.maxRedirects = maxRedirects;
|
|
45
|
-
}
|
|
46
|
-
async send(options) {
|
|
47
|
-
let currentUrl = options.url;
|
|
48
|
-
let redirectCount = 0;
|
|
49
|
-
while (redirectCount <= this.maxRedirects) {
|
|
50
|
-
const spec = new RequestSpec(currentUrl);
|
|
51
|
-
if (options.method !== void 0) {
|
|
52
|
-
spec.setMethod(options.method);
|
|
53
|
-
}
|
|
54
|
-
const normalizedHeaders = normalizeHeaders(options.headers);
|
|
55
|
-
const headers = { ...DEFAULT_HEADERS, ...normalizedHeaders };
|
|
56
|
-
for (const [name, value] of Object.entries(headers)) {
|
|
57
|
-
spec.setHeader(name, value);
|
|
58
|
-
}
|
|
59
|
-
if (options.body !== void 0) {
|
|
60
|
-
spec.setBody(options.body);
|
|
61
|
-
}
|
|
62
|
-
const result = await this.sdk.requests.send(spec);
|
|
63
|
-
const statusCode = result.response.getCode();
|
|
64
|
-
if ([301, 302, 303, 307, 308].includes(statusCode)) {
|
|
65
|
-
const locationHeader = result.response.getHeader("Location");
|
|
66
|
-
if (!locationHeader) {
|
|
67
|
-
return result;
|
|
68
|
-
}
|
|
69
|
-
currentUrl = resolveRedirectUrl(currentUrl, locationHeader.toString());
|
|
70
|
-
redirectCount++;
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
return result;
|
|
74
|
-
}
|
|
75
|
-
throw new Error(`Too many redirects (max: ${this.maxRedirects})`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|