Skip to content

Commit 435ece0

Browse files
ammarioclaude
andcommitted
docs: Add mdBook plugins for enhanced documentation
- Add mdbook-mermaid for diagram support - Add mdbook-linkcheck for broken link detection - Configure linkcheck to validate internal links only - Update GitHub Actions to install both plugins - Add example Mermaid diagram showing httpjail flow These plugins improve documentation quality by: - Enabling visual architecture diagrams with Mermaid - Automatically detecting broken internal links during builds - Ensuring documentation integrity in CI/CD 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b089883 commit 435ece0

6 files changed

Lines changed: 2720 additions & 25 deletions

File tree

.github/workflows/docs.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ jobs:
2727
uses: peaceiris/actions-mdbook@v2
2828
with:
2929
mdbook-version: 'latest'
30+
31+
- name: Install mdbook-mermaid
32+
run: |
33+
curl -sSL https://github.com/badboy/mdbook-mermaid/releases/latest/download/mdbook-mermaid-v0.16.0-x86_64-unknown-linux-gnu.tar.gz | tar -xz
34+
sudo mv mdbook-mermaid /usr/local/bin/
35+
mdbook-mermaid install .
36+
37+
- name: Install mdbook-linkcheck
38+
run: |
39+
curl -sSL https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -o linkcheck.zip
40+
unzip -q linkcheck.zip
41+
chmod +x mdbook-linkcheck
42+
sudo mv mdbook-linkcheck /usr/local/bin/
3043
3144
- name: Build documentation
3245
run: mdbook build

book.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ build-dir = "book"
1313

1414
[preprocessor.links]
1515

16+
[preprocessor.mermaid]
17+
command = "mdbook-mermaid"
18+
1619
[output.html]
1720
default-theme = "rust"
1821
preferred-dark-theme = "navy"
@@ -24,7 +27,7 @@ cname = ""
2427
mathjax-support = false
2528
copy-fonts = true
2629
additional-css = []
27-
additional-js = []
30+
additional-js = ["mermaid.min.js", "mermaid-init.js"]
2831
no-section-label = false
2932
fold.enable = true
3033
fold.level = 0
@@ -45,3 +48,13 @@ expand = true
4548
heading-split-level = 3
4649

4750
[output.html.redirect]
51+
52+
[output.linkcheck]
53+
# Optional: Only check internal links (faster builds)
54+
follow-web-links = false
55+
# Optional: Allow links outside book root
56+
traverse-parent-directories = false
57+
# Optional: Exclude patterns (regex)
58+
exclude = [ "^https://crates\\.io", "^https://docs\\.rs" ]
59+
# Optional: HTTP request configuration
60+
warning-policy = "warn"

docs/guide/rule-engines.md

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,56 @@ httpjail provides three different rule engines for evaluating HTTP requests. Eac
55
## Available Engines
66

77
### JavaScript (V8)
8+
89
Fast, secure JavaScript evaluation using the V8 engine. Best for most use cases.
910

1011
**Pros:**
12+
1113
- ⚡ Fastest performance (compiled and cached)
1214
- 🔒 Sandboxed execution environment
1315
- 📝 Familiar JavaScript syntax
1416
- 🎯 Direct access to request properties
1517

1618
**Cons:**
19+
1720
- Limited to JavaScript expressions
1821
- No external tool integration
1922
- No stateful operations between requests
2023

2124
**Use when:** You need high-performance filtering with simple to moderate logic.
2225

2326
### Shell Scripts
27+
2428
Execute shell scripts for each request with full system access.
2529

2630
**Pros:**
31+
2732
- 🔧 Full system access and tool integration
2833
- 📊 Can maintain state between requests
2934
- 🔗 Integrate with existing scripts and tools
3035
- 💾 Can query databases or external services
3136

3237
**Cons:**
38+
3339
- Slow (process spawn per request)
3440
- Security considerations with shell execution
3541
- Platform-specific behavior
3642

3743
**Use when:** You need to integrate with existing tools or require complex system interactions.
3844

3945
### Line Processor
46+
4047
Stream-based processing with line-by-line evaluation.
4148

4249
**Pros:**
50+
4351
- 🚀 Long-running process (no spawn overhead)
4452
- 📈 Can maintain state across requests
4553
- 🐍 Language agnostic (Python, Ruby, etc.)
4654
- 🔄 Bi-directional communication
4755

4856
**Cons:**
57+
4958
- More complex to implement
5059
- Requires handling the protocol correctly
5160
- Process management considerations
@@ -54,31 +63,37 @@ Stream-based processing with line-by-line evaluation.
5463

5564
## Performance Comparison
5665

57-
| Engine | Startup Time | Per-Request Overhead | Memory Usage | Stateful |
58-
|--------|-------------|---------------------|--------------|----------|
59-
| JavaScript | Fast | ~0.1ms | Low | No |
60-
| Shell Script | None | ~10-50ms | Variable | No* |
61-
| Line Processor | Slow | ~0.5ms | Variable | Yes |
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 |
6271

63-
*Shell scripts can use files for state but each invocation is independent
72+
\*Shell scripts can use files for state but each invocation is independent
6473

6574
## Choosing a Rule Engine
6675

6776
### For Production Use
77+
6878
**JavaScript** is recommended for production environments due to:
79+
6980
- Excellent performance
7081
- Predictable resource usage
7182
- Security isolation
7283
- Simple deployment
7384

7485
### For Development/Testing
86+
7587
**Shell scripts** work well for:
88+
7689
- Rapid prototyping
7790
- Integration testing
7891
- Debugging complex scenarios
7992

8093
### For Complex Filtering
94+
8195
**Line Processor** excels at:
96+
8297
- Machine learning models
8398
- Statistical analysis
8499
- Complex stateful logic
@@ -87,20 +102,24 @@ Stream-based processing with line-by-line evaluation.
87102
## Examples
88103

89104
### Simple Host Filtering
105+
90106
All three engines can handle basic filtering:
91107

92108
**JavaScript:**
109+
93110
```bash
94111
httpjail --js "r.host === 'github.com'" -- command
95112
```
96113

97114
**Shell Script:**
115+
98116
```bash
99117
#!/bin/bash
100118
[[ "$HTTPJAIL_HOST" == "github.com" ]] && exit 0 || exit 1
101119
```
102120

103121
**Line Processor:**
122+
104123
```python
105124
#!/usr/bin/env python3
106125
import sys, json
@@ -110,23 +129,27 @@ for line in sys.stdin:
110129
```
111130

112131
### Complex Logic
132+
113133
For complex scenarios, consider the implementation complexity:
114134

115135
**JavaScript** - Limited to expression evaluation:
136+
116137
```javascript
117138
// Complex but still performant
118-
const allowed = ['api.example.com', 'cdn.example.com'];
119-
allowed.includes(r.host) && r.method === 'GET' && r.path.startsWith('/v1/')
139+
const allowed = ["api.example.com", "cdn.example.com"];
140+
allowed.includes(r.host) && r.method === "GET" && r.path.startsWith("/v1/");
120141
```
121142

122143
**Shell Script** - Can use any tool but slow:
144+
123145
```bash
124146
#!/bin/bash
125147
# Check against database, but spawns process per request
126148
psql -c "SELECT allowed FROM rules WHERE host='$HTTPJAIL_HOST'" | grep -q true
127149
```
128150

129151
**Line Processor** - Best for complex stateful logic:
152+
130153
```python
131154
#!/usr/bin/env python3
132155
# Maintains state, handles thousands of requests efficiently
@@ -138,11 +161,11 @@ rate_limits = defaultdict(lambda: {"count": 0, "reset": time.time() + 60})
138161
for line in sys.stdin:
139162
req = json.loads(line)
140163
host_limit = rate_limits[req["host"]]
141-
164+
142165
if time.time() > host_limit["reset"]:
143166
host_limit["count"] = 0
144167
host_limit["reset"] = time.time() + 60
145-
168+
146169
if host_limit["count"] < 100: # 100 requests per minute
147170
host_limit["count"] += 1
148171
print("allow")
@@ -151,20 +174,6 @@ for line in sys.stdin:
151174
sys.stdout.flush()
152175
```
153176

154-
## Migration Path
155-
156-
Starting with JavaScript and need more features? Here's the typical migration path:
157-
158-
1. **Start with JavaScript** for simple rules
159-
2. **Move to Shell Scripts** when you need external tools
160-
3. **Upgrade to Line Processor** for high-volume or stateful filtering
161-
162-
## Security Considerations
163-
164-
- **JavaScript**: Fully sandboxed, safe for untrusted rules
165-
- **Shell Scripts**: Run with httpjail's privileges, validate all inputs
166-
- **Line Processor**: Depends on implementation language, consider using containers
167-
168177
## Next Steps
169178

170179
- [JavaScript Rules](./javascript-rules.md) - Learn the JavaScript API

docs/introduction.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@ httpjail creates an isolated network environment for your process:
4646
3. **Rule Evaluation**: Each request is evaluated against your configured rules
4747
4. **Action**: Requests are either allowed through or blocked based on the evaluation
4848

49+
```mermaid
50+
graph LR
51+
A[Application] -->|HTTP/HTTPS Request| B[httpjail Proxy]
52+
B --> C{Rule Engine}
53+
C -->|Allow| D[Forward to Target]
54+
C -->|Deny| E[Return 403]
55+
D --> F[Target Server]
56+
F -->|Response| B
57+
B -->|Response| A
58+
E -->|Error| A
59+
```
60+
4961
## Getting Started
5062

5163
The simplest way to use httpjail is with JavaScript rules:

mermaid-init.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
(() => {
6+
const darkThemes = ['ayu', 'navy', 'coal'];
7+
const lightThemes = ['light', 'rust'];
8+
9+
const classList = document.getElementsByTagName('html')[0].classList;
10+
11+
let lastThemeWasLight = true;
12+
for (const cssClass of classList) {
13+
if (darkThemes.includes(cssClass)) {
14+
lastThemeWasLight = false;
15+
break;
16+
}
17+
}
18+
19+
const theme = lastThemeWasLight ? 'default' : 'dark';
20+
mermaid.initialize({ startOnLoad: true, theme });
21+
22+
// Simplest way to make mermaid re-render the diagrams in the new theme is via refreshing the page
23+
24+
for (const darkTheme of darkThemes) {
25+
document.getElementById(darkTheme).addEventListener('click', () => {
26+
if (lastThemeWasLight) {
27+
window.location.reload();
28+
}
29+
});
30+
}
31+
32+
for (const lightTheme of lightThemes) {
33+
document.getElementById(lightTheme).addEventListener('click', () => {
34+
if (!lastThemeWasLight) {
35+
window.location.reload();
36+
}
37+
});
38+
}
39+
})();

mermaid.min.js

Lines changed: 2609 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)