HttpRecorder.DevProxy
0.5.0
See the version list below for details.
dotnet add package HttpRecorder.DevProxy --version 0.5.0
NuGet\Install-Package HttpRecorder.DevProxy -Version 0.5.0
<PackageReference Include="HttpRecorder.DevProxy" Version="0.5.0" />
<PackageVersion Include="HttpRecorder.DevProxy" Version="0.5.0" />
<PackageReference Include="HttpRecorder.DevProxy" />
paket add HttpRecorder.DevProxy --version 0.5.0
#r "nuget: HttpRecorder.DevProxy, 0.5.0"
#:package HttpRecorder.DevProxy@0.5.0
#addin nuget:?package=HttpRecorder.DevProxy&version=0.5.0
#tool nuget:?package=HttpRecorder.DevProxy&version=0.5.0
HttpRecorder Dev Proxy Extension
This directory contains a Microsoft Dev Proxy plugin that integrates HttpRecorder to capture HTTP traffic and save it as HAR (HTTP Archive) files.
Overview
The HttpRecorder Dev Proxy plugin allows you to:
- Intercept HTTP requests and responses passing through Dev Proxy
- Record them using the HttpRecorder library
- Save interactions as HAR files for later replay or analysis
- Anonymize sensitive data like authorization headers
- Filter which URLs to record
Project Structure
DevProxyExtension/
├── HttpRecorder.DevProxy/
│ ├── HttpRecorderPlugin.cs # Main plugin implementation
│ ├── HttpRecorderPluginConfiguration.cs # Plugin configuration class
│ ├── BasePlugin.cs # Base class stub (replace with DevProxy.Abstractions)
│ └── HttpRecorder.DevProxy.csproj # Project file
├── README.md # This file
└── devproxyrc.example.json # Example Dev Proxy configuration
Prerequisites
Microsoft Dev Proxy - Install using winget (recommended):
# Stable version winget install DevProxy.DevProxy --silent # OR Beta version (for latest preview features) winget install DevProxy.DevProxy.Beta --silentImportant: After installation, restart your command prompt to refresh the PATH environment variable.
Alternative: Manual installation from Microsoft Dev Proxy Documentation
.NET 9.0 SDK - Required for building the plugin
First Time Setup
When you start Dev Proxy for the first time:
- Trust the certificate: Dev Proxy installs a certificate named "Dev Proxy CA". Select Yes to confirm installation.
- Allow firewall access: Windows Firewall will show a warning. Select Allow access to permit traffic through the firewall.
Dev Proxy will display:
info Dev Proxy API listening on http://localhost:8897...
info Dev Proxy Listening on 127.0.0.1:8000...
Hotkeys: issue (w)eb request, (r)ecord, (s)top recording, (c)lear screen
Press CTRL+C to stop Dev Proxy
Important: Always stop Dev Proxy using Ctrl+C to safely unregister it as the system proxy. Closing the terminal without stopping Dev Proxy may cause connection issues.
Building the Plugin
# From the DevProxyExtension directory
cd HttpRecorder.DevProxy
dotnet build
# The plugin DLL will be at:
# bin/Debug/net9.0/HttpRecorder.DevProxy.dll
Configuration
Dev Proxy Configuration
Create or update your devproxyrc.json file:
{
"plugins": [
{
"name": "HttpRecorderPlugin",
"enabled": true,
"pluginPath": "./DevProxyExtension/HttpRecorder.DevProxy/bin/Debug/net9.0/HttpRecorder.DevProxy.dll",
"configSection": "httpRecorder"
}
],
"urlsToWatch": [
"https://api.example.com/*",
"https://graph.microsoft.com/*"
],
"httpRecorder": {
"outputDirectory": "./recordings",
"mode": "Record",
"includeBodies": true,
"anonymizeSensitiveData": true,
"sensitiveHeaders": [
"Authorization",
"Cookie",
"Set-Cookie",
"X-API-Key",
"X-Auth-Token"
]
}
}
Configuration Options
- outputDirectory: Directory where HAR files will be saved (default:
./recordings) - mode: Recording mode - currently supports "Record" (default)
- includeBodies: Whether to include request/response bodies (default:
true) - anonymizeSensitiveData: Redact sensitive headers (default:
true) - sensitiveHeaders: Array of header names to anonymize
Running Dev Proxy with the Plugin
# Start Dev Proxy with your configuration
devproxy --config-file devproxyrc.json
# Or if devproxyrc.json is in the current directory
devproxy
# For beta version
devproxy-beta --config-file devproxyrc.json
Verifying Dev Proxy is Working
Before using the plugin, confirm Dev Proxy is intercepting requests:
# Test with Invoke-WebRequest (PowerShell)
Invoke-WebRequest -Uri https://jsonplaceholder.typicode.com/posts
# Or with curl
curl -ikx http://localhost:8000 https://jsonplaceholder.typicode.com/posts
You should see output in the Dev Proxy terminal like:
req ╭ GET https://jsonplaceholder.typicode.com/posts
time │ 1/31/2025 12:12:14 PM +00:00
api ╰ Passed through
How It Works
- Request Interception: When Dev Proxy intercepts an HTTP request matching
urlsToWatch, theBeforeRequestAsyncmethod is called - Request Recording: The plugin creates an
Interactionobject and stores request details (URL, method, headers, body) - Response Interception: When the response arrives,
AfterResponseAsyncis called - Response Recording: The plugin updates the interaction with response details (status code, headers, body, timing)
- HAR Export: The complete interaction is saved as a HAR file using
HttpArchiveInteractionRepository
HAR File Output
Each recorded interaction is saved as a separate HAR file:
recordings/
├── 20251104_143022_1_api_example_com_users.har
├── 20251104_143023_2_api_example_com_orders.har
└── ...
Filenames include:
- Timestamp (yyyyMMdd_HHmmss)
- Interaction ID
- Sanitized URL path
Integration with Dev Proxy Abstractions
Note: The current implementation includes a stub BasePlugin.cs class. For production use:
- Install Dev Proxy and locate
DevProxy.Abstractions.dll - Add it as a reference in the
.csprojfile:
<ItemGroup>
<Reference Include="DevProxy.Abstractions">
<HintPath>path/to/DevProxy.Abstractions.dll</HintPath>
</Reference>
</ItemGroup>
- Remove the stub
BasePlugin.csfile - Update imports to use
DevProxy.Abstractionsnamespace
Use Cases
- API Testing: Record API interactions for test fixtures
- Documentation: Generate HAR files to document API behavior
- Debugging: Capture full request/response cycles for troubleshooting
- Replay: Save production traffic for replay in test environments
- Analysis: Analyze API performance and payloads
Example Workflow
# 1. Build the plugin
cd DevProxyExtension/HttpRecorder.DevProxy
dotnet build
# 2. Configure Dev Proxy (edit devproxyrc.json)
# 3. Start Dev Proxy
devproxy
# 4. Configure your application to use the proxy
$env:HTTP_PROXY = "http://localhost:8000"
$env:HTTPS_PROXY = "http://localhost:8000"
# 5. Run your application
# HTTP traffic will be recorded to ./recordings/
# 6. Stop Dev Proxy (Ctrl+C)
# 7. Review HAR files
ls ./recordings/*.har
Viewing HAR Files
HAR files can be viewed in:
- Chrome DevTools (Network tab → Import HAR)
- Firefox DevTools (Network tab → Import HAR)
- HAR Viewer
- Charles Proxy
- Fiddler
Advanced Usage
Custom Anonymization Rules
Extend the plugin to add custom anonymization logic:
private void AnonymizeSensitiveHeaders(Dictionary<string, string> headers)
{
// Existing logic...
// Custom: Anonymize API keys in query strings
if (headers.ContainsKey("X-Custom-Header"))
{
headers["X-Custom-Header"] = MaskApiKey(headers["X-Custom-Header"]);
}
}
Filtering Requests
Modify BeforeRequestAsync to add custom filtering:
public override Task BeforeRequestAsync(ProxyRequestArgs e)
{
// Only record POST/PUT requests
if (e.Session.HttpClient.Request.Method != "POST" &&
e.Session.HttpClient.Request.Method != "PUT")
{
return Task.CompletedTask;
}
// Continue with recording...
}
Troubleshooting
Plugin Not Loading
- Verify the
pluginPathindevproxyrc.jsonis correct - Check that the DLL was built successfully
- Ensure .NET 9.0 runtime is installed
No HAR Files Generated
- Check the
outputDirectoryhas write permissions - Verify
urlsToWatchpatterns match your requests - Check Dev Proxy console for error messages
Missing Request/Response Bodies
- Set
includeBodies: truein configuration - Some content types may not be captured (binary, streaming)
Contributing
This plugin is part of the HttpRecorder.Next project. See the main README for contribution guidelines.
License
MIT License - see LICENSE file in the project root.
References
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- HttpRecorder (>= 0.5.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.