No description
Find a file
2023-07-02 23:44:48 -04:00
examples status header 2023-07-02 23:44:48 -04:00
src status header 2023-07-02 23:44:48 -04:00
.gitignore add methods to routes, allow custom headers and response codes 2023-07-02 22:15:24 -04:00
Cargo.lock status header 2023-07-02 23:44:48 -04:00
Cargo.toml status header 2023-07-02 23:44:48 -04:00
LICENSE hi 2023-07-02 18:45:41 -04:00
README.md status header 2023-07-02 23:44:48 -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 if the Status header is given, it will be treated as the http response code.

An example script that gives custom headers (with res code) is shown below:

#!/bin/bash

# print headers that will be returned
printf "Content-Type: text/plain\n"
printf "aaaaaaaa: AAAAAAAAAA\n"
printf "Status: 418\n" # return 418 im a teapot
printf "\n"

printf "joe\n"

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

License

This project is licensed under the WTFPL

Warrenty

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

...wtfpl