Skip to content

Commit 0bb496b

Browse files
committed
WIP
1 parent 435ece0 commit 0bb496b

2 files changed

Lines changed: 26 additions & 96 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
book
2+
target

docs/guide/rule-engines.md

Lines changed: 25 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,31 @@
22

33
httpjail provides three different rule engines for evaluating HTTP requests. Each has different trade-offs in terms of performance, flexibility, and ease of use.
44

5-
## Available Engines
6-
7-
### JavaScript (V8)
8-
9-
Fast, secure JavaScript evaluation using the V8 engine. Best for most use cases.
10-
11-
**Pros:**
12-
13-
- ⚡ Fastest performance (compiled and cached)
14-
- 🔒 Sandboxed execution environment
15-
- 📝 Familiar JavaScript syntax
16-
- 🎯 Direct access to request properties
17-
18-
**Cons:**
19-
20-
- Limited to JavaScript expressions
21-
- No external tool integration
22-
- No stateful operations between requests
23-
24-
**Use when:** You need high-performance filtering with simple to moderate logic.
25-
26-
### Shell Scripts
27-
28-
Execute shell scripts for each request with full system access.
29-
30-
**Pros:**
31-
32-
- 🔧 Full system access and tool integration
33-
- 📊 Can maintain state between requests
34-
- 🔗 Integrate with existing scripts and tools
35-
- 💾 Can query databases or external services
36-
37-
**Cons:**
38-
39-
- Slow (process spawn per request)
40-
- Security considerations with shell execution
41-
- Platform-specific behavior
42-
43-
**Use when:** You need to integrate with existing tools or require complex system interactions.
44-
45-
### Line Processor
46-
47-
Stream-based processing with line-by-line evaluation.
48-
49-
**Pros:**
50-
51-
- 🚀 Long-running process (no spawn overhead)
52-
- 📈 Can maintain state across requests
53-
- 🐍 Language agnostic (Python, Ruby, etc.)
54-
- 🔄 Bi-directional communication
55-
56-
**Cons:**
57-
58-
- More complex to implement
59-
- Requires handling the protocol correctly
60-
- Process management considerations
61-
62-
**Use when:** You have high request volume and need stateful processing or want to use a specific language.
63-
64-
## Performance Comparison
65-
66-
| Engine | Startup Time | Per-Request Overhead | Memory Usage | Stateful |
67-
| -------------- | ------------ | -------------------- | ------------ | -------- |
68-
| JavaScript | Fast | ~0.1ms | Low | No |
69-
| Shell Script | None | ~10-50ms | Variable | No\* |
70-
| Line Processor | Slow | ~0.5ms | Variable | Yes |
71-
72-
\*Shell scripts can use files for state but each invocation is independent
73-
74-
## Choosing a Rule Engine
75-
76-
### For Production Use
77-
78-
**JavaScript** is recommended for production environments due to:
79-
80-
- Excellent performance
81-
- Predictable resource usage
82-
- Security isolation
83-
- Simple deployment
84-
85-
### For Development/Testing
86-
87-
**Shell scripts** work well for:
88-
89-
- Rapid prototyping
90-
- Integration testing
91-
- Debugging complex scenarios
92-
93-
### For Complex Filtering
94-
95-
**Line Processor** excels at:
96-
97-
- Machine learning models
98-
- Statistical analysis
99-
- Complex stateful logic
100-
- Custom protocols
5+
## Engine Comparison
6+
7+
| Feature | JavaScript (V8) | Shell Script | Line Processor |
8+
|---------|----------------|--------------|----------------|
9+
| **Performance** | | | |
10+
| Startup Time | Fast (~5ms) | None | Slow (~100ms) |
11+
| Per-Request Overhead | ~0.1ms | ~10-50ms | ~0.5ms |
12+
| Memory Usage | Low (5-10MB) | Variable | Variable |
13+
| Throughput | >10K req/s | ~50 req/s | ~2K req/s |
14+
| **Capabilities** | | | |
15+
| Stateful Processing ||* ||
16+
| External Tool Access ||||
17+
| Database Integration ||||
18+
| Language Choice | JS only | Bash/Shell | Any |
19+
| Sandboxed Execution ||| Depends |
20+
| **Development** | | | |
21+
| Setup Complexity | Simple | Simple | Moderate |
22+
| Debug Difficulty | Easy | Easy | Moderate |
23+
| Hot Reload ||||
24+
| **Best For** | | | |
25+
| Primary Use Case | Production filtering | System integration | Stateful logic |
26+
| Request Volume | High | Low | Medium |
27+
| Security Level | Untrusted rules | Trusted only | Depends on impl |
28+
29+
*Shell scripts can use files for state but each invocation is independent
10130

10231
## Examples
10332

0 commit comments

Comments
 (0)