No description
Find a file
2023-07-02 22:40:04 -04:00
examples move body to stdin 2023-07-02 22:40:04 -04:00
src move body to stdin 2023-07-02 22:40:04 -04:00
.gitignore add methods to routes, allow custom headers and response codes 2023-07-02 22:15:24 -04:00
Cargo.lock add methods to routes, allow custom headers and response codes 2023-07-02 22:15:24 -04:00
Cargo.toml hi 2023-07-02 18:45:41 -04:00
LICENSE hi 2023-07-02 18:45:41 -04:00
README.md move body to stdin 2023-07-02 22:40:04 -04:00

bashttp

A very goofy http server that runs scripts based of the given URI route

Config

All routes and scripts must be layed out in a file called config, or you can specift the path by setting the CONFIG_PATH env variable.

An example config is shown below

GET     /       command.sh
POST    /joe    headers.sh
POST    /echo   body.sh

As shown above, each line is the method route given to run a given script.

Scripts

Anything written to a scripts stdout will be treated as part of the HTTP Response.

Therefore the first things returned will be treated as headers. To stop reading headers, print a \n to stdout to tell the HTTP Response that the headers have ended.

All content after the headers will be treated as the response body, and the scripts exit code will be treated as the http response code.

An example script that gives custom headers is shown below:

#!/bin/bash

# print headers that will be returned
printf "Content-Type: text/plain\n"
printf "aaaaaaaa: AAAAAAAAAA\n"
printf "\n"

printf "joe\n"

# return http code 200
exit 200

Finally if you wish to read the request body given by the user, that is always stored in stdin. For example to create a echo endpoint:

#!/bin/bash

# even though we have no headers
# we still need to tell there will be no more headers
printf "\n"

# the body of any http request made will be stored in stdin
cat

exit 200

License

This project is licensed under the WTFPL

Warrenty

This project is probably not secure and if it beaks, uh... have fun

...wtfpl