Skip to content

Commit bf70cac

Browse files
authored
docs: Fix Line Processor response format documentation (#65)
The Line Processor does NOT accept simple text 'allow' or 'deny'. It accepts: - 'true' / 'false' (boolean strings) - JSON objects with allow/deny_message - Any other text is treated as deny with that text as the message
1 parent a959978 commit bf70cac

2 files changed

Lines changed: 11 additions & 12 deletions

File tree

docs/guide/rule-engines/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ httpjail --js "r.host === 'github.com'" -- command
4747
import sys, json
4848
for line in sys.stdin:
4949
req = json.loads(line)
50-
print("allow" if req["host"] == "github.com" else "deny")
50+
print("true" if req["host"] == "github.com" else "false")
5151
```
5252

5353
### Complex Logic
@@ -90,9 +90,9 @@ for line in sys.stdin:
9090

9191
if host_limit["count"] < 100: # 100 requests per minute
9292
host_limit["count"] += 1
93-
print("allow")
93+
print("true")
9494
else:
95-
print("deny")
95+
print("false")
9696
sys.stdout.flush()
9797
```
9898

docs/guide/rule-engines/line-processor.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Stream requests to a long-running process for stateful, high-performance filteri
66

77
1. httpjail spawns your processor once at startup
88
2. For each HTTP request, httpjail sends a JSON line to the processor's stdin
9-
3. The processor evaluates and responds with "allow" or "deny"
9+
3. The processor evaluates and responds with "true" or "false"
1010
4. The process continues running until httpjail exits
1111

1212
## Protocol
@@ -27,13 +27,12 @@ Each request is sent as a single JSON line:
2727

2828
### Response Format
2929

30-
Your processor can respond with one line per request:
30+
Your processor must respond with one line per request:
3131

32-
- **Simple text**: `"allow"` or `"deny"`
33-
- **Text with message**: `"deny: Custom error message"`
3432
- **Boolean strings**: `"true"` (allow) or `"false"` (deny)
3533
- **JSON object**: `{"allow": false, "deny_message": "Blocked by policy"}`
36-
- **Just message**: `{"deny_message": "Blocked"}` (implies deny)
34+
- **JSON with message only**: `{"deny_message": "Blocked"}` (implies deny)
35+
- **Any other text**: Treated as deny with that text as the message (e.g., `"Access denied"` becomes a deny with message "Access denied")
3736

3837
## Command Line Usage
3938

@@ -62,13 +61,13 @@ for line in sys.stdin:
6261
try:
6362
req = json.loads(line)
6463
if req['host'] in allowed_hosts:
65-
print("allow")
64+
print("true")
6665
else:
6766
# Can return JSON for custom messages
6867
response = {"allow": False, "deny_message": f"{req['host']} not allowed"}
6968
print(json.dumps(response))
7069
except:
71-
print("deny: Invalid request")
70+
print("Invalid request") # Any non-boolean text becomes deny message
7271
sys.stdout.flush() # Ensure immediate response
7372
```
7473

@@ -81,9 +80,9 @@ while IFS= read -r line; do
8180
host=$(echo "$line" | jq -r .host)
8281

8382
if [[ "$host" == *.github.com ]]; then
84-
echo "allow"
83+
echo "true"
8584
else
86-
echo "deny"
85+
echo "false"
8786
fi
8887
done
8988
```

0 commit comments

Comments
 (0)