Skip to content

Conversation

durch
Copy link
Contributor

@durch durch commented Sep 5, 2025

Overview

This PR introduces a proc-macro based system for globally configuring HTTP clients across the Nym workspace using the inventory crate. It enables any crate to contribute configuration modifications to reqwest::ClientBuilder
instances through a compile-time registry pattern.

Key Features

  • Global Configuration Registry: Allows crates to register HTTP client configurations that are automatically applied
  • Priority-based Ordering: Configurations can specify priorities to control application order (lower numbers run first)
  • Flexible DSL: Simple macro syntax for common configuration patterns
  • Zero Runtime Overhead: All configuration collection happens at compile time via inventory

Implementation Details

New Components

  • nym-http-api-client-macro: Proc-macro crate providing client_defaults! and client_cfg! macros
  • registry module: Runtime registry that collects and applies configurations

How It Works

  1. Crates use client_defaults! to register global configurations with optional priority
  2. The inventory crate collects all configurations at compile time
  3. When building HTTP clients, configurations are sorted by priority and applied sequentially
  4. Dynamic crate path resolution ensures the macros work both within and outside the core crate

Usage Examples

// Register default configurations globally
client_defaults!(
    priority = -100;  // Run early in configuration chain
    timeout = Duration::from_secs(30),
    gzip = true,
    default_headers {
        "User-Agent" => "NymApp/1.0",
        "Accept" => "application/json"
    }
);

// Create one-off configuration closures
let config = client_cfg!(
    pool_max_idle_per_host = 32,
    tcp_nodelay = true
);
let client = config(reqwest::ClientBuilder::new()).build()?;

Testing

  • ✅ 7 macro tests covering DSL parsing and code generation
  • ✅ 4 registry tests verifying configuration collection and application

This change is Reviewable

Copy link

vercel bot commented Sep 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nym-explorer-v2 Ready Ready Preview Comment Sep 11, 2025 7:38pm
nym-node-status Ready Ready Preview Comment Sep 11, 2025 7:38pm
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs-nextra Ignored Ignored Preview Sep 11, 2025 7:38pm

…ntation

- Fixed HeaderMapInit parsing bug that would cause compilation errors
- Added comprehensive documentation with usage examples and DSL reference
- Improved error handling with better error messages for invalid headers
- Added test coverage for both macro and registry functionality
- Added debug inspection capabilities for registered configurations
- Fixed module name conflicts in tests by using separate modules

All tests now passing:
- 7 macro tests validating DSL parsing and code generation
- 4 registry tests verifying configuration collection and application
* use display impl for urls

* feat: attempt to add more details to reqwest errors

* temporarily restored GenericRequestFailure variant

* another restoration

* cleanup
@durch durch merged commit 6907514 into domain-fronting-integration Sep 15, 2025
15 of 21 checks passed
@durch durch deleted the drazen/client-configuration-registry branch September 15, 2025 08:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants