http-sh
Overview
GET: Hello world
POST: echo
Request metadata
The Request metadata is available as JSON on file descriptor 3.
Pairs well with jq
{
}
Response metadata
You can set the Response metadata by writing JSON on file descriptor 4.
Currently you can set the Response status
and headers
.
Pairs well with jo
$ http-sh :5000 -- bash -c 'jo status=404 >&4; echo sorry, eh'
$ curl -si localhost:5000
HTTP/1.1 404 Not Found
content-type: text/plain
transfer-encoding: chunked
date: Sat, 25 Feb 2023 05:20:48 GMT
sorry, eh
Note, for streaming responses, you'll want to close fd 4, so the Response is initiated.
$ http-sh :5000 -- bash -c 'exec 4>&-; while true ; do date; sleep 1; done'
$ curl -s localhost:5000
Sat Feb 25 00:31:41 EST 2023
Sat Feb 25 00:31:43 EST 2023
Sat Feb 25 00:31:44 EST 2023
Sat Feb 25 00:31:45 EST 2023
Sat Feb 25 00:31:46 EST 2023
...
server-sent events
Pairs well with xcat
# simulate generating events in a seperate process
; do ; ; done
Direct Testing of Script
While http-sh
provides a convenient way to serve HTTP requests and interact with the associated metadata, there might be times when you wish to directly test the script you intend to use with http-sh
without the HTTP layer.
To simulate the environment in which http-sh
invokes your script, you can use the following command:
|
Here's a breakdown of what's happening:
echo "Hai"
: Simulates sending the request body../root.sh
: Your script that processes the input.3</tmp/req.json
: Mimics the JSON metadata thathttp-sh
provides on file descriptor 3. To obtain this JSON metadata for testing, check the log line of a specific request from thehttp-sh
logs, which are structured in JSON format.4>&1
: Redirects output from file descriptor 4 to stdout, so you can see the response metadata and main response together in the terminal.
This method allows you to bypass http-sh
during development and testing phases, ensuring that your script behaves as expected before integrating it with the HTTP server.