One-liner to accept incoming http POST data and then relay it to some number of POST endpoints.
while true; do printf 'HTTP/1.0 200 OK\r\nContent-Length: 0\r\n' | { nc -q1 -l 8080; echo; } | sed '0,/^[[:space:]]*$/d' | tee >(http POST http://localhost:8081/path1) >(http POST http://localhost:8081/path2); done
With some linebreaks so it's readable:
while true
do
printf 'HTTP/1.0 200 OK\r\nContent-Length: 0\r\n' \
| { nc -q1 -l 8080; echo; } \
| sed '0,/^[[:space:]]*$/d' \
| tee \
>(http POST http://localhost:8081/path1) \
>(http POST http://localhost:8081/path2)
done
- Data being resubmitted is logged to STDOUT along with the response from the relay targets
- I just used another netcat instance as the web server, because lazy; who knows how this works with real problems
- This uses httpie because web developers have convinced me that's the right way to do things
- There is basically no error checking at all, so there's a strong chance this will explode your house, computers, and things that actually need it to run
The "sketchy web server" doesn't like getting hit many times in a row. This is fine, because it's a terrible idea to write a web server this way.