Overview
The HTTP endpoints component provides all HTTP(S) server interfaces for the Internet Computer. These endpoints handle external client requests, internal metrics collection, and administrative operations. Location:rs/http_endpoints/
Public API
User-facing HTTPS endpoints for canister calls
Metrics
Prometheus-compatible metrics endpoint
Architecture
The HTTP endpoints follow best practices for reliability and security:Design Principles
Connection Management
Connection Management
Nftables IntegrationReplicaOS uses nftables for:
- Restrict inbound traffic to registry-approved IPs
- Limit simultaneous TCP connections per source IP
- Rate limit connection establishment
connection_read_timeout_seconds with no activity to prevent:- Resource exhaustion
- File descriptor leaks
- Hung connections
Queue Management
Queue Management
Uses the thread-per-request pattern:
- Requests sit in bounded-size queue
- Thread pool processes requests from queue
- Cancelled requests are not executed
- Non-blocking async runtime using threadpools and oneshot channels
Load Shedding
Load Shedding
Fail early and cheaply when overloaded:
- Return
429 Too Many Requestswhen queues are full - Benefits load balancers using least-loaded round robin
- Prevents cascading failures
Request Timeout
Request Timeout
Guard against stuck upstream services:
- Each request has a timeout
- Return
504 Gateway Timeoutif not completed - Prevents connection drops on slow operations
Public HTTPS API
Overview
Implements the HTTPS Interface defined by the Internet Computer Interface Specification. Location:rs/http_endpoints/public/
Endpoint Versions
The API supports multiple versions:- v2: Original API with flat canister ranges format
- v3: API with tree-based canister ranges format
- v4: Latest version with enhanced features (call endpoint)
Core Endpoints
Call Endpoint
Submit ingress messages to canisters. Paths:/api/v2/canister/{effective_canister_id}/call/api/v3/canister/{effective_canister_id}/call/api/v4/canister/{effective_canister_id}/call
- Validation: Verify signature and delegation chain
- Ingress Filter: Check if canister accepts the call
- Throttling: Apply rate limits and pool throttling
- Submission: Add to ingress pool for processing
202 Accepted: Message accepted for processing400 Bad Request: Malformed request413 Payload Too Large: Request exceeds size limit429 Too Many Requests: Ingress pool is full500 Internal Server Error: Internal processing error
Query Endpoint
Execute read-only queries against canisters. Paths:/api/v2/canister/{effective_canister_id}/query/api/v3/canister/{effective_canister_id}/query
- Synchronous execution and response
- Signed responses for verification
- Support for delegated query calls
- Health status checks before execution
Read State Endpoint
Read certified state information from the IC. Canister Read State:/api/v2/canister/{effective_canister_id}/read_state/api/v3/canister/{effective_canister_id}/read_state
/api/v2/subnet/{effective_subnet_id}/read_state/api/v3/subnet/{effective_subnet_id}/read_state
/time: Current certified time/request_status/<request_id>: Ingress message status/canister/<canister_id>/module_hash: Canister wasm hash/canister/<canister_id>/controllers: Canister controllers/canister/<canister_id>/metadata/<name>: Canister metadata/subnet/<subnet_id>/public_key: Subnet public key/subnet/<subnet_id>/canister_ranges: Canister ID ranges
All read_state responses include cryptographic certificates that can be verified against the IC root key.
Ingress Validation
The ingress validation pipeline ensures message integrity:- Signature Verification: Validate sender signature and delegation chain
- Expiry Check: Ensure ingress_expiry is within acceptable window
- Size Limits: Check against max_ingress_bytes_per_message
- Provisional Whitelist: Check if sender is authorized (when applicable)
- Ingress Filter: Query canister’s ingress filter
- Throttling: Apply rate limits based on canister and sender
Request Validation
Automatic validation and error handling:- 413 Payload Too Large: Body exceeds configured limit
- 408 Request Timeout: Request not completed within timeout
- 400 Bad Request: Malformed CBOR or invalid structure
Status Endpoint
Provides replica health and configuration information. Path:/api/v2/status
Response Format:
starting: Replica is initializingwaiting_for_certified_state: Waiting for first certified statewaiting_for_root_delegation: Waiting for NNS delegationhealthy: Ready to serve requests
Catch-Up Package Endpoint
Provides catch-up packages for subnet recovery. Path:/api/v1/catch_up_package
Purpose:
- Allow nodes to sync to latest subnet state
- Support subnet recovery scenarios
- Enable new nodes to join subnet
Metrics Endpoint
Prometheus-compatible metrics for monitoring. Location:rs/http_endpoints/metrics/
Path: /metrics (typically on port 9090)
Exported Metrics:
- Request counts by endpoint and status
- Request latencies (histograms)
- Connection counts
- Ingress pool statistics
- Query execution times
- Certificate generation times
Boundary Node Integration
The HTTP endpoints are designed to work behind boundary nodes:Boundary Node Responsibilities
- TLS Termination: Handle HTTPS from clients
- Load Balancing: Distribute requests across replicas
- Caching: Cache query responses when possible
- Rate Limiting: Implement per-client rate limits
- DDoS Protection: Filter malicious traffic
Replica Responsibilities
- Request Processing: Execute calls and queries
- State Certification: Generate certificates
- Consensus: Agree on ingress message ordering
- Health Reporting: Signal availability to load balancers
Boundary nodes use the health status to implement intelligent routing and failover.
Protocol Details
Content Types
- Request:
application/cbor - Response:
application/cbor
CORS Support
CORS headers are configured to allow browser-based dapps:TLS Configuration
- ALPN Protocols: HTTP/2 (
h2) and HTTP/1.1 - TLS Versions: TLS 1.2 and 1.3
- Certificate Validation: Against registry-stored certificates
Async Call Workflow
For asynchronous update calls:Sync Call Workflow
For synchronous query calls:Error Handling
HTTP Status Codes
200 OK: Query executed successfully202 Accepted: Call accepted for processing400 Bad Request: Malformed request408 Request Timeout: Request processing timeout413 Payload Too Large: Request body too large429 Too Many Requests: Rate limit or queue full500 Internal Server Error: Unexpected server error503 Service Unavailable: Certified state not available504 Gateway Timeout: Upstream service timeout
Error Response Format
Configuration
Key Settings
Default Values
- Connection read timeout: 300 seconds (5 minutes)
- Request timeout: 300 seconds (5 minutes)
- Max request size: Configured per subnet (typically 2-3 MB)
- TCP keepalive: Uses ReplicaOS defaults
Performance Optimization
Thread Pool Configuration
- Separate thread pools for different upstream services
- Prevents blocking the async runtime
- Configurable pool sizes based on workload
Request Cancellation
- Requests removed from queue if cancelled
- Prevents wasted processing
- Improves response to overload conditions
Fairness
- Fair thread scheduler ensures request processing fairness
- Bounded queues prevent resource exhaustion
- Load shedding protects against cascading failures
Security Considerations
Firewall Rules
Nftables restricts access:- Only registry-approved IPs can connect
- Connection rate limits per source IP
- Maximum concurrent connections per source
Request Validation
- Signature verification using Ed25519 or ECDSA
- Delegation chain validation
- Replay protection via nonces and expiry times
- Principal ID validation
Resource Protection
- Request size limits
- Request timeout limits
- Queue depth limits
- Concurrent request limits
Monitoring and Observability
Key Metrics
http_requests_total: Request count by endpoint and statushttp_request_duration_seconds: Request latency histogramhttp_concurrent_requests: Current concurrent request countingress_pool_size_bytes: Ingress pool memory usagehealth_status_transitions_total: Health status changes
Logging
Comprehensive logging at appropriate levels:- Request validation failures (WARN)
- Unexpected errors (ERROR)
- Health status transitions (INFO)
- Periodic status updates (INFO every N seconds)
Related APIs
P2P Layer
Subnet-internal message delivery
XNet Protocol
Cross-subnet communication
Source Code References
- HTTP endpoints:
rs/http_endpoints/ - Public API:
rs/http_endpoints/public/src/lib.rs - Call endpoint:
rs/http_endpoints/public/src/call.rs - Query endpoint:
rs/http_endpoints/public/src/query.rs - Read state:
rs/http_endpoints/public/src/read_state.rs - Metrics endpoint:
rs/http_endpoints/metrics/