### Advanced Repeat Configuration Example
Source: https://reqable.com/en-US/docs/capture/repeat
An example scenario illustrating how iterations, delay, and interval settings affect the timing of repeated requests.
```text
Jack set a replay request https://www.test.com/get at 13:00:00,
Iterations is 3 times, the delay is 3000ms, and the interval is 10000ms.
The time point of sending the first request is 13:00:03, with a delay of 3s.
The time point of sending the second request is 13:00:13, which is 10s after the previous request.
The time point when the third request is sent is 13:00:23, which is 20s after the first request starts.
```
--------------------------------
### Install Reqable on Linux via APT
Source: https://reqable.com/en-US/docs/getting-started
Install the Reqable deb package on x64 Linux systems using the apt package manager. Ensure the GTK library is installed prior to execution.
```bash
sudo apt install reqable-app-linux-x86_64.deb
```
--------------------------------
### Redirection URL Example
Source: https://reqable.com/en-US/docs/capture/rewrite
Example of how a source URL is transformed into a new destination URL using directory matching.
```text
https://hello.com/foo/bar/ok?abc=123
```
```text
https://world.com/new/*
```
```text
https://world.com/new/foo/bar/ok?abc=123
```
--------------------------------
### Install Reqable on macOS via Homebrew
Source: https://reqable.com/en-US/docs/getting-started
Use this command to install the Reqable application on macOS systems using the Homebrew package manager.
```bash
brew install reqable
```
--------------------------------
### Mapping Localhost to an Alias
Source: https://reqable.com/en-US/docs/capture/localhost
Example of replacing localhost with an alias for traffic capture.
```text
Old link: http://localhost:3000/
New link: http://go:3000/
```
--------------------------------
### Access App Information
Source: https://reqable.com/en-US/docs/capture/addons
Retrieve application metadata including name, unique ID, and installation path.
```python
def onRequest(context, response):
# Print app information
print(context.app.name)
print(context.app.id)
print(context.app.path)
# Done
return request
```
--------------------------------
### Example Request ID
Source: https://reqable.com/en-US/docs/rest/request_id
A sample value representing a generated Request ID.
```text
reqable-id-aee9bdc1-ad01-11ed-ace8-ade55d424a3d
```
--------------------------------
### Example Request URL for Modification
Source: https://reqable.com/en-US/docs/capture/rewrite
A sample URL used to demonstrate modifying query parameters via rewrite rules.
```text
https://reqable.com?key=12345&foo=bar&hello=world
```
--------------------------------
### Match URL patterns
Source: https://reqable.com/en-US/docs/tools/regex
Matches URLs starting with http or https followed by non-whitespace characters.
```regex
https?://[^\s]+
```
--------------------------------
### SSL Proxying Wildcard Domain Matching
Source: https://reqable.com/en-US/docs/capture/ssl
Example of domain patterns matched by the wildcard rule *.apple.com.
```text
https://www.apple.com/
https://api.apple.com/
```
--------------------------------
### Urlencode Request Body Format
Source: https://reqable.com/en-US/docs/rest/body
Example of the key-value pair format used for Urlencode request bodies.
```text
foo=bar&hello=reqable
```
--------------------------------
### Non-Capturing Group Example
Source: https://reqable.com/en-US/docs/tools/regex
Groups patterns for alternation without creating a capture group.
```regex
(?:http|https)
```
--------------------------------
### Sign request parameters with MD5
Source: https://reqable.com/en-US/docs/capture/addons
Shows how to sort query parameters and generate an MD5 signature to include in request headers.
```python
from reqable import *
import hashlib
def onRequest(context, request):
# Sort the query list
queries = sorted(request.queries)
# Concat the query parameters
text = queries.concat()
# Sign using the md5 algorithm
algorithm = hashlib.md5()
algorithm.update(text.encode(encoding='UTF-8'))
signature = algorithm.hexdigest()
# The signature is added to the request header
request.headers['signature'] = signature
# Done
return request
def onResponse(context, response):
# Done
return response
```
--------------------------------
### Accessing Context and Environment Variables
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates how to access request metadata, environment variables, and share data between request and response hooks.
```python
def onRequest(context, request):
# Print url, for example: https://reqable.com/
print(context.url)
# Print scheme, for example: https
print(context.scheme)
# Print host, for example: reqable.com
print(context.host)
# Print port number, for example: 443
print(context.port)
# Print connection ID, for example: 1
print(context.cid)
# Print TCP connection timestamp, for example: 1686711219444
print(context.ctime)
# Print HTTP session ID, for example: 1
print(context.sid)
# Print HTTP session start timestamp, for example: 1686711224132
print(context.stime)
# Get an environment variable
print(context.env['foo'])
print(context.env['$timestamp'])
# Write an environment variable
# The currently activated custom environment is written first, and if there is no activated environment, the global environment is written.
context.env['foo'] = 'bar'
# Set shared value
context.shared = 'Hello'
# Done
return request
def onResponse(context, response):
# Print shared value, output: Hello
print(context.shared)
return response
```
--------------------------------
### Locate Reqable log files
Source: https://reqable.com/en-US/docs/faq/windows
The default path for Reqable log files on Windows.
```text
C:\Users\xxx\AppData\Roaming\Reqable\log
```
--------------------------------
### Create Network Security Configuration
Source: https://reqable.com/en-US/docs/getting-started/installation
Define a network security configuration file to allow trust for both system and user certificates.
```xml
```
--------------------------------
### Match a URL
Source: https://reqable.com/en-US/docs/tools/regex
Matches HTTP or HTTPS links until a delimiter is reached.
```regex
https?://[^\s"'<>]+
```
--------------------------------
### Locate Reqable cache directory
Source: https://reqable.com/en-US/docs/faq/windows
The default path for Reqable cache files on Windows.
```text
C:\Users\xxx\AppData\Roaming\Reqable
```
--------------------------------
### Match a Domain Name
Source: https://reqable.com/en-US/docs/tools/regex
Matches standard domain name formats.
```regex
^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
```
--------------------------------
### Match HTTP Methods
Source: https://reqable.com/en-US/docs/tools/regex
Matches standard HTTP request methods.
```regex
^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)$
```
--------------------------------
### URL Pattern Matching with Groups
Source: https://reqable.com/en-US/docs/tools/regex
Uses capturing groups to extract protocol, hostname, and path components from a URL.
```regex
(https?)://([^/\s]+)(/[^\s]*)?
```
--------------------------------
### Match an Email Address
Source: https://reqable.com/en-US/docs/tools/regex
Matches standard email address formats.
```regex
[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}
```
--------------------------------
### Key-Value Replacement Pattern
Source: https://reqable.com/en-US/docs/tools/regex
Demonstrates capturing a numeric value and using it in a replacement string.
```text
key=12345
```
```text
key=api-$1
```
```regex
key=(\d+)
```
```text
key=api-12345
```
--------------------------------
### Locate Reqable log files
Source: https://reqable.com/en-US/docs/faq/linux
The default directory where Reqable stores application logs on Linux.
```text
~/.local/share/reqable/log
```
--------------------------------
### Manipulate Request Query Parameters
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates common operations such as counting, iterating, adding, removing, and retrieving query parameters.
```python
def onRequest(context, request):
# Print the count of query parameters
print(len(request.queries))
# Iterate the query parameters
for query in request.queries:
print(query)
# Add a new query
request.queries.add('foo', 'bar')
# Remove the query named `foo`
request.queries.remove('foo')
# Remove all query parameters
request.queries.clear()
# Update the query parameter, if it does not exist, it will be added automatically.
request.queries['foo'] = 'bar'
# Print the query value, for example: bar
print(request.queries['foo'])
# Print the query name and value at the specified index position, for example: (foo, bar)
print(request.queries[0])
# Print the concatenated query string, such as: foo=bar&hello=world
print(request.queries.concat())
# Print the concatenated query string(URL encoded).
print(request.queries.concat(encode=True))
# Done
return request
```
--------------------------------
### App Object
Source: https://reqable.com/en-US/docs/capture/addons
Provides metadata about the application or process associated with the request.
```APIDOC
## App Object
### Properties
- **name** (str) - Name of the app/process.
- **id** (str) - App unique id (e.g., bundleId or packageName). Returns None if not detected.
- **path** (str) - The app installed path.
```
--------------------------------
### Match an Authorization Header
Source: https://reqable.com/en-US/docs/tools/regex
Case-insensitively matches an Authorization header and captures the Bearer token.
```regex
(?i)^Authorization:\s*Bearer\s+(\S+)
```
--------------------------------
### Locate Reqable log files
Source: https://reqable.com/en-US/docs/faq/macos
Path to the directory where Reqable stores application logs on macOS.
```text
~/Library/Application Support/com.reqable.macosx/log
```
--------------------------------
### Manipulating HttpHeaders in a Script
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates common operations on the request headers object, including iteration, modification, and index-based access.
```python
def onRequest(context, request):
# Print the count of headers
print(len(request.headers))
# Iterate the header list
for header in request.headers:
print(header)
# Add a new header
request.headers.add('foo', 'bar')
# Remove the header named `foo`
request.headers.remove('foo')
# Remove all headers
request.headers.clear()
# Update the header, if it does not exist, it will be added automatically.
request.headers['foo'] = 'bar'
# Print the header value, for example: bar
print(request.headers['foo'])
# Print the header at the specified index position, for example: `foo: bar`
print(request.headers[0])
# Done
return request
```
--------------------------------
### Configure AndroidManifest.xml
Source: https://reqable.com/en-US/docs/getting-started/installation
Reference the network security configuration file within the application tag of your AndroidManifest.xml.
```xml
...
```
--------------------------------
### Read and write environment variables in Python scripts
Source: https://reqable.com/en-US/docs/environment/practice
Access environment variables using the context.env dictionary. Changes are applied to the global or active environment based on current activation status.
```python
# Read the variable
print(context.env['username'])
# Write a variable
context.env['username'] = 'reqable'
```
--------------------------------
### Add User Certificate Trust Dependency
Source: https://reqable.com/en-US/docs/getting-started/installation
Include this dependency in your build.gradle file to automatically integrate the network security configuration for debug builds.
```gradle
dependencies {
debugImplementation("com.reqable.android:user-certificate-trust:1.0.0")
}
```
--------------------------------
### Locate Reqable cache directory
Source: https://reqable.com/en-US/docs/faq/linux
The default directory where Reqable stores cached data on Linux.
```text
~/.local/share/reqable
```
--------------------------------
### Match a Phone Number
Source: https://reqable.com/en-US/docs/tools/regex
Matches simplified US phone number formats including optional country codes and separators.
```regex
^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$
```
--------------------------------
### Share data between onRequest and onResponse
Source: https://reqable.com/en-US/docs/capture/script
Demonstrates how to use the shared attribute of the CaptureContext object to pass data between request and response processing functions.
```python
def onRequest(context, request):
context.shared = 'foobar'
return request
def onResponse(context, response):
print(context.shared) # print foobar
return response
```
--------------------------------
### Locate Reqable cache directory
Source: https://reqable.com/en-US/docs/faq/macos
Path to the directory where Reqable stores cache files on macOS.
```text
~/Library/Application Support/com.reqable.macosx
```
--------------------------------
### Network Throttling API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing network throttling profiles.
```APIDOC
## Network Throttling
- capture_network_throttling_get_config: Get the current network throttling configuration.
- capture_network_throttling_set_enabled: Enable or disable network throttling.
- capture_network_throttling_get_active: Get the active network throttling profile.
- capture_network_throttling_lookup: Get network throttling profile details by ID.
- capture_network_throttling_select: Select a network throttling profile by ID.
- capture_network_throttling_create: Create a new network throttling profile.
- capture_network_throttling_delete: Delete one or more network throttling profiles.
- capture_network_throttling_update: Update a network throttling profile.
```
--------------------------------
### Add a Prefix to a Parameter Value
Source: https://reqable.com/en-US/docs/tools/regex
Demonstrates using regex replacement to modify a query parameter value.
```text
key=12345&foo=bar
```
```regex
key=([^&]*)
```
```regex
key=api-$1
```
```text
key=api-12345&foo=bar
```
--------------------------------
### onRequest(context, request)
Source: https://reqable.com/en-US/docs/capture/addons
The onRequest hook is triggered when a request is captured. It allows access to request metadata via the context object and modification of environment variables.
```APIDOC
## onRequest(context, request)
### Description
This function is called when a request is intercepted. It provides access to the `context` object containing request metadata and environment variables, and the `request` object for modification.
### Parameters
- **context** (Context) - The context object containing request details (url, scheme, host, port, etc.) and environment variables.
- **request** (Request) - The request object to be processed.
### Usage Example
```python
def onRequest(context, request):
print(context.url)
context.env['foo'] = 'bar'
context.shared = 'Hello'
return request
```
```
--------------------------------
### Capture Scripts API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing Python capture script rules and configurations.
```APIDOC
## Capture Scripts
- capture_script_get_config: Get the current capture script configuration.
- capture_script_set_enabled: Enable or disable the capture script feature.
- capture_script_list: List all script rules.
- capture_script_set_item_enabled: Batch enable or disable specific script rules.
- capture_script_get_by_id: Get script details by ID.
- capture_script_create: Create a new Python capture script rule.
- capture_script_create_folder: Create a script folder.
- capture_script_delete: Delete one or more script rules.
- capture_script_delete_folder: Delete one or more script folders.
- capture_script_update: Update a script rule.
- capture_script_update_folder_name: Rename a script folder.
```
--------------------------------
### Request ID Format
Source: https://reqable.com/en-US/docs/rest/request_id
The standard format for the automatically generated Reqable-Id header.
```text
reqable-id-{UUID}
```
--------------------------------
### Access and Modify HttpResponse Properties
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates how to access response attributes like status code, headers, and body, and how to modify the status code within an onResponse hook.
```python
def onResponse(context, response):
# Print request information, for more APIs, please refer to `HttpRequest` above
print(response.request)
# Print response status code, for example: 200
print(response.code)
# Print response status message, for example: OK
print(response.message)
# Print response headers, for example: ['server: Netlify', 'content-length: 6', 'content-type: text/plain']
print(response.headers)
# Print response body payload, for example: {"foo":"bar"}
print(response.body)
# Update status code
response.code = 400
# More examples refer to `onRequest` above, exactly the same.
# Done
return response
```
--------------------------------
### Reverse Proxies API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing reverse proxy rules and folders.
```APIDOC
## Reverse Proxies
- capture_reverse_proxy_get_config: Get the current reverse proxy configuration.
- capture_reverse_proxy_set_enabled: Enable or disable the reverse proxy feature.
- capture_reverse_proxy_list: List all reverse proxy rules.
- capture_reverse_proxy_set_item_enabled: Batch enable or disable specific reverse proxy rules.
- capture_reverse_proxy_lookup: Get reverse proxy details by ID.
- capture_reverse_proxy_create: Create a new reverse proxy rule.
- capture_reverse_proxy_create_folder: Create a reverse proxy folder.
- capture_reverse_proxy_delete: Delete one or more reverse proxies.
- capture_reverse_proxy_delete_folder: Delete one or more reverse proxy folders.
- capture_reverse_proxy_update: Update a reverse proxy rule.
- capture_reverse_proxy_update_folder_name: Rename a reverse proxy folder.
```
--------------------------------
### HttpQueries Interface
Source: https://reqable.com/en-US/docs/capture/addons
Methods available for managing query parameters on an HTTP request object.
```APIDOC
## HttpQueries Interface
### Methods
- **len()** (int) - Returns the count of query parameters.
- **iter()** - Iterate the query parameters.
- **add(name: str, value: str)** - Add a new query parameter.
- **remove(name: str)** - Delete all query parameters with the specified name.
- **clear()** - Delete all query parameters.
- **concat(encode: bool)** (str) - Returns the concatenated complete query string. If encode is True, the string is URL encoded.
- **index(name: str)** (int) - Returns the first index of the query parameter with the specified name.
- **indexes(name: str)** (list) - Returns a list of all indexes matching the specified name.
- **__getitem__(name: str)** (str) - Returns the value of the first query parameter with the specified name, or None if it does not exist.
- **__getitem__(index: int)** (tuple) - Returns the query name and value as a tuple at the specified index.
- **__setitem__(name: str, value: str)** - Updates the value of the first query parameter with the specified name, or adds a new one if it does not exist.
```
--------------------------------
### Match an IP Address
Source: https://reqable.com/en-US/docs/tools/regex
A simplified pattern for matching IPv4 addresses. Does not validate that octets are within the 0-255 range.
```regex
\b\d{1,3}(\.\d{1,3}){3}\b
```
--------------------------------
### Highlight Enum
Source: https://reqable.com/en-US/docs/capture/addons
Defines the available highlight colors and styles for requests within the Reqable interface.
```APIDOC
## Highlight Enum
### Values
- **none** - No highlight
- **red** - Red highlight
- **yellow** - Yellow highlight
- **green** - Green highlight
- **blue** - Blue highlight
- **teal** - Teal highlight
- **strikethrough** - Strike-through highlight
```
--------------------------------
### Set Request Highlight
Source: https://reqable.com/en-US/docs/capture/addons
Apply a visual highlight color to a request using the Highlight enum.
```python
def onRequest(context, request):
# Set request red highlight
context.highlight = Highlight.red
# Done
return request
```
--------------------------------
### Connection Object
Source: https://reqable.com/en-US/docs/capture/addons
Provides access to TCP connection metadata including timestamps and local/remote address information.
```APIDOC
## Connection Object
### Properties
- **id** (int) - Connection id, starts from 0.
- **timestamp** (int) - TCP connection established timestamp, in milliseconds.
- **local** (Address) - The client address.
- **remote** (Address) - The server address.
```
--------------------------------
### Secondary Proxies API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing secondary proxy definitions.
```APIDOC
## Secondary Proxies
- capture_secondary_proxy_get_config: Get the current secondary proxy configuration.
- capture_secondary_proxy_set_enabled: Enable or disable the secondary proxy feature.
- capture_secondary_proxy_get_active: Get the active secondary proxy profile.
- capture_secondary_proxy_lookup: Get secondary proxy details by ID.
- capture_secondary_proxy_select: Select a secondary proxy profile by ID.
- capture_secondary_proxy_create: Create a new secondary proxy definition.
- capture_secondary_proxy_delete: Delete one or more secondary proxy definitions.
- capture_secondary_proxy_update: Update a secondary proxy definition.
```
--------------------------------
### Manipulate HttpRequest properties
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates how to access and modify request attributes including method, path, query parameters, headers, and body content.
```python
def onRequest(context, request):
# Print method, for example: POST
print(request.method)
# Print path, for example: /foo
print(request.path)
# Print query parameters, for example: [('foo', 'bar'), ('hello', 'world')]
print(request.queries)
# Print headers, for example: ['host: reqable.com', 'content-length: 6', 'content-type: text/plain']
print(request.headers)
# Print body payload, for example: {"foo":"bar"}
print(request.body)
# Update request method
request.method = 'GET'
# Update request path
request.path = '/bar'
# Update request parameters, more APIs please refer to `HttpQueries` below.
request.queries['foo'] = 'bar'
# Assign request parameters
request.queries = 'foo=bar&hello=world&abc=123'
request.queries = {
'foo': 'bar',
'hello': 'world',
'abc': '123'
}
# Delete specified request parameters
request.queries.remove('foo')
# Update request headers, more APIs please refer to `HttpHeaders` below.
request.headers['content-type'] = 'application/json'
# Assign request headers
request.headers = [
'content-type: application/json',
'foo: bar'
]
# Delete specified request headers
request.headers.remove('foo')
# Set a text to body
request.body = 'Hello World'
# Set a dictionary to body, it will be automatically converted to JSON
request.body = {
'foo': 'bar',
'abc': 123
}
# Set a binary data to body
request.body = b'\x01\x02\x03\x04'
# Set a file path to body
request.body.file('/User/Reqable/Desktop/test.png')
# JSON body is converted into a dictionary
request.body.jsonify()
# Then manipulate the dictionary to modify the Body
request.body['foo'] = 'bar'
request.body['error'] = {
'code': 1000,
'message': 'Runtime Error'
}
# Done
return request
```
--------------------------------
### Iterate and update multipart body parts
Source: https://reqable.com/en-US/docs/capture/addons
Access individual parts of a multipart body and update them using HttpMultipartBody factory methods.
```python
def onRequest(context, request):
# Iterate parts
for part in request.body:
print(f'name {part.name}')
print(f'filename {part.filename}')
print(f'value {part}')
# Update parts
request.body[0] = HttpMultipartBody.text('Hi World')
request.body[0] = HttpMultipartBody.text('Hi World', name='reqable')
request.body[0] = HttpMultipartBody.file('data/body_binary.bin')
request.body[0] = HttpMultipartBody.file('data/body_binary.bin', name='reqable', filename='test.png')
# Done
return request
```
--------------------------------
### HttpBody Interface
Source: https://reqable.com/en-US/docs/capture/addons
The HttpBody interface provides properties to inspect the body type and methods to set or write body content.
```APIDOC
## HttpBody
### Properties
- **isNone** (bool) - Determine whether it is an empty Body.
- **isText** (bool) - Determine whether it is a string Body.
- **isBinary** (bool) - Determine whether it is a binary Body.
- **isMultipart** (bool) - Determine whether it is a form Body.
- **type** (int) - Returns the type of Body (0: none, 1: text, 2: binary, 3: form).
- **payload** (Polymorphic) - The body payload.
### Methods
- **none()** - Set None to body.
- **text(str)** - Set a text value to body.
- **textFromFile(str)** - Set a file content (text) to body.
- **binary(str or bytes)** - Set binary data to body.
- **file(str)** - Set the file content (binary) to body.
- **multiparts(list)** - Set to forms, the parameter is a list of HttpMultipartBody.
- **writeFile(str)** - Write body payload to a file (form body not supported).
```
--------------------------------
### onResponse(context, response)
Source: https://reqable.com/en-US/docs/capture/addons
The onResponse hook is triggered when a response is received. It allows access to shared data set during the request phase.
```APIDOC
## onResponse(context, response)
### Description
This function is called when a response is received. It allows access to the `context` object, including shared data passed from the `onRequest` hook.
### Parameters
- **context** (Context) - The context object containing session information and shared data.
- **response** (Response) - The response object to be processed.
### Usage Example
```python
def onResponse(context, response):
print(context.shared)
return response
```
```
--------------------------------
### Report Servers API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing report server definitions.
```APIDOC
## Report Servers
- capture_report_server_get_config: Get the current report server configuration.
- capture_report_server_set_enabled: Enable or disable the report server feature.
- capture_report_server_lookup: Get report server details by ID.
- capture_report_server_set_item_enabled: Batch enable or disable specific report server items.
- capture_report_server_create: Create a new report server definition.
- capture_report_server_delete: Delete one or more report server definitions.
- capture_report_server_update: Update a report server definition.
```
--------------------------------
### Access Control API
Source: https://reqable.com/en-US/docs/mcp
Tools for managing access control profiles.
```APIDOC
## Access Control
- capture_access_control_get_config: Get the current access control configuration.
- capture_access_control_set_enabled: Enable or disable access control.
- capture_access_control_get_active: Get the active access control profile.
- capture_access_control_lookup: Get access control details by ID.
- capture_access_control_select: Select an access control profile by ID.
- capture_access_control_create: Create a new access control profile.
- capture_access_control_delete: Delete one or more access control profiles.
- capture_access_control_update: Update an access control profile.
```
--------------------------------
### Access Connection Information
Source: https://reqable.com/en-US/docs/capture/addons
Access connection details such as ID, timestamp, and local/remote address components within the onRequest hook.
```python
def onRequest(context, response):
# Print connection information
print(context.connection.id)
print(context.connection.timestamp)
# Print client address
print(context.connection.local.ip)
print(context.connection.local.port)
# Print server address
print(context.connection.remote.ip)
print(context.connection.remote.port)
# Done
return request
```
--------------------------------
### Address Object
Source: https://reqable.com/en-US/docs/capture/addons
Represents a network address structure used by connection objects.
```APIDOC
## Address Object
### Properties
- **ip** (str) - IPv4 or IPv6 address.
- **port** (int) - TCP/IP port number.
```
--------------------------------
### Alternation Patterns
Source: https://reqable.com/en-US/docs/tools/regex
Matches one of several specified strings using the OR operator.
```regex
GET|POST|PUT
```
```regex
^(GET|POST|PUT)$
```
--------------------------------
### Check HTTP body type and payload
Source: https://reqable.com/en-US/docs/capture/addons
Use these properties to inspect the body type and access the underlying payload data within an onRequest hook.
```python
def onRequest(context, request):
# Judging body type
print(request.body.type)
if request.body.isNone:
print('Http body is none')
elif request.body.isText:
print('Http body is text')
elif request.body.isBinary:
print('Http body is binary')
elif request.body.isMultipart:
print('Http body is multipart')
# Print body type value
print(request.body.type)
# Print body payload
print(request.body.payload)
```
--------------------------------
### Automatically save images
Source: https://reqable.com/en-US/docs/capture/addons
Filters responses by MIME type and saves image payloads to a local directory using a timestamped filename.
```python
from reqable import *
from mimetypes import guess_extension
import datetime
import os
def onRequest(context, request):
return request
def onResponse(context, response):
# Check the Mime type, if it is not an image type, it will be skipped and not processed
mime = response.mime
if mime == None:
return response
maintype, subtype = mime.split('/')
if not maintype == 'image':
return response
# Save the image to the directory, the file name is timestamp, and the suffix is derived according to the mime type
dir = '/Users/megatronking/Downloads/reqable/'
os.makedirs(dir, exist_ok=True)
name = datetime.datetime.now().strftime("%H%M%S%f")
ext = guess_extension(mime)
image = os.path.join(dir, name + ext)
# Write body payload to file
print(f'Saving image {image}')
response.body.writeFile(image)
# Done
return response
```
--------------------------------
### Match literal dot with regex
Source: https://reqable.com/en-US/docs/tools/regex
Escapes a dot character to match a literal period in a string.
```regex
reqable\.com
```
--------------------------------
### HttpMultipartBody Interface
Source: https://reqable.com/en-US/docs/capture/addons
The HttpMultipartBody interface extends HttpBody to handle individual parts of a multipart request.
```APIDOC
## HttpMultipartBody
### Properties
- **headers** (HttpHeaders) - List of headers in the part.
- **name** (str) - Part name.
- **filename** (str) - Part file name.
```
--------------------------------
### HttpHeaders Interface
Source: https://reqable.com/en-US/docs/capture/addons
The HttpHeaders object allows for programmatic access and modification of HTTP headers. It supports standard collection operations like length, iteration, addition, removal, and indexed access.
```APIDOC
## HttpHeaders Interface
### Methods
- **len()** (int) - Returns the count of headers.
- **iter()** - Iterate the headers.
- **add(name: str, value: str)** - Add a new header.
- **remove(name: str)** - Delete all headers with the specified name.
- **clear()** - Delete all headers.
- **index(name: str)** (int) - Query the index of the first header matching the name.
- **indexes(name: str)** (list) - Query a list of all indexes matching the name.
- **__getitem__(name: str)** (str) - Get the value of the first header matching the name, or None if not found.
- **__getitem__(index: int)** (str) - Get header by index.
- **__setitem__(name: str, value: str)** - Update or add a header.
```
--------------------------------
### Modify HTTP request body content
Source: https://reqable.com/en-US/docs/capture/addons
Use these methods to set the request body to various formats or write the current payload to a file.
```python
def onRequest(context, request):
# Set `None` to body.
request.body.none()
# Set `foobar` to body.
request.body.text('foobar')
# Set the file content to body, body type is text.
request.body.textFromFile('/User/Reqable/Desktop/body.json')
# Set bytes to body
request.body.binary(b'\x01\x02\x03\x04')
# Set the file content to body, body type is binary.
request.body.binary('~/Desktop/body.json')
# Set the forms to body.
request.body.multiparts([
HttpMultipartBody.text('Hi World'),
HttpMultipartBody.file('data/body_binary.bin')
])
# Write body payload to the file.
request.body.writeFile('/User/Reqable/Desktop/body.json')
# Done
return request
```
--------------------------------
### HttpRequest Object
Source: https://reqable.com/en-US/docs/capture/addons
The HttpRequest object allows users to access and manipulate HTTP request data during the request lifecycle.
```APIDOC
## HttpRequest Object
### Description
The HttpRequest object represents an HTTP request and provides properties to access and modify its components.
### Properties
- **method** (str) - HTTP request method.
- **path** (str) - HTTP request path (query part not included).
- **protocol** (str) - HTTP protocol version (read-only).
- **queries** (HttpQueries) - List of request query parameters.
- **headers** (HttpHeaders) - List of request headers.
- **body** (HttpBody) - Request body.
- **trailers** (HttpHeaders) - List of request trailers.
- **contentType** (str or None) - Request Content-Type header value (read-only).
- **mime** (str or None) - Request MIME type (read-only).
```
--------------------------------
### Modify JSON response data
Source: https://reqable.com/en-US/docs/capture/addons
Demonstrates how to parse a JSON response body and update specific fields.
```json
{
"code": 10000,
"message": "ok",
"content": {
"version": "1.0.0",
"platform": "windows"
}
}
```
```python
from reqable import *
def onRequest(context, request):
# Done
return request
def onResponse(context, response):
# Jsonify the response body
response.body.jsonify()
# Modify the version value in the dictionary
response.body['content']['version'] = '2.0.0'
# Done
return response
```
--------------------------------
### Extract a Query Parameter Value
Source: https://reqable.com/en-US/docs/tools/regex
Extracts the value of a specific query parameter from a URL string.
```text
https://reqable.com?key=12345&foo=bar
```
```regex
[?&]key=([^&]*)
```
--------------------------------
### Extract a JSON Field Value
Source: https://reqable.com/en-US/docs/tools/regex
Extracts a value from a simple JSON string. Not recommended for complex or nested JSON structures.
```json
{"token":"abc123","expired":false}
```
```regex
"token"\s*:\s*"([^"]*)"
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.