The body of a Request or Response.
Calling to<FORMAT> will try to convert the body to the desired format.
new Body(
data:string|number[] |Uint8Array):Body
| Parameter | Type |
|---|---|
data |
string | number[] | Uint8Array |
readonlylength:number
The length of the body in bytes.
toJson():
unknown
Try to parse the body as JSON.
unknown
If the body is not valid JSON.
toRaw():
Uint8Array
Get the raw body as an array of bytes.
Uint8Array
toText():
string
Parse the body as a string.
Unprintable characters will be replaced with �.
string
A mutable Request that has not yet been sent.
new RequestSpec(
url:string):RequestSpec
Build a new RequestSpec from a URL string. We try to infer as much information as possible from the URL, including the scheme, host, path and query.
You can convert a saved immutable Request object into a RequestSpec object by using the toSpec() method.
By default:
- Method is
GET. - Path is
/.
| Parameter | Type |
|---|---|
url |
string |
If the URL is invalid.
const spec = new RequestSpec("https://example.com");getBody():
Body|undefined
The body of the request.
Body | undefined
getHeader(
name:string|GetHeaderOptions):string[] |undefined
Get a header value.
Header name is case-insensitive. The header might have multiple values.
| Parameter | Type |
|---|---|
name |
string | GetHeaderOptions |
string[] | undefined
getHeaders():
Record<string,string[]>
The headers of the request.
Header names are case-insensitive. Each header might have multiple values.
Record<string, string[]>
{
"Host": ["caido.io"],
"Connection": ["keep-alive"],
"Content-Length": ["95"]
}getHost():
string
Get the host of the request.
string
getInfo():
ConnectionInfo
Get the connection information of the request.
The connection information.
getMethod():
string
Get the HTTP method of the request.
Get the raw version by passing { raw: true } in the options.
string
getMethod(
options:RawOption):Uint8Array
Get the HTTP method of the request.
Get the raw version by passing { raw: true } in the options.
| Parameter | Type |
|---|---|
options |
RawOption |
Uint8Array
getPath():
string
Get the path of the request.
Get the raw version by passing { raw: true } in the options.
string
getPath(
options:RawOption):Uint8Array
Get the path of the request.
Get the raw version by passing { raw: true } in the options.
| Parameter | Type |
|---|---|
options |
RawOption |
Uint8Array
getPort():
number
Get the port of the request.
number
getQuery():
string
Get the unparsed query of the request.
Get the raw version by passing { raw: true } in the options.
Excludes the leading ?.
string
getQuery(
options:RawOption):Uint8Array
Get the unparsed query of the request.
Get the raw version by passing { raw: true } in the options.
Excludes the leading ?.
| Parameter | Type |
|---|---|
options |
RawOption |
Uint8Array
getRaw():
RequestSpecRaw
This methods converts the RequestSpec to a RequestSpecRaw.
This is useful to retrieve the raw bytes of the request.
const spec = new RequestSpec("https://example.com");
const specRaw = spec.getRaw();
const bytes = specRaw.getRaw(); // GET / HTTP/1.1\r\nHost: example.com\r\n\r\ngetTls():
boolean
Get if the request uses TLS (HTTPS).
boolean
getUrl():
string
The full URL of the request.
string
removeHeader(
name:string):void
Removes a header.
| Parameter | Type |
|---|---|
name |
string |
void
setBody(
body:Bytes|Body,options?:SetBodyOptions):void
Set the body of the request.
The body can either be a Body or any type that can be converted to Bytes.
| Parameter | Type |
|---|---|
body |
Bytes | Body |
options? |
SetBodyOptions |
void
const body = new Body("Hello world.");
const options = { updateContentLength: true };
request.setBody(body, options);setHeader(
name:string,value:string):void
Set a header value.
This will overwrite any existing values.
| Parameter | Type |
|---|---|
name |
string |
value |
string |
void
setHost(
host:string):void
Set the host of the request.
It will also update the Host header.
| Parameter | Type |
|---|---|
host |
string |
void
setMethod(
method:Bytes):void
Set the HTTP method of the request.
All strings are accepted.
| Parameter | Type |
|---|---|
method |
Bytes |
void
setPath(
path:Bytes):void
Set the path of the request.
| Parameter | Type |
|---|---|
path |
Bytes |
void
setPort(
port:number):void
Set the port of the request.
The port number must be between 1 and 65535.
| Parameter | Type |
|---|---|
port |
number |
void
setQuery(
query:Bytes):void
Set the unparsed query of the request.
The query string should not include the leading ?.
| Parameter | Type |
|---|---|
query |
Bytes |
void
spec.setQuery("q=hello");setRaw(
raw:Bytes):RequestSpecRaw
This method sets the raw Bytes of the request and converts it to a RequestSpecRaw.
This is useful when you have a prepared RequestSpec and you just want to modify the raw data.
| Parameter | Type |
|---|---|
raw |
Bytes |
const rawBytes = []; // RAW BYTES HERE
const request = new RequestSpec("https://example.com");
const rawRequest = request.setRaw(rawBytes);setTls(
tls:boolean):void
Set if the request uses TLS (HTTPS).
| Parameter | Type |
|---|---|
tls |
boolean |
void
staticparse(bytes:Bytes):RequestSpec
Parses raw bytes into a RequestSpec.
| Parameter | Type |
|---|---|
bytes |
Bytes |
If the bytes are not a valid HTTP request.
const rawInput = 'GET / HTTP/1.1\r\nHost: example.com\r\n\r\n';
const spec = RequestSpec.parse(rawInput);
spec.setHeader('x-caido', 'test');
const specRaw = spec.getRaw();
const rawOutput = specRaw.getRaw(); // Will contain the new header
staticparse(raw:RequestSpecRaw):RequestSpec
Parses the raw bytes of a RequestSpecRaw into a RequestSpec.
| Parameter | Type |
|---|---|
raw |
RequestSpecRaw |
If the bytes are not a valid HTTP request.
A mutable raw Request that has not yet been sent.
new RequestSpecRaw(
url:string):RequestSpecRaw
Build a new RequestSpecRaw from a URL string. Only the host, port and scheme will be parsed.
You can convert a saved immutable Request object into a RequestSpecRaw object by using the toSpecRaw() method.
You MUST use setRaw to set the raw bytes of the request.
| Parameter | Type |
|---|---|
url |
string |
const spec = new RequestSpecRaw("https://example.com");getHost():
string
Get the host of the request.
string
getInfo():
ConnectionInfo
Get the connection information of the request.
The connection information.
getPort():
number
Get the port of the request.
number
getRaw():
Uint8Array
Get the raw bytes of the request.
Uint8Array
getSpec():
RequestSpec
This methods converts the RequestSpecRaw to a RequestSpec.
Use toSpec instead.
If the bytes are not a valid HTTP request.
getTls():
boolean
Get if the request uses TLS (HTTPS).
boolean
setHost(
host:string):void
Set the host of the request.
It will NOT update the Host header.
| Parameter | Type |
|---|---|
host |
string |
void
setPort(
port:number):void
Set the port of the request.
The port number must be between 1 and 65535.
| Parameter | Type |
|---|---|
port |
number |
void
setRaw(
raw:Bytes):void
Set the raw Bytes of the request.
| Parameter | Type |
|---|---|
raw |
Bytes |
void
setTls(
tls:boolean):void
Set if the request uses TLS (HTTPS).
| Parameter | Type |
|---|---|
tls |
boolean |
void
toSpec():
RequestSpec
This methods converts the RequestSpecRaw to a RequestSpec.
If the bytes are not a valid HTTP request.
GetHeaderOptions =
object
Options for getting a header value.
name:
string
The name of the header to get. Header name is case-insensitive.
optionalsplit:boolean
Whether to split the header value on commas.
falseRequest =
object
An immutable saved Request.
To modify, use toSpec to get a RequestSpec object.
getBody():
Body|undefined
The body of the request.
Body | undefined
getCreatedAt():
Date
The datetime the request was recorded by the proxy.
Date
getHeader(
name:string|GetHeaderOptions):string[] |undefined
Get a header value.
Header name is case-insensitive. The header might have multiple values.
| Parameter | Type |
|---|---|
name |
string | GetHeaderOptions |
string[] | undefined
getHeaders():
Record<string,string[]>
The headers of the request.
Header names are case-insensitive. Each header might have multiple values.
Record<string, string[]>
{
"Host": ["caido.io"],
"Connection": ["keep-alive"],
"Content-Length": ["95"]
}getHost():
string
The target host of the request.
string
getId():
ID
The unique Caido ID of the request.
getMethod():
string
The HTTP method of the request.
string
getPath():
string
The path of the request.
string
getPort():
number
The target port of the request.
number
getQuery():
string
The unparsed query of the request.
Excludes the leading ?.
string
getRaw():
RequestRaw
The raw version of the request.
Used to access the bytes directly.
getTls():
boolean
If the request uses TLS (HTTPS).
boolean
getUrl():
string
The full URL of the request.
string
toSpec():
RequestSpec
Copied the request to a mutable un-saved RequestSpec. This enables you to make modify a request before re-sending it.
toSpecRaw():
RequestSpecRaw
Copied the request to a mutable un-saved RequestSpecRaw. The raw requests are not parsed and can be used to send invalid HTTP Requests.
RequestOrderField =
"ext"|"host"|"id"|"method"|"path"|"query"|"created_at"|"source"
Field to order requests by.
RequestRaw =
object
An immutable saved raw Request.
toBytes():
Uint8Array
Get the raw request as an array of bytes.
Uint8Array
toText():
string
Parse the raw request as a string.
Unprintable characters will be replaced with �.
string
RequestResponse =
object
An immutable saved Request and Response pair.
request:
Request
response:
Response
RequestResponseOpt =
object
An immutable saved Request and optional Response pair.
request:
Request
optionalresponse:Response
RequestsConnection =
object
A connection of requests.
items:
RequestsConnectionItem[]
pageInfo:
PageInfo
RequestsConnectionItem =
object
An item in a connection of requests.
cursor:
Cursor
request:
Request
optionalresponse:Response
RequestSendOptions =
object
Options for sending a request.
optionalconnection:Connection
The Connection to use for the request.
If provided, the request will be sent through the connection.
If not provided, the engine will open a new connection to the target.
undefined
optionalplugins:boolean
If true, the request will be sent through the upstream plugins.
It defaults to to true most of the time except when called from
a onUpstream callback.
true
optionalsave:boolean
If true, the request and response will be saved to the database and the user will see them in the Search tab.
If you do not save, the request and response IDs will be set to 0.
true
optionaltimeouts:RequestSendTimeouts|number
The timeouts to use for sending a request and receiving a response.
If a number is provided, it will be used as the global timeout and the other timeouts will be set to infinity.
See the RequestSendTimeouts for the default values.
RequestSendPayload =
RequestResponse&object
A saved Request and Response pair with the connection used to send the request.
connection:
Connection
RequestSendTimeouts =
object
Timeouts for sending a request and receiving a response.
optionalconnect:number
The timeout to open the TCP connection to the target host and perform the TLS handshake.
Defaults to 30s.
optionalextra:number
The timeout to read data after we have a read the full response.
This is useful if you believe the server will send more data than implied by the Content-Length header.
Defaults to 0s (no timeout).
optionalglobal:number
The global timeout for sending a request and receiving a response.
No default value.
optionalpartial:number
The timeout between each read attempt for the response. On a slow connection, this is important to increase.
Defaults to 5s.
optionalresponse:number
The timeout to receive the first byte of the response.
After the first byte is received, the partial timeout will be used.
Defaults to 30s.
RequestsQuery =
object
Query builder to fetch requests.
after(
cursor:Cursor):RequestsQuery
Requests after a given cursor.
| Parameter | Type | Description |
|---|---|---|
cursor |
Cursor |
Cursor of the request |
ascending(
target:"req",field:RequestOrderField):RequestsQuery
Ascending ordering.
| Parameter | Type | Description |
|---|---|---|
target |
"req" |
Target of the ordering: req or resp. |
field |
RequestOrderField |
Field to order by. |
ascending(
target:"resp",field:ResponseOrderField):RequestsQuery
| Parameter | Type |
|---|---|
target |
"resp" |
field |
ResponseOrderField |
before(
cursor:Cursor):RequestsQuery
Requests before a given cursor.
| Parameter | Type | Description |
|---|---|---|
cursor |
Cursor |
Cursor of the request |
descending(
target:"req",field:RequestOrderField):RequestsQuery
Descending ordering.
| Parameter | Type | Description |
|---|---|---|
target |
"req" |
Target of the ordering: req or resp. |
field |
RequestOrderField |
Field to order by. |
descending(
target:"resp",field:ResponseOrderField):RequestsQuery
| Parameter | Type |
|---|---|
target |
"resp" |
field |
ResponseOrderField |
execute():
Promise<RequestsConnection>
Execute the query.
Promise<RequestsConnection>
If a query parameter is invalid or the query cannot be executed.
filter(
filter:string):RequestsQuery
Filter requests.
| Parameter | Type | Description |
|---|---|---|
filter |
string |
HTTPQL filter |
first(
n:number):RequestsQuery
First n requests.
| Parameter | Type | Description |
|---|---|---|
n |
number |
Number of requests to return |
last(
n:number):RequestsQuery
Last n requests.
| Parameter | Type | Description |
|---|---|---|
n |
number |
Number of requests to return |
RequestsSDK =
object
The SDK for the Requests service.
get(
id:ID):Promise<RequestResponseOpt|undefined>
Get a request by its unique ID.
| Parameter | Type |
|---|---|
id |
ID |
Promise<RequestResponseOpt | undefined>
await sdk.requests.get("1");inScope(
request:RequestSpec|Request,scopes?:Scope[] |ID[]):boolean
Checks if a request is in scope.
| Parameter | Type | Description |
|---|---|---|
request |
RequestSpec | Request |
The request to check |
scopes? |
Scope[] | ID[] |
Optional scopes or scope IDs to check against. If not provided, checks against the default scope. |
boolean
True if the request is in scope
// Check against default scope
if (sdk.requests.inScope(request)) {
sdk.console.log("In scope");
}
// Check against specific scopes
const isInScope = sdk.requests.inScope(request, [scope1, scope2]);
sdk.console.log(isInScope); // true or falsematches(
filter:string,request:Request,response?:Response):boolean
Checks if a request/response matches an HTTPQL filter.
| Parameter | Type | Description |
|---|---|---|
filter |
string |
HTTPQL filter |
request |
Request |
The Request to match against |
response? |
Response |
The Response to match against |
boolean
query():
RequestsQuery
Query requests of the current project.
const page = await sqk.requests.query().first(2).execute();
sdk.console.log(`ID: ${page.items[1].request.getId()}`);send(
request:RequestSpec|RequestSpecRaw,options?:RequestSendOptions):Promise<RequestSendPayload>
Sends an HTTP request, either a RequestSpec or RequestSpecRaw.
This respects the upstream proxy settings.
| Parameter | Type |
|---|---|
request |
RequestSpec | RequestSpecRaw |
options? |
RequestSendOptions |
Promise<RequestSendPayload>
If the request cannot be sent. If the request times out, the error message will contain the word "Timeout".
const spec = new RequestSpec("https://example.com");
try {
const res = await sdk.requests.send(request)
sdk.console.log(res.request.getId());
sdk.console.log(res.response.getCode());
} catch (err) {
sdk.console.error(err);
}Response =
object
An immutable saved Response.
getBody():
Body|undefined
The body of the response
Body | undefined
getCode():
number
The status code of the response.
number
getCreatedAt():
Date
The datetime the response was recorded by the proxy.
Date
getHeader(
name:string|GetHeaderOptions):string[] |undefined
Get a header value.
Header name is case-insensitive. The header might have multiple values.
| Parameter | Type |
|---|---|
name |
string | GetHeaderOptions |
string[] | undefined
getHeaders():
Record<string,string[]>
The headers of the response.
Header names are case-insensitive. Each header might have multiple values.
Record<string, string[]>
{
"Date": ["Sun, 26 May 2024 10:59:21 GMT"],
"Content-Type": ["text/html"]
}getId():
ID
The unique Caido ID of the response.
getRaw():
ResponseRaw
The raw version of the response.
Used to access the bytes directly.
getRoundtripTime():
number
The time it took to send the request and receive the response in milliseconds.
number
ResponseOrderField =
"length"|"roundtrip"|"code"
Field to order responses by.
ResponseRaw =
object
An immutable saved raw Response.
toBytes():
Uint8Array
Get the raw response as an array of bytes.
Uint8Array
toText():
string
Parse the raw response as a string.
Unprintable characters will be replaced with �.
string
SetBodyOptions =
object
Options when setting the body of a Request.
updateContentLength:
boolean
Should update the Content-export type header.
true